summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-11-02 08:26:03 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-11-02 08:26:03 +0000
commit5dfed1b24a0a68aab25c10ca9e69072188baa3c9 (patch)
treedeb77ef5901dd9ea8415054348487520a7ff6226 /tests/regressiontests
parentbe89c9ababd85ec25606b39b408a2ab7ee6da357 (diff)
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
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/dateformat/tests.py20
-rw-r--r--tests/regressiontests/utils/dateformat.py10
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)