def test_timeout(): start = datetime.now() with pytest.raises(TimeoutError): popen_streaming_output('python -c "import time; time.sleep(4)"', lambda line: line, timeout=0.1) assert (datetime.now() - start).total_seconds() < 3
def test_popen_streaming_output_timeout(): start = time() with pytest.raises(TimeoutError): popen_streaming_output('python -c "import time; time.sleep(4)"', lambda line: line, timeout=0.1) assert (time() - start) < 3
def test_popen_streaming_output_stream(): mock = MagicMock() popen_streaming_output('python -c "print(\'first\'); print(\'second\')"', callback=mock) mock.assert_has_calls([call('first'), call('second')]) mock = MagicMock() popen_streaming_output( 'python -c "import time; print(\'first\'); time.sleep(1); print(\'second\'); print(\'third\')"', callback=mock) mock.assert_has_calls([call('first'), call('second'), call('third')]) mock = MagicMock() popen_streaming_output('python -c "exit(0);"', callback=mock) mock.assert_not_called()