Mercurial > p > roundup > code
comparison test/test_dates.py @ 1930:71056b09f2bf
Add tests for Interval.pretty().
Fix 'ago' and 'in' not being added to years.
Fix docstrings for emacs.
| author | Johannes Gijsbers <jlgijsbers@users.sourceforge.net> |
|---|---|
| date | Wed, 19 Nov 2003 22:53:15 +0000 |
| parents | 41ad8b781232 |
| children | bcc65c5b86e6 |
comparison
equal
deleted
inserted
replaced
| 1929:b7912efc7f57 | 1930:71056b09f2bf |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: test_dates.py,v 1.29 2003-11-04 12:35:47 anthonybaxter Exp $ | 18 # $Id: test_dates.py,v 1.30 2003-11-19 22:53:14 jlgijsbers Exp $ |
| 19 from __future__ import nested_scopes | |
| 19 | 20 |
| 20 import unittest, time | 21 import unittest, time |
| 21 | 22 |
| 22 from roundup.date import Date, Interval, Range, fixTimeOverflow | 23 from roundup.date import Date, Interval, Range, fixTimeOverflow |
| 23 | 24 |
| 333 ae(str(Date('2003-1-1.23:00', add_granularity=1)), '2003-01-01.23:00:59') | 334 ae(str(Date('2003-1-1.23:00', add_granularity=1)), '2003-01-01.23:00:59') |
| 334 ae(str(Date('2003', add_granularity=1)), '2003-12-31.23:59:59') | 335 ae(str(Date('2003', add_granularity=1)), '2003-12-31.23:59:59') |
| 335 ae(str(Date('2003-5', add_granularity=1)), '2003-05-31.23:59:59') | 336 ae(str(Date('2003-5', add_granularity=1)), '2003-05-31.23:59:59') |
| 336 ae(str(Interval('+1w', add_granularity=1)), '+ 14d') | 337 ae(str(Interval('+1w', add_granularity=1)), '+ 14d') |
| 337 ae(str(Interval('-2m 3w', add_granularity=1)), '- 2m 14d') | 338 ae(str(Interval('-2m 3w', add_granularity=1)), '- 2m 14d') |
| 339 | |
| 340 def testIntervalPretty(self): | |
| 341 def ae(spec, pretty): | |
| 342 self.assertEqual(Interval(spec).pretty(), pretty) | |
| 343 ae('2y', 'in 2 years') | |
| 344 ae('1y', 'in 1 year') | |
| 345 ae('2m', 'in 2 months') | |
| 346 ae('1m 30d', 'in 2 months') | |
| 347 ae('60d', 'in 2 months') | |
| 348 ae('59d', 'in 1 month') | |
| 349 ae('1m', 'in 1 month') | |
| 350 ae('29d', 'in 1 month') | |
| 351 ae('28d', 'in 4 weeks') | |
| 352 ae('8d', 'in 1 week') | |
| 353 ae('7d', 'in 7 days') | |
| 354 ae('1w', 'in 7 days') | |
| 355 ae('2d', 'in 2 days') | |
| 356 ae('1d', 'tomorrow') | |
| 357 ae('02:00:00', 'in 2 hours') | |
| 358 ae('01:59:00', 'in 1 3/4 hours') | |
| 359 ae('01:45:00', 'in 1 3/4 hours') | |
| 360 ae('01:30:00', 'in 1 1/2 hours') | |
| 361 ae('01:29:00', 'in 1 1/4 hours') | |
| 362 ae('01:00:00', 'in an hour') | |
| 363 ae('00:30:00', 'in 1/2 an hour') | |
| 364 ae('00:15:00', 'in 1/4 hour') | |
| 365 ae('00:02:00', 'in 2 minutes') | |
| 366 ae('00:01:00', 'in 1 minute') | |
| 367 ae('00:00:30', 'in a moment') | |
| 368 ae('-00:00:30', 'just now') | |
| 369 ae('-1d', 'yesterday') | |
| 370 ae('-1y', '1 year ago') | |
| 371 ae('-2y', '2 years ago') | |
| 338 | 372 |
| 339 def test_suite(): | 373 def test_suite(): |
| 340 suite = unittest.TestSuite() | 374 suite = unittest.TestSuite() |
| 341 suite.addTest(unittest.makeSuite(DateTestCase)) | 375 suite.addTest(unittest.makeSuite(DateTestCase)) |
| 342 return suite | 376 return suite |
