-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
256 lines (233 loc) · 5.11 KB
/
test.py
File metadata and controls
256 lines (233 loc) · 5.11 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import unittest
from datetime import datetime as dt
from datetime import timedelta as td
from logtime.logtime import Log
from logtime.logtime import LogItem
from logtime.query import parse
from logtime.utils import fix
class CutDate(unittest.TestCase):
def test_01(self):
l = LogItem(
dt(2016, 10, 1), dt(2016, 10, 1), []
).cut_to_dates(dt(2015, 1, 1), dt(2017, 1, 1))
self.assertEqual(
l,
LogItem(
dt(2016, 10, 1), dt(2016, 10, 1), []
)
)
def test_02(self):
l = LogItem(
dt(2016, 10, 1), dt(2016, 10, 1), []
).cut_to_dates(dt(2017, 1, 1), dt(2017, 1, 1))
self.assertEqual(
l, None
)
def test_03(self):
l = LogItem(
dt(2016, 10, 1), dt(2016, 10, 1), []
).cut_to_dates(dt(2015, 1, 1), dt(2015, 1, 1))
self.assertEqual(
l, None
)
def test_04(self):
l = LogItem(
dt(2016, 10, 1), dt(2016, 10, 10), []
).cut_to_dates(dt(2015, 1, 1), dt(2016, 10, 5))
self.assertEqual(
l,
LogItem(
dt(2016, 10, 1), dt(2016, 10, 5), []
)
)
def test_05(self):
l = LogItem(
dt(2016, 10, 1), dt(2016, 10, 10), []
).cut_to_dates(dt(2016, 10, 5), dt(2017, 1, 1))
self.assertEqual(
l,
LogItem(
dt(2016, 10, 5), dt(2016, 10, 10), []
)
)
def test_06(self):
l = LogItem(
dt(2016, 10, 1), dt(2016, 10, 10), []
).cut_to_dates(dt(2016, 10, 2), dt(2016, 10, 8))
self.assertEqual(
l,
LogItem(
dt(2016, 10, 2), dt(2016, 10, 8), []
)
)
def test_slicing_with_start(self):
log = Log("""
2018-06-28 09:00
test
2018-06-28 10:00
test2
2018-06-29 10:00
""")
output = str(log['2018-06-28':])
self.assertEqual(output, """2018-06-28 09:00
test
2018-06-28 10:00
test2
2018-06-29 10:00""")
def test_slicing_with_end(self):
log = Log("""
2018-06-28 09:00
test
2018-06-28 10:00
test2
2018-06-29 10:00
""")
output = str(log[:'2018-06-29'])
self.assertEqual(output, """2018-06-28 09:00
test
2018-06-28 10:00
test2
2018-06-29 00:00""")
def test_slicing_with_start_and_end(self):
log = Log("""
2018-06-28 09:00
test
2018-06-28 10:00
test2
2018-06-29 10:00
""")
output = str(log['2018-06-28 12:00':'2018-06-29'])
self.assertEqual(output, """2018-06-28 12:00
test2
2018-06-29 00:00""")
def test_slicing_with_start_end_and_step(self):
log = Log("""
2018-06-27 09:00
test0
2018-06-28 09:00
test1
2018-06-28 10:00
test2
2018-06-29 10:00
""")
output = log['2018-06-27':'2018-06-29':td(hours=24)]
self.assertEqual(str(output[0]), """2018-06-27 09:00
test0
2018-06-28 00:00""")
self.assertEqual(str(output[1]), """2018-06-28 00:00
test0
2018-06-28 09:00
test1
2018-06-28 10:00
test2
2018-06-29 00:00""")
def test_slicing_with_start_and_step(self):
log = Log("""
2018-06-27 09:00
test0
2018-06-28 09:00
test1
2018-06-28 10:00
test2
2018-06-29 10:00
""")
output = log['2018-06-27'::td(hours=24)]
self.assertEqual(str(output[0]), """2018-06-27 09:00
test0
2018-06-28 00:00""")
self.assertEqual(str(output[1]), """2018-06-28 00:00
test0
2018-06-28 09:00
test1
2018-06-28 10:00
test2
2018-06-29 00:00""")
self.assertEqual(str(output[2]), """2018-06-29 00:00
test2
2018-06-29 10:00""")
def test_slicing_with_step_function(self):
log = Log("""
2018-01-27 09:00
test
2018-03-29 10:00
""")
output = log[::lambda start: next_month(start)]
self.assertEqual(str(output[0]), """2018-01-27 09:00
test
2018-02-01 00:00""")
self.assertEqual(str(output[1]), """2018-02-01 00:00
test
2018-03-01 00:00""")
self.assertEqual(str(output[2]), """2018-03-01 00:00
test
2018-03-29 10:00""")
def next_month(start):
return (start + td(days=32)).replace(day=1, hour=0, minute=0, second=0)
class ParseAndSort(unittest.TestCase):
def test01(self):
fixed_log = fix("""
2018-05-20 09:00
foo
2018-05-20 20:00
2018-06-28 20:00
test
2018-06-28 10:00
test2
2018-06-29 11:00
2018-04-20 09:00
bar
2018-04-20 20:00
""")
self.assertEqual(fixed_log, """2018-04-20 09:00
bar
2018-04-20 20:00
2018-05-20 09:00
foo
2018-05-20 20:00
2018-06-28 10:00
test2
2018-06-28 20:00
test
2018-06-29 11:00""")
def test02(self):
fixed_log = fix("""
2018-05-20 09:00
foo
2018-05-20 20:00
2018-06-28 20:00
test
2018-06-28 10:00
test2
2018-06-29 11:00
2018-04-20 09:00
bar
2018-04-20 20:00
2019-01-01 01:00
last
""")
self.assertEqual(fixed_log, """2018-04-20 09:00
bar
2018-04-20 20:00
2018-05-20 09:00
foo
2018-05-20 20:00
2018-06-28 10:00
test2
2018-06-28 20:00
test
2019-01-01 01:00
last""")
def test03(self):
text = """2017-09-18 08:49
a3m
2017-09-18 17:49
2017-09-19 08:58
a3m
2017-09-19 17:58
2017-09-20 08:57
a3m
2017-09-20 17:57"""
log = Log(text)
self.assertEqual(str(log), text)
if __name__ == '__main__':
unittest.main()