-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_stime.py
123 lines (95 loc) · 3.85 KB
/
test_stime.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import pytest
from const import DAY_STRING
from const import HOUR_STRING
from const import MINUTE_STRING
from const import SECONDE_STRING
from const import SECONDES_PER_MINUTES
from const import MINUTES_PER_HOURS
from const import HOURS_PER_DAY
from const import NO_TIME_STRING
#
# TIME TO SEC (string to float)
#
from stime import time_to_sec
@pytest.mark.time_to_sec
def test_1_minute_to_sec():
assert time_to_sec(f"1{MINUTE_STRING}") == SECONDES_PER_MINUTES
@pytest.mark.time_to_sec
def test_1_hour_to_sec():
assert time_to_sec(f"1{HOUR_STRING}") == SECONDES_PER_MINUTES * MINUTES_PER_HOURS
@pytest.mark.time_to_sec
def test_1_day_to_sec():
assert time_to_sec(f"1{DAY_STRING}") == SECONDES_PER_MINUTES * MINUTES_PER_HOURS * HOURS_PER_DAY
@pytest.mark.time_to_sec
def test_1_sec_to_sec():
assert time_to_sec(f"1{SECONDE_STRING}") == 1
@pytest.mark.time_to_sec
def test_1515_sec_to_sec():
assert time_to_sec(f"15.15{SECONDE_STRING}") == 15.15
@pytest.mark.time_to_sec
def test_1_hour_1_sec_to_sec():
assert time_to_sec(f"1{HOUR_STRING}1{SECONDE_STRING}") == SECONDES_PER_MINUTES * MINUTES_PER_HOURS + 1
@pytest.mark.time_to_sec
def test_1_day_1_minute_to_sec():
assert time_to_sec(f"1{DAY_STRING}1{MINUTE_STRING}") == SECONDES_PER_MINUTES * MINUTES_PER_HOURS * HOURS_PER_DAY + SECONDES_PER_MINUTES
@pytest.mark.time_to_sec
def test_1_day_1_hour_1_minute_1_sec_to_sec():
assert time_to_sec(f"1{DAY_STRING}1{HOUR_STRING}1{MINUTE_STRING}1{SECONDE_STRING}") == SECONDES_PER_MINUTES * MINUTES_PER_HOURS * HOURS_PER_DAY + SECONDES_PER_MINUTES + SECONDES_PER_MINUTES * MINUTES_PER_HOURS + 1
@pytest.mark.time_to_sec
def test_0_to_sec():
assert time_to_sec("") == 0
@pytest.mark.time_to_sec
def test_neg_to_sec():
with pytest.raises(ValueError):
time_to_sec("-1h")
@pytest.mark.time_to_sec
def test_s_not_in_range_to_sec():
with pytest.raises(ValueError):
time_to_sec(f"{SECONDES_PER_MINUTES + 1}s")
@pytest.mark.time_to_sec
def test_m_not_in_range_to_sec():
with pytest.raises(ValueError):
time_to_sec(f"{MINUTES_PER_HOURS + 15}m")
@pytest.mark.time_to_sec
def test_h_not_in_range_to_sec():
with pytest.raises(ValueError):
time_to_sec(f"{HOURS_PER_DAY + 10}h")
@pytest.mark.time_to_sec
def test_multiple_to_sec():
with pytest.raises(ValueError):
time_to_sec("1h3m2d1h")
#
# SEC TO TIME (float to string)
#
from stime import sec_to_time
@pytest.mark.sec_to_time
def test_1_hour_to_time():
assert sec_to_time(SECONDES_PER_MINUTES * MINUTES_PER_HOURS) == f"1{HOUR_STRING}"
@pytest.mark.sec_to_time
def test_1_minute_to_time():
assert sec_to_time(SECONDES_PER_MINUTES) == f"1{MINUTE_STRING}"
@pytest.mark.sec_to_time
def test_1_day_to_time():
assert sec_to_time(SECONDES_PER_MINUTES * MINUTES_PER_HOURS * HOURS_PER_DAY) == f"1{DAY_STRING}"
@pytest.mark.sec_to_time
def test_1_sec_to_time():
assert sec_to_time(1) == f"1{SECONDE_STRING}"
@pytest.mark.sec_to_time
def test_0_to_time():
assert sec_to_time(0) == NO_TIME_STRING
@pytest.mark.sec_to_time
def test_neg_to_time():
with pytest.raises(ValueError):
sec_to_time(-1)
@pytest.mark.sec_to_time
def test_1515_sec_to_time():
assert sec_to_time(15.15) == f"15.15{SECONDE_STRING}"
@pytest.mark.sec_to_time
def test_1_hour_1_sec_to_time():
assert sec_to_time(SECONDES_PER_MINUTES * MINUTES_PER_HOURS + 1) == f"1{HOUR_STRING}1{SECONDE_STRING}"
@pytest.mark.sec_to_time
def test_1_day_1_minute_to_time():
assert sec_to_time(SECONDES_PER_MINUTES * MINUTES_PER_HOURS * HOURS_PER_DAY + SECONDES_PER_MINUTES) == f"1{DAY_STRING}1{MINUTE_STRING}"
@pytest.mark.sec_to_time
def test_1_day_1_hour_1_minute_1_sec_to_time():
assert sec_to_time(SECONDES_PER_MINUTES * MINUTES_PER_HOURS * HOURS_PER_DAY + SECONDES_PER_MINUTES + SECONDES_PER_MINUTES * MINUTES_PER_HOURS + 1) == f"1{DAY_STRING}1{HOUR_STRING}1{MINUTE_STRING}1{SECONDE_STRING}"