From 5dfed1b24a0a68aab25c10ca9e69072188baa3c9 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 2 Nov 2009 08:26:03 +0000 Subject: [PATCH] Fixed #12127 -- Corrected teardown of dateformat tests. Thanks to apollo13 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 --- tests/regressiontests/dateformat/tests.py | 20 +++++++++++++------- tests/regressiontests/utils/dateformat.py | 10 ---------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/regressiontests/dateformat/tests.py b/tests/regressiontests/dateformat/tests.py index 3a19d26e19..bbde45b903 100644 --- a/tests/regressiontests/dateformat/tests.py +++ b/tests/regressiontests/dateformat/tests.py @@ -9,12 +9,24 @@ class DateFormatTests(TestCase): 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 @@ class DateFormatTests(TestCase): 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 @@ class DateFormatTests(TestCase): 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 diff --git a/tests/regressiontests/utils/dateformat.py b/tests/regressiontests/utils/dateformat.py index 2ff3441486..b80010f8d8 100644 --- a/tests/regressiontests/utils/dateformat.py +++ b/tests/regressiontests/utils/dateformat.py @@ -5,16 +5,6 @@ from django.utils.dateformat import format 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)