From 22adcfba754b9cf837cb5f57ceafd74888e188b2 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 3 Oct 2017 19:28:41 +0200 Subject: [PATCH] Stop using mocks in test_editor --- tests/unit/misc/test_editor.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py index 26a92476a..d97a39f7b 100644 --- a/tests/unit/misc/test_editor.py +++ b/tests/unit/misc/test_editor.py @@ -22,7 +22,6 @@ import os import os.path import logging -from unittest import mock from PyQt5.QtCore import QProcess import pytest @@ -40,7 +39,6 @@ def patch_things(config_stub, monkeypatch, stubs): @pytest.fixture def editor(caplog): ed = editormod.ExternalEditor() - ed.editing_finished = mock.Mock() yield ed with caplog.at_level(logging.ERROR): ed._remove_file = True @@ -99,8 +97,7 @@ class TestFileHandling: filename = editor._filename assert os.path.exists(filename) - editor._proc._proc.exitStatus = mock.Mock( - return_value=QProcess.CrashExit) + editor._proc._proc.exitStatus = lambda: QProcess.CrashExit editor._proc.finished.emit(1, QProcess.NormalExit) assert os.path.exists(filename) @@ -113,8 +110,7 @@ class TestFileHandling: filename = editor._filename assert os.path.exists(filename) - editor._proc._proc.exitStatus = mock.Mock( - return_value=QProcess.CrashExit) + editor._proc._proc.exitStatus = lambda: QProcess.CrashExit editor._proc.error.emit(QProcess.Crashed) editor._proc.finished.emit(0, QProcess.CrashExit) @@ -167,7 +163,7 @@ class TestFileHandling: ('Hällö Wörld', 'Überprüfung'), ('\u2603', '\u2601') # Unicode snowman -> cloud ]) -def test_modify(editor, initial_text, edited_text): +def test_modify(qtbot, editor, initial_text, edited_text): """Test if inputs get modified correctly.""" editor.edit(initial_text) @@ -177,5 +173,7 @@ def test_modify(editor, initial_text, edited_text): with open(editor._filename, 'w', encoding='utf-8') as f: f.write(edited_text) - editor._proc.finished.emit(0, QProcess.NormalExit) - editor.editing_finished.emit.assert_called_with(edited_text) + with qtbot.wait_signal(editor.editing_finished) as blocker: + editor._proc.finished.emit(0, QProcess.NormalExit) + + assert blocker.args == [edited_text]