-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_onthisday.py
executable file
·149 lines (126 loc) · 5.42 KB
/
test_onthisday.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
"""
Unit tests for contact_sheet.py
"""
import datetime
import unittest
import onthisday
class TestSequenceFunctions(unittest.TestCase):
# def setUp(self):
# self.seq = range(10)
def daterange(self, start_date, end_date):
# https://stackoverflow.com/q/1060279/724176
for n in range(int((end_date - start_date).days)):
yield start_date + datetime.timedelta(n)
def test_changed(self):
""" Test return isn't same as parameter """
input = datetime.datetime.now()
output = onthisday.six_months_ago(input)
self.assertNotEqual(input, output)
def test_dec_to_june(self):
""" Test 22 December 2013 -> 22 June 2013 """
input = datetime.datetime(2013, 12, 22)
expected_output = datetime.datetime(2013, 6, 22)
output = onthisday.six_months_ago(input)
self.assertEqual(expected_output, output)
def test_jan_to_july(self):
""" Test 20 January 2014 -> 20 July 2013 """
input = datetime.datetime(2014, 1, 20)
expected_output = datetime.datetime(2013, 7, 20)
output = onthisday.six_months_ago(input)
self.assertEqual(expected_output, output)
def test_from_31st_jan(self):
""" Test 31 January 2014 -> 31 July 2013 """
input = datetime.datetime(2014, 1, 31)
expected_output = datetime.datetime(2013, 7, 31)
output = onthisday.six_months_ago(input)
self.assertEqual(expected_output, output)
def test_from_31st_march(self):
""" Test 31 March 2014 -> 30 September 2013 """
input = datetime.datetime(2014, 3, 31)
expected_output = datetime.datetime(2013, 9, 30)
output = onthisday.six_months_ago(input)
self.assertEqual(expected_output, output)
def test_to_last_of_feb(self):
""" Test 31 August 2014 -> 28 Feb 2014 """
input = datetime.datetime(2014, 8, 31)
expected_output = datetime.datetime(2014, 2, 28)
output = onthisday.six_months_ago(input)
self.assertEqual(expected_output, output)
def test_to_leap_day(self):
""" Test 31 August 2012 -> 29 Feb 2012 """
input = datetime.datetime(2012, 8, 31)
expected_output = datetime.datetime(2012, 2, 29)
output = onthisday.six_months_ago(input)
self.assertEqual(expected_output, output)
def test_lots_of_days(self):
"""Tests:
No "ValueError: day is out of range for month" exceptions raised
(e.g. for 30 Feb),
output value is different from input, and
output value is earlier than input
"""
start_date = datetime.datetime(2000, 1, 1)
end_date = datetime.datetime(2030, 12, 31)
for input in self.daterange(start_date, end_date):
output = onthisday.six_months_ago(input)
self.assertNotEqual(input, output)
self.assertLess(output, input)
def test_2_changed(self):
""" Test return isn't same as parameter """
input = datetime.datetime.now()
output = onthisday.six_months_from(input)
self.assertNotEqual(input, output)
def test_2_dec_to_june(self):
""" Test 22 December 2013 -> 22 June 2014 """
input = datetime.datetime(2013, 12, 22)
expected_output = datetime.datetime(2014, 6, 22)
output = onthisday.six_months_from(input)
self.assertEqual(expected_output, output)
def test_2_jan_to_july(self):
""" Test 20 January 2014 -> 20 July 2014 """
input = datetime.datetime(2014, 1, 20)
expected_output = datetime.datetime(2014, 7, 20)
output = onthisday.six_months_from(input)
self.assertEqual(expected_output, output)
def test_2_from_31st_jan(self):
""" Test 31 January 2014 -> 31 July 2014 """
input = datetime.datetime(2014, 1, 31)
expected_output = datetime.datetime(2014, 7, 31)
output = onthisday.six_months_from(input)
self.assertEqual(expected_output, output)
def test_2_from_31st_march(self):
""" Test 31 March 2014 -> None """
input = datetime.datetime(2014, 3, 31)
expected_output = None
output = onthisday.six_months_from(input)
self.assertEqual(expected_output, output)
def test_2_to_last_of_feb(self):
""" Test 31 August 2014 -> 28 Feb 2015 """
input = datetime.datetime(2014, 8, 31)
expected_output = None
output = onthisday.six_months_from(input)
self.assertEqual(expected_output, output)
def test_2_to_leap_day(self):
""" Test 31 August 2011 -> 29 Feb 2012 """
input = datetime.datetime(2011, 8, 31)
expected_output = None
output = onthisday.six_months_from(input)
self.assertEqual(expected_output, output)
def test_2_lots_of_days(self):
"""Some dates with day > 28 will return None. Forget those.
Tests:
days 1-28 don't return None
output value is different from input, and
output value is later than input
"""
for year in range(2000, 2030 + 1):
for month in range(1, 12):
for day in range(1, 28):
input = datetime.datetime(year, month, day)
output = onthisday.six_months_from(input)
self.assertIsNotNone(output)
self.assertNotEqual(input, output)
self.assertGreater(output, input)
if __name__ == "__main__":
unittest.main()