Wait until the mtime changed
This commit is contained in:
parent
a8733d7228
commit
abd56a5abd
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
"""Tests for qutebrowser.misc.editor."""
|
"""Tests for qutebrowser.misc.editor."""
|
||||||
|
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import logging
|
import logging
|
||||||
@ -179,19 +180,31 @@ def test_modify(qtbot, editor, initial_text, edited_text):
|
|||||||
assert blocker.args == [edited_text]
|
assert blocker.args == [edited_text]
|
||||||
|
|
||||||
|
|
||||||
|
def _update_file(filename, contents):
|
||||||
|
"""Update the given file and make sure its mtime changed.
|
||||||
|
|
||||||
|
This might write the file multiple times, but different systems have
|
||||||
|
different mtime's, so we can't be sure how long to wait otherwise.
|
||||||
|
"""
|
||||||
|
old_mtime = new_mtime = os.stat(filename).st_mtime
|
||||||
|
while old_mtime == new_mtime:
|
||||||
|
time.sleep(0.1)
|
||||||
|
with open(filename, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(contents)
|
||||||
|
new_mtime = os.stat(filename).st_mtime
|
||||||
|
|
||||||
|
|
||||||
def test_modify_watch(qtbot):
|
def test_modify_watch(qtbot):
|
||||||
"""Test that saving triggers file_updated when watch=True."""
|
"""Test that saving triggers file_updated when watch=True."""
|
||||||
editor = editormod.ExternalEditor(watch=True)
|
editor = editormod.ExternalEditor(watch=True)
|
||||||
editor.edit('foo')
|
editor.edit('foo')
|
||||||
|
|
||||||
with qtbot.wait_signal(editor.file_updated, timeout=3000) as blocker:
|
with qtbot.wait_signal(editor.file_updated, timeout=3000) as blocker:
|
||||||
with open(editor._filename, 'w', encoding='utf-8') as f:
|
_update_file(editor._filename, 'bar')
|
||||||
f.write('bar')
|
|
||||||
assert blocker.args == ['bar']
|
assert blocker.args == ['bar']
|
||||||
|
|
||||||
with qtbot.wait_signal(editor.file_updated) as blocker:
|
with qtbot.wait_signal(editor.file_updated) as blocker:
|
||||||
with open(editor._filename, 'w', encoding='utf-8') as f:
|
_update_file(editor._filename, 'baz')
|
||||||
f.write('baz')
|
|
||||||
assert blocker.args == ['baz']
|
assert blocker.args == ['baz']
|
||||||
|
|
||||||
with qtbot.assert_not_emitted(editor.file_updated):
|
with qtbot.assert_not_emitted(editor.file_updated):
|
||||||
|
Loading…
Reference in New Issue
Block a user