Mercurial > p > roundup > code
comparison test/test_dates.py @ 3824:a5fb7698439d
remove some try:/import statements caught by alexander smishlajev
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Mon, 12 Mar 2007 17:53:38 +0000 |
| parents | 2a60b68985db |
| children | c68581212cf7 |
comparison
equal
deleted
inserted
replaced
| 3823:7cda5b4daa91 | 3824:a5fb7698439d |
|---|---|
| 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.40 2007-03-09 10:25:10 schlatterbeck Exp $ | 18 # $Id: test_dates.py,v 1.41 2007-03-12 17:53:38 schlatterbeck Exp $ |
| 19 from __future__ import nested_scopes | 19 from __future__ import nested_scopes |
| 20 | 20 |
| 21 import unittest, time | 21 import unittest |
| 22 import time | |
| 23 import datetime | |
| 22 | 24 |
| 23 from roundup.date import Date, Interval, Range, fixTimeOverflow, get_timezone | 25 from roundup.date import Date, Interval, Range, fixTimeOverflow, get_timezone |
| 24 | 26 |
| 25 class DateTestCase(unittest.TestCase): | 27 class DateTestCase(unittest.TestCase): |
| 26 def testDateInterval(self): | 28 def testDateInterval(self): |
| 391 ae('-1d', 'yesterday') | 393 ae('-1d', 'yesterday') |
| 392 ae('-1y', '1 year ago') | 394 ae('-1y', '1 year ago') |
| 393 ae('-2y', '2 years ago') | 395 ae('-2y', '2 years ago') |
| 394 | 396 |
| 395 def testPyDatetime(self): | 397 def testPyDatetime(self): |
| 396 try: | |
| 397 import datetime | |
| 398 except: | |
| 399 return | |
| 400 d = datetime.datetime.now() | 398 d = datetime.datetime.now() |
| 401 Date(d) | 399 Date(d) |
| 402 toomuch = datetime.MAXYEAR + 1 | 400 toomuch = datetime.MAXYEAR + 1 |
| 403 self.assertRaises(ValueError, Date, (toomuch, 1, 1, 0, 0, 0, 0, 1, -1)) | 401 self.assertRaises(ValueError, Date, (toomuch, 1, 1, 0, 0, 0, 0, 1, -1)) |
| 404 | 402 |
| 420 ae = self.assertEqual | 418 ae = self.assertEqual |
| 421 date = Date('2038') | 419 date = Date('2038') |
| 422 ae(date.timestamp(), 2145916800) | 420 ae(date.timestamp(), 2145916800) |
| 423 date = Date('1902') | 421 date = Date('1902') |
| 424 ae(date.timestamp(), -2145916800) | 422 ae(date.timestamp(), -2145916800) |
| 425 try: | 423 date = Date(time.gmtime(0)) |
| 426 from time import gmtime | |
| 427 except: | |
| 428 return | |
| 429 date = Date(gmtime(0)) | |
| 430 ae(date.timestamp(), 0) | 424 ae(date.timestamp(), 0) |
| 431 ae(str(date), '1970-01-01.00:00:00') | 425 ae(str(date), '1970-01-01.00:00:00') |
| 432 date = Date(gmtime(0x7FFFFFFF)) | 426 date = Date(time.gmtime(0x7FFFFFFF)) |
| 433 ae(date.timestamp(), 2147483647) | 427 ae(date.timestamp(), 2147483647) |
| 434 ae(str(date), '2038-01-19.03:14:07') | 428 ae(str(date), '2038-01-19.03:14:07') |
| 435 date = Date('1901-12-13.20:45:52') | 429 date = Date('1901-12-13.20:45:52') |
| 436 ae(date.timestamp(), -0x80000000L) | 430 ae(date.timestamp(), -0x80000000L) |
| 437 ae(str(date), '1901-12-13.20:45:52') | 431 ae(str(date), '1901-12-13.20:45:52') |
