Example #1
0
def test_InfiniteProcess__catches_error_in_teardown_after_loop(mocker):
    expected_error = ValueError("error during teardown")
    error_queue = SimpleMultiprocessingQueue()
    p = InfiniteProcessThatRaisesErrorInTeardown(error_queue)
    mocker.patch("builtins.print",
                 autospec=True)  # don't print the error message to stdout
    p.run(num_iterations=1)
    assert error_queue.empty() is False
    actual_error, _ = error_queue.get_nowait()
    assert isinstance(actual_error, type(expected_error))
    assert str(actual_error) == str(expected_error)
Example #2
0
def test_InfiniteProcess__catches_error_in_setup_before_loop_and_does_not_run_iteration_or_teardown(
    mocker, ):
    expected_error = ValueError("error during setup")
    error_queue = SimpleMultiprocessingQueue()
    p = InfiniteProcessThatRaisesErrorInSetup(error_queue)
    mocker.patch("builtins.print",
                 autospec=True)  # don't print the error message to stdout
    p.run(num_iterations=1)
    assert error_queue.empty() is False
    actual_error, _ = error_queue.get_nowait()
    assert p.get_num_iterations() == 0
    assert p.is_teardown_complete() is False
    assert isinstance(actual_error, type(expected_error))
    assert str(actual_error) == str(expected_error)
Example #3
0
def test_SimpleMultiprocessingQueue__put_nowait__adds_value_to_queue():
    test_queue = SimpleMultiprocessingQueue()
    expected = "blah7"
    test_queue.put_nowait(expected)
    actual = test_queue.get_nowait()
    assert actual == expected
Example #4
0
def test_SimpleMultiprocessingQueue__get_nowait__raises_error_if_empty():
    test_queue = SimpleMultiprocessingQueue()
    with pytest.raises(queue.Empty):
        test_queue.get_nowait()
Example #5
0
def test_SimpleMultiprocessingQueue__get_nowait__returns_value_if_present():
    test_queue = SimpleMultiprocessingQueue()
    expected = "blah"
    test_queue.put(expected)
    actual = test_queue.get_nowait()
    assert actual == expected