-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
58 lines (46 loc) · 1.6 KB
/
test.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
#!/usr/bin/env python3
from datetime import datetime, timedelta
from pycron import CronTime
def test1():
crontime = CronTime("* * * * *")
dt = datetime(2024, 3, 4, 23, 1, 0, 0)
tick1 = crontime.next_tick(dt)
tick2 = crontime.next_tick(tick1)
tick3 = crontime.next_tick(tick2)
tick4 = crontime.next_tick(tick3)
tick5 = crontime.next_tick(tick4)
expected_tick_1 = dt + timedelta(minutes=1)
expected_tick_2 = dt + timedelta(minutes=2)
expected_tick_3 = dt + timedelta(minutes=3)
expected_tick_4 = dt + timedelta(minutes=4)
expected_tick_5 = dt + timedelta(minutes=5)
assert tick1 == expected_tick_1
assert tick2 == expected_tick_2
assert tick3 == expected_tick_3
assert tick4 == expected_tick_4
assert tick5 == expected_tick_5
print("[Test 1] Passed!")
def test2():
crontime = CronTime("@minutely")
dt = datetime(2024, 3, 4, 23, 1, 0, 0)
tick1 = crontime.next_tick(dt)
tick2 = crontime.next_tick(tick1)
tick3 = crontime.next_tick(tick2)
tick4 = crontime.next_tick(tick3)
tick5 = crontime.next_tick(tick4)
expected_tick_1 = dt + timedelta(minutes=1)
expected_tick_2 = dt + timedelta(minutes=2)
expected_tick_3 = dt + timedelta(minutes=3)
expected_tick_4 = dt + timedelta(minutes=4)
expected_tick_5 = dt + timedelta(minutes=5)
assert tick1 == expected_tick_1
assert tick2 == expected_tick_2
assert tick3 == expected_tick_3
assert tick4 == expected_tick_4
assert tick5 == expected_tick_5
print("[Test 2] Passed!")
def Main():
test1()
test2()
if __name__ == "__main__":
Main()