|
1
|
|
|
# pylint: disable=misplaced-comparison-constant,no-self-use |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
import pytest |
|
4
|
|
|
|
|
5
|
|
|
from mine.timestamp import Timestamp |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class TestTimestamp: |
|
9
|
|
|
|
|
10
|
|
|
"""Unit tests for the timestamp class.""" |
|
11
|
|
|
|
|
12
|
|
|
none = Timestamp() |
|
13
|
|
|
started_only = Timestamp(started=42) |
|
14
|
|
|
stopped_only = Timestamp(stopped=42) |
|
15
|
|
|
started_after_stopped = Timestamp(2, 1) |
|
16
|
|
|
stopped_after_started = Timestamp(3, 4) |
|
17
|
|
|
|
|
18
|
|
|
active_timestamp = [ |
|
19
|
|
|
(False, none), |
|
20
|
|
|
(True, started_only), |
|
21
|
|
|
(False, stopped_only), |
|
22
|
|
|
(True, started_after_stopped), |
|
23
|
|
|
(False, stopped_after_started), |
|
24
|
|
|
] |
|
25
|
|
|
|
|
26
|
|
|
repr_timestamp = [ |
|
27
|
|
|
("<timestamp 0>", none), |
|
28
|
|
|
("<timestamp 42>", started_only), |
|
29
|
|
|
("<timestamp 42>", stopped_only), |
|
30
|
|
|
("<timestamp 2>", started_after_stopped), |
|
31
|
|
|
("<timestamp 4>", stopped_after_started), |
|
32
|
|
|
] |
|
33
|
|
|
|
|
34
|
|
|
@pytest.mark.parametrize("representation,timestamp", repr_timestamp) |
|
35
|
|
|
def test_repr(self, representation, timestamp): |
|
36
|
|
|
"""Verify timestamps can represented as strings.""" |
|
37
|
|
|
assert representation == repr(timestamp) |
|
38
|
|
|
|
|
39
|
|
|
def test_eq(self): |
|
40
|
|
|
"""Verify timestamps can be equated.""" |
|
41
|
|
|
assert Timestamp(1, 1) == Timestamp(1, 1) |
|
42
|
|
|
assert Timestamp(1, 2) == Timestamp(1, 2) |
|
43
|
|
|
assert Timestamp(1, 2) != Timestamp(1, 3) |
|
44
|
|
|
assert Timestamp(4, 2) == Timestamp(4, 3) |
|
45
|
|
|
|
|
46
|
|
|
def test_lt(self): |
|
47
|
|
|
"""Verify timestamps can be sorted.""" |
|
48
|
|
|
assert Timestamp(1, 2) < Timestamp(1, 3) |
|
49
|
|
|
assert Timestamp(1, 4) > Timestamp(1, 3) |
|
50
|
|
|
assert Timestamp(4, 2) < Timestamp(5, 3) |
|
51
|
|
|
assert Timestamp(3, 2) < Timestamp(4, 3) |
|
52
|
|
|
|
|
53
|
|
|
@pytest.mark.parametrize("active,timestamp", active_timestamp) |
|
54
|
|
|
def test_active(self, active, timestamp): |
|
55
|
|
|
"""Verify started/stopped counters determine activity.""" |
|
56
|
|
|
assert active == timestamp.active |
|
57
|
|
|
|