Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12127 -- Corrected teardown of dateformat tests. Thanks to apo…

…llo13 for the report, and Karen Tracey for the debugging help.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11705 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5dfed1b24a0a68aab25c10ca9e69072188baa3c9 1 parent be89c9a
Russell Keith-Magee authored November 02, 2009
20  tests/regressiontests/dateformat/tests.py
@@ -9,12 +9,24 @@ def setUp(self):
9 9
         os.environ['TZ'] = 'Europe/Copenhagen'
10 10
         translation.activate('en-us')
11 11
 
  12
+        try:
  13
+            # Check if a timezone has been set
  14
+            time.tzset()
  15
+            self.tz_tests = True
  16
+        except AttributeError:
  17
+            # No timezone available. Don't run the tests that require a TZ
  18
+            self.tz_tests = False
  19
+
12 20
     def tearDown(self):
13 21
         if self.old_TZ is None:
14 22
             del os.environ['TZ']
15 23
         else:
16 24
             os.environ['TZ'] = self.old_TZ
17 25
 
  26
+        # Cleanup - force re-evaluation of TZ environment variable.
  27
+        if self.tz_tests:
  28
+            time.tzset()
  29
+
18 30
     def test_empty_format(self):
19 31
         my_birthday = datetime.datetime(1979, 7, 8, 22, 00)
20 32
 
@@ -68,10 +80,7 @@ def test_timezones(self):
68 80
         summertime = datetime.datetime(2005, 10, 30, 1, 00)
69 81
         wintertime = datetime.datetime(2005, 10, 30, 4, 00)
70 82
 
71  
-        try:
72  
-            # Check if a timezone has been set
73  
-            time.tzset()
74  
-
  83
+        if self.tz_tests:
75 84
             self.assertEquals(dateformat.format(my_birthday, 'O'), u'+0100')
76 85
             self.assertEquals(dateformat.format(my_birthday, 'r'), u'Sun, 8 Jul 1979 22:00:00 +0100')
77 86
             self.assertEquals(dateformat.format(my_birthday, 'T'), u'CET')
@@ -81,6 +90,3 @@ def test_timezones(self):
81 90
             self.assertEquals(dateformat.format(summertime, 'O'), u'+0200')
82 91
             self.assertEquals(dateformat.format(wintertime, 'I'), u'0')
83 92
             self.assertEquals(dateformat.format(wintertime, 'O'), u'+0100')
84  
-        except AttributeError:
85  
-            # No timezone available. Don't run the tests
86  
-            pass
10  tests/regressiontests/utils/dateformat.py
@@ -5,16 +5,6 @@
5 5
 from django.utils.tzinfo import FixedOffset, LocalTimezone
6 6
 
7 7
 class DateFormatTests(TestCase):
8  
-    def setUp(self):
9  
-        self.old_TZ = os.environ.get('TZ')
10  
-        os.environ['TZ'] = 'Europe/Copenhagen'
11  
-
12  
-    def tearDown(self):
13  
-        if self.old_TZ is None:
14  
-            del os.environ['TZ']
15  
-        else:
16  
-            os.environ['TZ'] = self.old_TZ
17  
-
18 8
     def test_date(self):
19 9
         d = date(2009, 5, 16)
20 10
         self.assertEquals(date.fromtimestamp(int(format(d, 'U'))), d)

0 notes on commit 5dfed1b

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