Merge branch 'editor_crash_behaviour' of https://github.com/EliteTK/qutebrowser into EliteTK-editor_crash_behaviour

This commit is contained in:
Florian Bruhin 2016-03-17 21:40:17 +01:00
commit 0830b400fe
3 changed files with 16 additions and 3 deletions

View File

@ -58,6 +58,7 @@ class ExternalEditor(QObject):
return
try:
os.close(self._oshandle)
if self._proc.exit_status() != QProcess.CrashExit:
os.remove(self._filename)
except OSError as e:
# NOTE: Do not replace this with "raise CommandError" as it's

View File

@ -160,3 +160,6 @@ class GUIProcess(QObject):
else:
message.error(self._win_id, "Error while spawning {}: {}.".format(
self._what, self._proc.error()), immediately=True)
def exit_status(self):
return self._proc.exitStatus()

View File

@ -98,19 +98,28 @@ class TestFileHandling:
filename = editor._filename
assert os.path.exists(filename)
editor._proc._proc.exitStatus = mock.Mock(
return_value=QProcess.CrashExit)
editor._proc.finished.emit(1, QProcess.NormalExit)
assert not os.path.exists(filename)
assert os.path.exists(filename)
os.remove(filename)
def test_crash(self, editor):
"""Test file handling when closing with a crash."""
editor.edit("")
filename = editor._filename
assert os.path.exists(filename)
editor._proc._proc.exitStatus = mock.Mock(
return_value=QProcess.CrashExit)
editor._proc.error.emit(QProcess.Crashed)
editor._proc.finished.emit(0, QProcess.CrashExit)
assert not os.path.exists(filename)
assert os.path.exists(filename)
os.remove(filename)
@pytest.mark.posix
def test_unreadable(self, message_mock, editor):