From 6c5e158fc5d29fb916699eba1ad2f37ccdc1eff0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 17 Jan 2016 20:19:41 +0100 Subject: [PATCH] tests: Add a test for a quitting testprocess. --- tests/integration/test_testprocess.py | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/integration/test_testprocess.py b/tests/integration/test_testprocess.py index 4f4bbea94..b9c91c199 100644 --- a/tests/integration/test_testprocess.py +++ b/tests/integration/test_testprocess.py @@ -74,6 +74,29 @@ class PythonProcess(testprocess.Process): return (sys.executable, ['-c', ';'.join(code)]) +class QuitPythonProcess(testprocess.Process): + + """A testprocess which quits immediately.""" + + def __init__(self): + super().__init__() + self.proc.setReadChannel(QProcess.StandardOutput) + + def _parse_line(self, line): + print("LINE: {}".format(line)) + if line.strip() == 'ready': + self.ready.emit() + return testprocess.Line(line) + + def _executable_args(self): + code = [ + 'import sys', + 'print("ready")', + 'sys.exit(0)', + ] + return (sys.executable, ['-c', ';'.join(code)]) + + @pytest.yield_fixture def pyproc(): proc = PythonProcess() @@ -81,6 +104,20 @@ def pyproc(): proc.terminate() +@pytest.yield_fixture +def quit_pyproc(): + proc = QuitPythonProcess() + yield proc + proc.terminate() + + +def test_quitting_process(qtbot, quit_pyproc): + with qtbot.waitSignal(quit_pyproc.proc.finished): + quit_pyproc.start() + with pytest.raises(testprocess.ProcessExited): + quit_pyproc.after_test() + + def test_wait_signal_raising(qtbot): """testprocess._wait_signal should raise by default.""" proc = testprocess.Process()