1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import pytest
from labgrid.util import Timeout
class TestTimeout:
def test_create(self):
t = Timeout()
assert (isinstance(t, Timeout))
t = Timeout(5.0)
assert (isinstance(t, Timeout))
with pytest.raises(TypeError):
t = Timeout(10)
with pytest.raises(ValueError):
t = Timeout(-1.0)
def test_expire(self, mocker):
m = mocker.patch('time.monotonic')
m.return_value = 0.0
t = Timeout(5.0)
assert not t.expired
assert t.remaining == 5.0
m.return_value += 3.0
assert not t.expired
assert t.remaining == 2.0
m.return_value += 3.0
assert t.expired
assert t.remaining == 0.0
|