diff --git a/qutebrowser/misc/editor.py b/qutebrowser/misc/editor.py index 62d4a2d6f..53067ca2c 100644 --- a/qutebrowser/misc/editor.py +++ b/qutebrowser/misc/editor.py @@ -55,7 +55,7 @@ class ExternalEditor(QObject): def _cleanup(self): """Clean up temporary files after the editor closed.""" assert self._remove_file is not None - self._watcher.fileChanged.disconnect() + self._watcher.removePaths(self._watcher.files()) if self._filename is None or not self._remove_file: # Could not create initial file. return diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py index 7dea6e069..55425a1c4 100644 --- a/tests/unit/misc/test_editor.py +++ b/tests/unit/misc/test_editor.py @@ -37,7 +37,7 @@ def patch_things(config_stub, monkeypatch, stubs): @pytest.fixture -def editor(caplog): +def editor(caplog, qtbot): ed = editormod.ExternalEditor() yield ed with caplog.at_level(logging.ERROR): @@ -118,18 +118,21 @@ class TestFileHandling: os.remove(filename) - def test_unreadable(self, message_mock, editor, caplog): + def test_unreadable(self, message_mock, editor, caplog, qtbot): """Test file handling when closing with an unreadable file.""" editor.edit("") filename = editor._filename assert os.path.exists(filename) - os.chmod(filename, 0o077) + os.chmod(filename, 0o277) if os.access(filename, os.R_OK): # Docker container or similar pytest.skip("File was still readable") with caplog.at_level(logging.ERROR): - editor._proc.finished.emit(0, QProcess.NormalExit) + with qtbot.wait_signal(editor._watcher.fileChanged): + with open(filename, 'w', encoding='utf-8') as f: + f.write('unreadable') + editor._proc.finished.emit(0, QProcess.NormalExit) assert not os.path.exists(filename) msg = message_mock.getmsg(usertypes.MessageLevel.error) assert msg.text.startswith("Failed to read back edited file: ") @@ -170,11 +173,11 @@ def test_modify(qtbot, editor, initial_text, edited_text): with open(editor._filename, 'r', encoding='utf-8') as f: assert f.read() == initial_text - with open(editor._filename, 'w', encoding='utf-8') as f: - f.write(edited_text) - with qtbot.wait_signal(editor.editing_finished) as blocker: - editor._proc.finished.emit(0, QProcess.NormalExit) + with open(editor._filename, 'w', encoding='utf-8') as f: + f.write(edited_text) + + editor._proc.finished.emit(0, QProcess.NormalExit) assert blocker.args == [edited_text]