-
Notifications
You must be signed in to change notification settings - Fork 1
/
jrnltime_tests.py
executable file
·169 lines (159 loc) · 5.27 KB
/
jrnltime_tests.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python
import unittest
import jrnltime
class JrnlTime(unittest.TestCase):
def setUp(self):
self.jrnl = jrnltime.JrnlTime()
def tearDown(self):
pass
def test_workdays_one_day(self):
jrnldata = {
'entries': [
{
'title': 'entry 0',
'body': 'workstart @time',
'date': '2015-04-28',
'time': '08:00',
},
{
'title': 'entry 1 workend @time',
'body': 'yo',
'date': '2015-04-28',
'time': '16:00',
},
]
}
n_days, n_hours, hours_in_lieu = self.jrnl.get_workdays(jrnldata)
self.assertEquals(n_days, 1)
self.assertEquals(n_hours, 8)
self.assertEquals(hours_in_lieu, 0)
def test_workdays_two_days(self):
jrnldata = {
'entries': [
{
'title': 'entry 0',
'body': 'workstart @time',
'date': '2015-04-28',
'time': '08:00',
},
{
'title': 'entry 1 workend @time',
'body': 'yo',
'date': '2015-04-28',
'time': '16:00',
},
{
'title': 'entry 2 workstart @time',
'body': 'foo',
'date': '2015-04-29',
'time': '09:00',
},
{
'title': 'entry 3 workend @time',
'body': 'bar',
'date': '2015-04-29',
'time': '15:00',
},
]
}
n_days, n_hours, hours_in_lieu = self.jrnl.get_workdays(jrnldata)
self.assertEquals(n_days, 2)
self.assertEquals(n_hours, 8+6)
self.assertEquals(hours_in_lieu, -2)
def test_workdays_one_day_two_entries(self):
jrnldata = {
'entries': [
{
'title': 'entry 0',
'body': 'workstart @time',
'date': '2015-04-28',
'time': '08:00',
},
{
'title': 'entry 1 workend @time',
'body': 'yo',
'date': '2015-04-28',
'time': '16:00',
},
{
'title': 'entry 2 workstart @time',
'body': 'foo',
'date': '2015-04-28',
'time': '20:00',
},
{
'title': 'entry 3 workend @time',
'body': 'bar',
'date': '2015-04-28',
'time': '21:00',
},
]
}
n_days, n_hours, hours_in_lieu = self.jrnl.get_workdays(jrnldata)
self.assertEquals(n_days, 1)
self.assertEquals(n_hours, 8+1)
self.assertEquals(hours_in_lieu, 1)
def test_workdays_one_day_two_entries_working_late(self):
jrnldata = {
'entries': [
{
'title': 'entry 0',
'body': 'workstart @time',
'date': '2015-04-28',
'time': '08:00',
},
{
'title': 'entry 1 workend @time',
'body': 'yo',
'date': '2015-04-28',
'time': '16:00',
},
{
'title': 'entry 2 workstart @time',
'body': 'foo',
'date': '2015-04-28',
'time': '23:00',
},
{
'title': 'entry 3 workend @time',
'body': 'bar',
'date': '2015-04-29',
'time': '01:00',
},
]
}
n_days, n_hours, hours_in_lieu = self.jrnl.get_workdays(jrnldata)
# Starting a workday on day A and ending on day A+1 should count as
# "1 workday with extra hours".
self.assertEquals(n_days, 1)
self.assertEquals(n_hours, 8+2)
self.assertEquals(hours_in_lieu, 2)
def test_workdays_workday_in_progress(self):
jrnldata = {
'entries': [
{
'title': 'entry 0',
'body': 'workstart @time',
'date': '2015-04-28',
'time': '08:00',
},
{
'title': 'entry 1 workend @time',
'body': 'yo',
'date': '2015-04-28',
'time': '16:00',
},
{
'title': 'entry 2 workstart @time',
'body': 'foo',
'date': '2015-04-29',
'time': '08:00',
},
]
}
n_days, n_hours, hours_in_lieu = self.jrnl.get_workdays(jrnldata)
self.assertEquals(n_days, 1)
self.assertEquals(n_hours, 8)
self.assertEquals(hours_in_lieu, 0)
if __name__ == '__main__':
unittest.main()