~ubuntu-branches/ubuntu/vivid/gtimelog/vivid

« back to all changes in this revision

Viewing changes to test_gtimelog.py

  • Committer: Bazaar Package Importer
  • Author(s): Simon McVittie
  • Date: 2008-06-24 01:35:56 UTC
  • mfrom: (3.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080624013556-epl93105tw4dmqjn
Tags: 0.0+svn88-3
* Use my debian.org address
* Depend on python-eggtrayicon in preference to python-gnome2-extras
  (closes: #485317, #418885)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
    """
37
37
 
38
 
 
39
38
def doctest_format_duration_long():
40
39
    """Tests for format_duration_long.
41
40
 
128
127
 
129
128
    """
130
129
 
 
130
def doctest_first_of_month():
 
131
    """Tests for first_of_month
 
132
 
 
133
        >>> from gtimelog import first_of_month
 
134
        >>> from datetime import date, timedelta
 
135
 
 
136
        >>> first_of_month(date(2007, 1, 1))
 
137
        datetime.date(2007, 1, 1)
 
138
 
 
139
        >>> first_of_month(date(2007, 1, 7))
 
140
        datetime.date(2007, 1, 1)
 
141
 
 
142
        >>> first_of_month(date(2007, 1, 31))
 
143
        datetime.date(2007, 1, 1)
 
144
 
 
145
        >>> first_of_month(date(2007, 2, 1))
 
146
        datetime.date(2007, 2, 1)
 
147
 
 
148
        >>> first_of_month(date(2007, 2, 28))
 
149
        datetime.date(2007, 2, 1)
 
150
 
 
151
        >>> first_of_month(date(2007, 3, 1))
 
152
        datetime.date(2007, 3, 1)
 
153
 
 
154
    Why not test extensively?
 
155
 
 
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)
 
162
 
 
163
    """
 
164
 
 
165
def doctest_next_month():
 
166
    """Tests for next_month
 
167
 
 
168
        >>> from gtimelog import next_month
 
169
        >>> from datetime import date, timedelta
 
170
 
 
171
        >>> next_month(date(2007, 1, 1))
 
172
        datetime.date(2007, 2, 1)
 
173
 
 
174
        >>> next_month(date(2007, 1, 7))
 
175
        datetime.date(2007, 2, 1)
 
176
 
 
177
        >>> next_month(date(2007, 1, 31))
 
178
        datetime.date(2007, 2, 1)
 
179
 
 
180
        >>> next_month(date(2007, 2, 1))
 
181
        datetime.date(2007, 3, 1)
 
182
 
 
183
        >>> next_month(date(2007, 2, 28))
 
184
        datetime.date(2007, 3, 1)
 
185
 
 
186
        >>> next_month(date(2007, 3, 1))
 
187
        datetime.date(2007, 4, 1)
 
188
 
 
189
    Why not test extensively?
 
190
 
 
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)
 
198
 
 
199
    """
 
200
 
131
201
def doctest_uniq():
132
202
    """Tests for uniq
133
203
 
141
211
 
142
212
    """
143
213
 
 
214
def doctest_TimeWindow_monthly_report():
 
215
    r"""Tests for TimeWindow.monthly_report
 
216
 
 
217
        >>> import sys
 
218
 
 
219
        >>> from datetime import datetime, time
 
220
        >>> from tempfile import NamedTemporaryFile
 
221
        >>> from gtimelog import TimeWindow
 
222
 
 
223
        >>> vm = time(2, 0)
 
224
        >>> min = datetime(2007, 9, 1)
 
225
        >>> max = datetime(2007, 10, 1)
 
226
        >>> fh = NamedTemporaryFile()
 
227
 
 
228
        >>> window = TimeWindow(fh.name, min, max, vm)
 
229
        >>> window.monthly_report(sys.stdout, 'foo@bar.com', 'Bob Jones')
 
230
        To: foo@bar.com
 
231
        Subject: Monthly report for Bob Jones (2007/09)
 
232
        <BLANKLINE>
 
233
        No work done this month.
 
234
 
 
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',
 
241
        ...    '']]
 
242
        >>> fh.flush()
 
243
 
 
244
        >>> window = TimeWindow(fh.name, min, max, vm)
 
245
        >>> window.monthly_report(sys.stdout, 'foo@bar.com', 'Bob Jones')
 
246
        To: foo@bar.com
 
247
        Subject: Monthly report for Bob Jones (2007/09)
 
248
        <BLANKLINE>
 
249
        <BLANKLINE>
 
250
        Bing: stuff                                                     23 min
 
251
        Bong: other stuff                                               3 hours 31 min
 
252
        Misc                                                            2 hours 14 min
 
253
        <BLANKLINE>
 
254
        Total work done this month: 6 hours 8 min
 
255
        <BLANKLINE>
 
256
        By category:
 
257
        <BLANKLINE>
 
258
        Bing                                                            23 min
 
259
        Bong                                                            3 hours 31 min
 
260
        (none)                                                          2 hours 14 min
 
261
        <BLANKLINE>
 
262
 
 
263
    """
 
264
 
144
265
if __name__ == '__main__':
145
266
    import doctest
146
267
    fail, total = doctest.testmod()