-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunit_tests0.py
More file actions
58 lines (29 loc) · 1.06 KB
/
unit_tests0.py
File metadata and controls
58 lines (29 loc) · 1.06 KB
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
import unittest
from time_of_day0 import *
from datetime import datetime
# Bad example of test to test poorly writtern testable code
# class Test(unittest.TestCase):
#
# def test(self):
#
# # Setup: change system time to 6AM
#
# time_of_day = get_time_of_day()
#
# self.assertEqual("Afternoon", time_of_day)
# Good examples of test for testable code
class Test(unittest.TestCase):
def test_morning(self):
time_of_day = get_time_of_day(datetime(2020, 7, 15, 6, 00, 00))
self.assertEqual("Morning", time_of_day)
def test_afternoon(self):
time_of_day = get_time_of_day(datetime(2020, 7, 15, 14, 12, 54))
self.assertEqual("Afternoon", time_of_day)
def test_evening(self):
time_of_day = get_time_of_day(datetime(2029, 7, 15, 23, 59, 59))
self.assertEqual("Evening", time_of_day)
def test_night(self):
time_of_day = get_time_of_day(datetime(2020, 7, 15, 2, 30, 00))
self.assertEqual("Night", time_of_day)
if __name__ == '__main__':
unittest.main()