File: test_timeout.py

package info (click to toggle)
labgrid 25.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,796 kB
  • sloc: python: 21,352; sh: 846; makefile: 35
file content (31 lines) | stat: -rw-r--r-- 741 bytes parent folder | download | duplicates (3)
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