PageRenderTime 156ms CodeModel.GetById 151ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/utils/datetime_safe.py

https://code.google.com/p/mango-py/
Python | 42 lines | 26 code | 10 blank | 6 comment | 0 complexity | 1dd4363960562c49fd7b9984c7b6bb99 MD5 | raw file
 1import unittest
 2
 3from datetime import date as original_date, datetime as original_datetime
 4from django.utils.datetime_safe import date, datetime
 5
 6class DatetimeTests(unittest.TestCase):
 7
 8    def setUp(self):
 9        self.just_safe = (1900, 1, 1)
10        self.just_unsafe = (1899, 12, 31, 23, 59, 59)
11        self.really_old = (20, 1, 1)
12        self.more_recent = (2006, 1, 1)
13
14    def test_compare_datetimes(self):
15        self.assertEqual(original_datetime(*self.more_recent), datetime(*self.more_recent))
16        self.assertEqual(original_datetime(*self.really_old), datetime(*self.really_old))
17        self.assertEqual(original_date(*self.more_recent), date(*self.more_recent))
18        self.assertEqual(original_date(*self.really_old), date(*self.really_old))
19
20        self.assertEqual(original_date(*self.just_safe).strftime('%Y-%m-%d'), date(*self.just_safe).strftime('%Y-%m-%d'))
21        self.assertEqual(original_datetime(*self.just_safe).strftime('%Y-%m-%d'), datetime(*self.just_safe).strftime('%Y-%m-%d'))
22
23    def test_safe_strftime(self):
24        self.assertEqual(date(*self.just_unsafe[:3]).strftime('%Y-%m-%d (weekday %w)'), '1899-12-31 (weekday 0)')
25        self.assertEqual(date(*self.just_safe).strftime('%Y-%m-%d (weekday %w)'), '1900-01-01 (weekday 1)')
26
27        self.assertEqual(datetime(*self.just_unsafe).strftime('%Y-%m-%d %H:%M:%S (weekday %w)'), '1899-12-31 23:59:59 (weekday 0)')
28        self.assertEqual(datetime(*self.just_safe).strftime('%Y-%m-%d %H:%M:%S (weekday %w)'), '1900-01-01 00:00:00 (weekday 1)')
29
30        # %y will error before this date
31        self.assertEqual(date(*self.just_safe).strftime('%y'), '00')
32        self.assertEqual(datetime(*self.just_safe).strftime('%y'), '00')
33
34        self.assertEqual(date(1850, 8, 2).strftime("%Y/%m/%d was a %A"), '1850/08/02 was a Friday')
35
36    def test_zero_padding(self):
37        """
38        Regression for #12524
39
40        Check that pre-1000AD dates are padded with zeros if necessary
41        """
42        self.assertEqual(date(1, 1, 1).strftime("%Y/%m/%d was a %A"), '0001/01/01 was a Monday')