diff --git a/tests/misc/test_editor.py b/tests/misc/test_editor.py index 10142b525..773769f80 100644 --- a/tests/misc/test_editor.py +++ b/tests/misc/test_editor.py @@ -43,7 +43,7 @@ class TestArg: @pytest.yield_fixture(autouse=True) def setup(self, monkeypatch, stubs): monkeypatch.setattr('qutebrowser.misc.editor.guiprocess.QProcess', - stubs.FakeQProcess()) + stubs.fake_qprocess()) self.editor = editor.ExternalEditor(0) yield self.editor._cleanup() # pylint: disable=protected-access @@ -102,7 +102,7 @@ class TestFileHandling: monkeypatch.setattr('qutebrowser.misc.editor.message', stubs.MessageModule()) monkeypatch.setattr('qutebrowser.misc.editor.guiprocess.QProcess', - stubs.FakeQProcess()) + stubs.fake_qprocess()) config_stub.data = {'general': {'editor': [''], 'editor-encoding': 'utf-8'}} monkeypatch.setattr('qutebrowser.misc.editor.config', config_stub) @@ -149,7 +149,7 @@ class TestModifyTests: @pytest.fixture(autouse=True) def setup(self, monkeypatch, stubs, config_stub): monkeypatch.setattr('qutebrowser.misc.editor.guiprocess.QProcess', - stubs.FakeQProcess()) + stubs.fake_qprocess()) config_stub.data = {'general': {'editor': [''], 'editor-encoding': 'utf-8'}} monkeypatch.setattr('qutebrowser.misc.editor.config', config_stub) @@ -221,7 +221,7 @@ class TestErrorMessage: @pytest.yield_fixture(autouse=True) def setup(self, monkeypatch, stubs, config_stub): monkeypatch.setattr('qutebrowser.misc.editor.guiprocess.QProcess', - stubs.FakeQProcess()) + stubs.fake_qprocess()) monkeypatch.setattr('qutebrowser.misc.editor.message', stubs.MessageModule()) config_stub.data = {'general': {'editor': [''], diff --git a/tests/stubs.py b/tests/stubs.py index 9d7091581..381ccea7d 100644 --- a/tests/stubs.py +++ b/tests/stubs.py @@ -147,22 +147,13 @@ class FakeNetworkReply: self.headers[key] = value -class FakeQProcess(mock.Mock): - - """QProcess stub. - - Gets some enum values from the real QProcess. - """ - - NormalExit = QProcess.NormalExit - CrashExit = QProcess.CrashExit - - FailedToStart = QProcess.FailedToStart - Crashed = QProcess.Crashed - Timedout = QProcess.Timedout - WriteError = QProcess.WriteError - ReadError = QProcess.ReadError - UnknownError = QProcess.UnknownError +def fake_qprocess(): + """Factory for a QProcess mock which has the QProcess enum values.""" + m = mock.Mock(spec=QProcess) + for attr in ['NormalExit', 'CrashExit', 'FailedToStart', 'Crashed', + 'Timedout', 'WriteError', 'ReadError', 'UnknownError']: + setattr(m, attr, getattr(QProcess, attr)) + return m class FakeSignal: