Change FakeQProcess stub to a function with spec.

This commit is contained in:
Florian Bruhin 2015-06-11 23:02:18 +02:00
parent d3b727d0c7
commit fc5349e1dc
2 changed files with 11 additions and 20 deletions

View File

@ -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': [''],

View File

@ -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: