How to use the mutmut.popen_streaming_output function in mutmut

To help you get started, we’ve selected a few mutmut examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github boxed / mutmut / tests / test_main.py View on Github external
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
github boxed / mutmut / tests / test_main.py View on Github external
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:
github boxed / mutmut / mutmut / __main__.py View on Github external
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