|
@@ -1,92 +0,0 @@
|
|
|
-import copy
|
|
|
-import datetime
|
|
|
-import os
|
|
|
-import pickle
|
|
|
-import time
|
|
|
-import unittest
|
|
|
-import warnings
|
|
|
-
|
|
|
-from django.test import ignore_warnings
|
|
|
-from django.utils.deprecation import RemovedInDjango19Warning
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-with warnings.catch_warnings():
|
|
|
- warnings.filterwarnings("ignore", category=RemovedInDjango19Warning)
|
|
|
- from django.utils.tzinfo import FixedOffset, LocalTimezone
|
|
|
-
|
|
|
-
|
|
|
-@ignore_warnings(category=RemovedInDjango19Warning)
|
|
|
-class TzinfoTests(unittest.TestCase):
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def setUpClass(cls):
|
|
|
- super(TzinfoTests, cls).setUpClass()
|
|
|
- cls.old_TZ = os.environ.get('TZ')
|
|
|
- os.environ['TZ'] = 'US/Eastern'
|
|
|
-
|
|
|
- try:
|
|
|
-
|
|
|
- time.tzset()
|
|
|
- cls.tz_tests = True
|
|
|
- except AttributeError:
|
|
|
-
|
|
|
- cls.tz_tests = False
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def tearDownClass(cls):
|
|
|
- if cls.old_TZ is None:
|
|
|
- del os.environ['TZ']
|
|
|
- else:
|
|
|
- os.environ['TZ'] = cls.old_TZ
|
|
|
-
|
|
|
-
|
|
|
- if cls.tz_tests:
|
|
|
- time.tzset()
|
|
|
- super(TzinfoTests, cls).tearDownClass()
|
|
|
-
|
|
|
- def test_fixedoffset(self):
|
|
|
- self.assertEqual(repr(FixedOffset(0)), '+0000')
|
|
|
- self.assertEqual(repr(FixedOffset(60)), '+0100')
|
|
|
- self.assertEqual(repr(FixedOffset(-60)), '-0100')
|
|
|
- self.assertEqual(repr(FixedOffset(280)), '+0440')
|
|
|
- self.assertEqual(repr(FixedOffset(-280)), '-0440')
|
|
|
- self.assertEqual(repr(FixedOffset(-78.4)), '-0118')
|
|
|
- self.assertEqual(repr(FixedOffset(78.4)), '+0118')
|
|
|
- self.assertEqual(repr(FixedOffset(-5.5 * 60)), '-0530')
|
|
|
- self.assertEqual(repr(FixedOffset(5.5 * 60)), '+0530')
|
|
|
- self.assertEqual(repr(FixedOffset(-.5 * 60)), '-0030')
|
|
|
- self.assertEqual(repr(FixedOffset(.5 * 60)), '+0030')
|
|
|
-
|
|
|
- def test_16899(self):
|
|
|
- if not self.tz_tests:
|
|
|
- return
|
|
|
- ts = 1289106000
|
|
|
-
|
|
|
- dt = datetime.datetime.utcfromtimestamp(ts)
|
|
|
-
|
|
|
- tz = LocalTimezone(dt + datetime.timedelta(days=1))
|
|
|
- self.assertEqual(
|
|
|
- repr(datetime.datetime.fromtimestamp(ts - 3600, tz)),
|
|
|
- 'datetime.datetime(2010, 11, 7, 0, 0, tzinfo=EST)')
|
|
|
- self.assertEqual(
|
|
|
- repr(datetime.datetime.fromtimestamp(ts, tz)),
|
|
|
- 'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')
|
|
|
- self.assertEqual(
|
|
|
- repr(datetime.datetime.fromtimestamp(ts + 3600, tz)),
|
|
|
- 'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')
|
|
|
-
|
|
|
- def test_copy(self):
|
|
|
- now = datetime.datetime.now()
|
|
|
- self.assertIsInstance(copy.copy(FixedOffset(90)), FixedOffset)
|
|
|
- self.assertIsInstance(copy.copy(LocalTimezone(now)), LocalTimezone)
|
|
|
-
|
|
|
- def test_deepcopy(self):
|
|
|
- now = datetime.datetime.now()
|
|
|
- self.assertIsInstance(copy.deepcopy(FixedOffset(90)), FixedOffset)
|
|
|
- self.assertIsInstance(copy.deepcopy(LocalTimezone(now)), LocalTimezone)
|
|
|
-
|
|
|
- def test_pickling_unpickling(self):
|
|
|
- now = datetime.datetime.now()
|
|
|
- self.assertIsInstance(pickle.loads(pickle.dumps(FixedOffset(90))), FixedOffset)
|
|
|
- self.assertIsInstance(pickle.loads(pickle.dumps(LocalTimezone(now))), LocalTimezone)
|