Mercurial > p > roundup > code
comparison test/test_dates.py @ 3953:78dc9b275aeb
New tests for range searching by specifying just a month.
Currently some of them fail.
_add_granularity is broken - needs tests and complete fix.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 21 Dec 2007 11:21:09 +0000 |
| parents | c68581212cf7 |
| children | 3d5a0a949107 |
comparison
equal
deleted
inserted
replaced
| 3952:c68581212cf7 | 3953:78dc9b275aeb |
|---|---|
| 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.42 2007-12-20 01:01:49 richard Exp $ | 18 # $Id: test_dates.py,v 1.43 2007-12-21 11:21:09 richard Exp $ |
| 19 from __future__ import nested_scopes | 19 from __future__ import nested_scopes |
| 20 | 20 |
| 21 import unittest | 21 import unittest |
| 22 import time | 22 import time |
| 23 import datetime | 23 import datetime |
| 24 | 24 import calendar |
| 25 from roundup.date import Date, Interval, Range, fixTimeOverflow, get_timezone | 25 |
| 26 from roundup.date import Date, Interval, Range, fixTimeOverflow, \ | |
| 27 get_timezone, _add_granularity | |
| 28 | |
| 26 | 29 |
| 27 class DateTestCase(unittest.TestCase): | 30 class DateTestCase(unittest.TestCase): |
| 31 def testAddGranularity(self): | |
| 32 def d(m=None, d=None, H=None, M=None, S=None, value=1): | |
| 33 d = dict(y='2006', m=m, d=d, H=H, M=M, S=S) | |
| 34 _add_granularity(d, 'SMHdmy', value) | |
| 35 return d | |
| 36 ae = self.assertEqual | |
| 37 ae(d(), dict(y=2007, m=None, d=None, H=None, M=None, S=None)) | |
| 38 ae(d(m='1'), dict(y='2006', m=2, d=None, H=None, M=None, S=None)) | |
| 39 ae(d(m='12'), dict(y=2007, m=1, d=None, H=None, M=None, S=None)) | |
| 40 | |
| 28 def testDateInterval(self): | 41 def testDateInterval(self): |
| 29 ae = self.assertEqual | 42 ae = self.assertEqual |
| 30 date = Date("2000-06-26.00:34:02 + 2d") | 43 date = Date("2000-06-26.00:34:02 + 2d") |
| 31 ae(str(date), '2000-06-28.00:34:02') | 44 ae(str(date), '2000-06-28.00:34:02') |
| 32 date = Date("2000-02-27 + 2d") | 45 date = Date("2000-02-27 + 2d") |
| 470 def testRange(self): | 483 def testRange(self): |
| 471 ae = self.assertEqual | 484 ae = self.assertEqual |
| 472 r = Range('2006', Date) | 485 r = Range('2006', Date) |
| 473 ae(str(r.from_value), '2006-01-01.00:00:00') | 486 ae(str(r.from_value), '2006-01-01.00:00:00') |
| 474 ae(str(r.to_value), '2006-12-31.23:59:59') | 487 ae(str(r.to_value), '2006-12-31.23:59:59') |
| 475 # XXX this is probably in the calendar module | |
| 476 days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) | |
| 477 for i in range(1, 13): | 488 for i in range(1, 13): |
| 478 print i | |
| 479 r = Range('2006-%02d'%i, Date) | 489 r = Range('2006-%02d'%i, Date) |
| 480 ae(str(r.from_value), '2006-%02d-01.00:00:00'%i) | 490 ae(str(r.from_value), '2006-%02d-01.00:00:00'%i) |
| 481 ae(str(r.to_value), '2006-%02d-%02d.23:59:59'%(i, days[i-1])) | 491 ae(str(r.to_value), '2006-%02d-%02d.23:59:59'%(i, |
| 492 calendar.mdays[i])) | |
| 482 | 493 |
| 483 | 494 |
| 484 def test_suite(): | 495 def test_suite(): |
| 485 suite = unittest.TestSuite() | 496 suite = unittest.TestSuite() |
| 486 suite.addTest(unittest.makeSuite(DateTestCase)) | 497 suite.addTest(unittest.makeSuite(DateTestCase)) |
