Exemple #1
0
def test_with_custom_exception_instance():
    exc = ValueError("an instance of an excepiton")
    timeout = Timeout(0.01, exc)
    timeout.start()
    time.sleep(0.02)
    with pytest.raises(ValueError) as err:
        timeout.check()

    assert err.value is exc
Exemple #2
0
def test_inline_timeout():
    timeout = Timeout(0.01)
    timeout.start()
    time.sleep(0.02)
    with pytest.raises(Timeout):
        timeout.check()
Exemple #3
0
def test_with_custom_exception_type():
    timeout = Timeout(0.01, ValueError)
    timeout.start()
    time.sleep(0.02)
    with pytest.raises(ValueError):
        timeout.check()
Exemple #4
0
def test_inline_completion_before_timeout():
    timeout = Timeout(0.01)
    timeout.start()
    timeout.check()
    timeout.cancel()
    time.sleep(0.02)