130
def doctest_first_of_month():
131
"""Tests for first_of_month
133
>>> from gtimelog import first_of_month
134
>>> from datetime import date, timedelta
136
>>> first_of_month(date(2007, 1, 1))
137
datetime.date(2007, 1, 1)
139
>>> first_of_month(date(2007, 1, 7))
140
datetime.date(2007, 1, 1)
142
>>> first_of_month(date(2007, 1, 31))
143
datetime.date(2007, 1, 1)
145
>>> first_of_month(date(2007, 2, 1))
146
datetime.date(2007, 2, 1)
148
>>> first_of_month(date(2007, 2, 28))
149
datetime.date(2007, 2, 1)
151
>>> first_of_month(date(2007, 3, 1))
152
datetime.date(2007, 3, 1)
154
Why not test extensively?
156
>>> d = date(2000, 1, 1)
157
>>> while d < date(2005, 1, 1):
158
... f = first_of_month(d)
159
... if (f.year, f.month, f.day) != (d.year, d.month, 1):
160
... print "WRONG: first_of_month(%r) returned %r" % (d, f)
161
... d += timedelta(1)
165
def doctest_next_month():
166
"""Tests for next_month
168
>>> from gtimelog import next_month
169
>>> from datetime import date, timedelta
171
>>> next_month(date(2007, 1, 1))
172
datetime.date(2007, 2, 1)
174
>>> next_month(date(2007, 1, 7))
175
datetime.date(2007, 2, 1)
177
>>> next_month(date(2007, 1, 31))
178
datetime.date(2007, 2, 1)
180
>>> next_month(date(2007, 2, 1))
181
datetime.date(2007, 3, 1)
183
>>> next_month(date(2007, 2, 28))
184
datetime.date(2007, 3, 1)
186
>>> next_month(date(2007, 3, 1))
187
datetime.date(2007, 4, 1)
189
Why not test extensively?
191
>>> d = date(2000, 1, 1)
192
>>> while d < date(2005, 1, 1):
193
... f = next_month(d)
194
... prev = f - timedelta(1)
195
... if f.day != 1 or (prev.year, prev.month) != (d.year, d.month):
196
... print "WRONG: next_month(%r) returned %r" % (d, f)
197
... d += timedelta(1)
131
201
def doctest_uniq():
132
202
"""Tests for uniq
214
def doctest_TimeWindow_monthly_report():
215
r"""Tests for TimeWindow.monthly_report
219
>>> from datetime import datetime, time
220
>>> from tempfile import NamedTemporaryFile
221
>>> from gtimelog import TimeWindow
224
>>> min = datetime(2007, 9, 1)
225
>>> max = datetime(2007, 10, 1)
226
>>> fh = NamedTemporaryFile()
228
>>> window = TimeWindow(fh.name, min, max, vm)
229
>>> window.monthly_report(sys.stdout, 'foo@bar.com', 'Bob Jones')
231
Subject: Monthly report for Bob Jones (2007/09)
233
No work done this month.
235
>>> _ = [fh.write(s + '\n') for s in [
236
... '2007-09-30 09:00: start',
237
... '2007-09-30 09:23: Bing: stuff',
238
... '2007-09-30 12:54: Bong: other stuff',
239
... '2007-09-30 13:32: lunch **',
240
... '2007-09-30 15:46: misc',
244
>>> window = TimeWindow(fh.name, min, max, vm)
245
>>> window.monthly_report(sys.stdout, 'foo@bar.com', 'Bob Jones')
247
Subject: Monthly report for Bob Jones (2007/09)
251
Bong: other stuff 3 hours 31 min
254
Total work done this month: 6 hours 8 min
260
(none) 2 hours 14 min
144
265
if __name__ == '__main__':
146
267
fail, total = doctest.testmod()