Merge branch 'EliteTK-editor_crash_behaviour'

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

View File

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

View File

@ -160,3 +160,6 @@ class GUIProcess(QObject):
else: else:
message.error(self._win_id, "Error while spawning {}: {}.".format( message.error(self._win_id, "Error while spawning {}: {}.".format(
self._what, self._proc.error()), immediately=True) 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 filename = editor._filename
assert os.path.exists(filename) assert os.path.exists(filename)
editor._proc._proc.exitStatus = mock.Mock(
return_value=QProcess.CrashExit)
editor._proc.finished.emit(1, QProcess.NormalExit) 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): def test_crash(self, editor):
"""Test file handling when closing with a crash.""" """Test file handling when closing with a crash."""
editor.edit("") editor.edit("")
filename = editor._filename filename = editor._filename
assert os.path.exists(filename) assert os.path.exists(filename)
editor._proc._proc.exitStatus = mock.Mock(
return_value=QProcess.CrashExit)
editor._proc.error.emit(QProcess.Crashed) editor._proc.error.emit(QProcess.Crashed)
editor._proc.finished.emit(0, QProcess.CrashExit) editor._proc.finished.emit(0, QProcess.CrashExit)
assert not os.path.exists(filename) assert os.path.exists(filename)
os.remove(filename)
@pytest.mark.posix @pytest.mark.posix
def test_unreadable(self, message_mock, editor): def test_unreadable(self, message_mock, editor):