Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12123 -- Updated the utils.dateformat test to be a unittest to…

…o, due to a dependency on the old dateformat test.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11695 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e18af06eed4c6ad6266766810e4613e4d2700dbb 1 parent acfa933
Russell Keith-Magee authored November 01, 2009
78  tests/regressiontests/utils/dateformat.py
... ...
@@ -1,48 +1,42 @@
1  
-"""
2  
->>> from datetime import datetime, date
3  
->>> from django.utils.dateformat import format
4  
->>> from django.utils.tzinfo import FixedOffset, LocalTimezone
  1
+import os
  2
+from unittest import TestCase
  3
+from datetime import datetime, date
  4
+from django.utils.dateformat import format
  5
+from django.utils.tzinfo import FixedOffset, LocalTimezone
5 6
 
6  
-# date
7  
->>> d = date(2009, 5, 16)
8  
->>> date.fromtimestamp(int(format(d, 'U'))) == d
9  
-True
  7
+class DateFormatTests(TestCase):
  8
+    def setUp(self):
  9
+        self.old_TZ = os.environ['TZ']
  10
+        os.environ['TZ'] = 'Europe/Copenhagen'
10 11
 
11  
-# Naive datetime
12  
->>> dt = datetime(2009, 5, 16, 5, 30, 30)
13  
->>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt
14  
-True
  12
+    def tearDown(self):
  13
+        os.environ['TZ'] = self.old_TZ
15 14
 
16  
-# datetime with local tzinfo
17  
->>> ltz = LocalTimezone(datetime.now())
18  
->>> dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=ltz)
19  
->>> datetime.fromtimestamp(int(format(dt, 'U')), ltz) == dt
20  
-True
21  
->>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt.replace(tzinfo=None)
22  
-True
  15
+    def test_date(self):
  16
+        d = date(2009, 5, 16)
  17
+        self.assertEquals(date.fromtimestamp(int(format(d, 'U'))), d)
23 18
 
24  
-# datetime with arbitrary tzinfo
25  
->>> tz = FixedOffset(-510)
26  
->>> ltz = LocalTimezone(datetime.now())
27  
->>> dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=tz)
28  
->>> datetime.fromtimestamp(int(format(dt, 'U')), tz) == dt
29  
-True
30  
->>> datetime.fromtimestamp(int(format(dt, 'U')), ltz) == dt
31  
-True
32  
->>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt.astimezone(ltz).replace(tzinfo=None)
33  
-True
34  
->>> datetime.fromtimestamp(int(format(dt, 'U')), tz).utctimetuple() == dt.utctimetuple()
35  
-True
36  
->>> datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple() == dt.utctimetuple()
37  
-True
  19
+    def test_naive_datetime(self):
  20
+        dt = datetime(2009, 5, 16, 5, 30, 30)
  21
+        self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt)
38 22
 
39  
-# Epoch
40  
->>> utc = FixedOffset(0)
41  
->>> udt = datetime(1970, 1, 1, tzinfo=utc)
42  
->>> format(udt, 'U')
43  
-u'0'
44  
-"""
  23
+    def test_datetime_with_local_tzinfo(self):
  24
+        ltz = LocalTimezone(datetime.now())
  25
+        dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=ltz)
  26
+        self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz), dt)
  27
+        self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt.replace(tzinfo=None))
45 28
 
46  
-if __name__ == "__main__":
47  
-    import doctest
48  
-    doctest.testmod()
  29
+    def test_datetime_with_tzinfo(self):
  30
+        tz = FixedOffset(-510)
  31
+        ltz = LocalTimezone(datetime.now())
  32
+        dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=tz)
  33
+        self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), tz), dt)
  34
+        self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz), dt)
  35
+        self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt.astimezone(ltz).replace(tzinfo=None))
  36
+        self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), tz).utctimetuple(), dt.utctimetuple())
  37
+        self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple(), dt.utctimetuple())
  38
+
  39
+    def test_epoch(self):
  40
+        utc = FixedOffset(0)
  41
+        udt = datetime(1970, 1, 1, tzinfo=utc)
  42
+        self.assertEquals(format(udt, 'U'), u'0')
3  tests/regressiontests/utils/tests.py
@@ -24,10 +24,11 @@
24 24
 __test__ = {
25 25
     'timesince': timesince,
26 26
     'datastructures': datastructures,
27  
-    'dateformat': dateformat,
28 27
     'itercompat': itercompat,
29 28
 }
30 29
 
  30
+from dateformat import *
  31
+
31 32
 class TestUtilsHtml(TestCase):
32 33
 
33 34
     def check_output(self, function, value, output=None):

0 notes on commit e18af06

Please sign in to comment.
Something went wrong with that request. Please try again.