-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_time.py
62 lines (50 loc) · 1.57 KB
/
test_time.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
from generallibrary import RedirectStdout
from generallibrary.time import *
import unittest
class TimeTest(unittest.TestCase):
def test_timerAndSleep(self):
timer = Timer(print_out=False)
sleep(0.1)
secs = timer.time()
self.assertTrue(0 < secs < 1)
def test_timer_context(self):
x = []
with RedirectStdout(x):
with Timer():
pass
self.assertIn(Timer.UNIT, x[0])
def test_timer_method_deco(self):
class X:
@Timer
def y(self):
pass
x = []
with RedirectStdout(x):
X().y()
self.assertIn(Timer.UNIT, x[0])
def test_timer_deco(self):
@Timer
def y():
pass
x = []
with RedirectStdout(x):
y()
self.assertIn(Timer.UNIT, x[0])
def test_timer_deco_no_print(self):
@Timer(print_out=False)
def y():
pass
x = []
with RedirectStdout(x):
y()
self.assertEqual([], x)
def test_current_date_and_time(self):
Date.now()
Date.get_timezone_obj()
def test_get_datetime_format(self):
self.assertEqual(True, isinstance(Date.format, str))
def test_time(self):
now = Date.now()
self.assertEqual(now, Date(str(now)))
# AssertionError: 2021-11-19 00:22 CET != 2021-11-18 00:22 CET < workflow unittest
# self.assertEqual(now, Date(f"{now.datetime.hour}:{now.datetime.minute}")) # Todo: Fix time casting to wrong day when past midnight.