Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@freakboy3742 freakboy3742 authored
View
20 tests/regressiontests/dateformat/tests.py
@@ -9,12 +9,24 @@ def setUp(self):
os.environ['TZ'] = 'Europe/Copenhagen'
translation.activate('en-us')
+ try:
+ # Check if a timezone has been set
+ time.tzset()
+ self.tz_tests = True
+ except AttributeError:
+ # No timezone available. Don't run the tests that require a TZ
+ self.tz_tests = False
+
def tearDown(self):
if self.old_TZ is None:
del os.environ['TZ']
else:
os.environ['TZ'] = self.old_TZ
+ # Cleanup - force re-evaluation of TZ environment variable.
+ if self.tz_tests:
+ time.tzset()
+
def test_empty_format(self):
my_birthday = datetime.datetime(1979, 7, 8, 22, 00)
@@ -68,10 +80,7 @@ def test_timezones(self):
summertime = datetime.datetime(2005, 10, 30, 1, 00)
wintertime = datetime.datetime(2005, 10, 30, 4, 00)
- try:
- # Check if a timezone has been set
- time.tzset()
-
+ if self.tz_tests:
self.assertEquals(dateformat.format(my_birthday, 'O'), u'+0100')
self.assertEquals(dateformat.format(my_birthday, 'r'), u'Sun, 8 Jul 1979 22:00:00 +0100')
self.assertEquals(dateformat.format(my_birthday, 'T'), u'CET')
@@ -81,6 +90,3 @@ def test_timezones(self):
self.assertEquals(dateformat.format(summertime, 'O'), u'+0200')
self.assertEquals(dateformat.format(wintertime, 'I'), u'0')
self.assertEquals(dateformat.format(wintertime, 'O'), u'+0100')
- except AttributeError:
- # No timezone available. Don't run the tests
- pass
View
10 tests/regressiontests/utils/dateformat.py
@@ -5,16 +5,6 @@
from django.utils.tzinfo import FixedOffset, LocalTimezone
class DateFormatTests(TestCase):
- def setUp(self):
- self.old_TZ = os.environ.get('TZ')
- os.environ['TZ'] = 'Europe/Copenhagen'
-
- def tearDown(self):
- if self.old_TZ is None:
- del os.environ['TZ']
- else:
- os.environ['TZ'] = self.old_TZ
-
def test_date(self):
d = date(2009, 5, 16)
self.assertEquals(date.fromtimestamp(int(format(d, 'U'))), d)
Please sign in to comment.
Something went wrong with that request. Please try again.