Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
)
if os.name == 'nt':
mock.assert_has_calls([call('first\r\n'), call('second\r\n')])
else:
mock.assert_has_calls([call('first\n'), call('second\n')])
mock = MagicMock()
popen_streaming_output(
PYTHON + ' -c "import time; print(\'first\'); print(\'second\'); print(\'third\')"',
callback=mock
)
if os.name == 'nt':
mock.assert_has_calls([call('first\r\n'), call('second\r\n'), call('third\r\n')])
else:
if cached_time is not None and current_hash_of_tests == cached_hash_of_tests():
print('1. Using cached time for baseline tests, to run baseline again delete the cache file')
return cached_time
print('1. Running tests without mutations')
start_time = time()
output = []
def feedback(line):
if not swallow_output:
print(line)
print_status('Running...')
output.append(line)
returncode = popen_streaming_output(test_command, feedback)
if returncode == 0 or (using_testmon and returncode == 5):
baseline_time_elapsed = time() - start_time
else:
raise RuntimeError("Tests don't run cleanly without mutations. Test command was: {}\n\nOutput:\n\n{}".format(test_command, '\n'.join(output)))
print('Done')
set_cached_test_time(baseline_time_elapsed, current_hash_of_tests)
return baseline_time_elapsed