tests: Add a test for a quitting testprocess.
This commit is contained in:
parent
dd211adf0f
commit
6c5e158fc5
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user