2011-11-18 13:01:06 +00:00
|
|
|
import copy
|
2012-04-29 13:37:23 +00:00
|
|
|
import datetime
|
2011-11-18 13:01:06 +00:00
|
|
|
import pickle
|
2012-04-29 13:37:23 +00:00
|
|
|
from django.test.utils import override_settings
|
|
|
|
from django.utils import timezone
|
2011-11-18 13:01:06 +00:00
|
|
|
from django.utils import unittest
|
|
|
|
|
2012-04-29 13:37:23 +00:00
|
|
|
|
2011-11-18 13:01:06 +00:00
|
|
|
class TimezoneTests(unittest.TestCase):
|
|
|
|
|
2012-04-29 13:37:23 +00:00
|
|
|
def test_localtime(self):
|
|
|
|
now = datetime.datetime.utcnow().replace(tzinfo=timezone.utc)
|
|
|
|
local_tz = timezone.LocalTimezone()
|
|
|
|
local_now = timezone.localtime(now, local_tz)
|
|
|
|
self.assertEqual(local_now.tzinfo, local_tz)
|
|
|
|
|
|
|
|
def test_now(self):
|
|
|
|
with override_settings(USE_TZ=True):
|
|
|
|
self.assertTrue(timezone.is_aware(timezone.now()))
|
|
|
|
with override_settings(USE_TZ=False):
|
|
|
|
self.assertTrue(timezone.is_naive(timezone.now()))
|
|
|
|
|
2011-11-18 13:01:06 +00:00
|
|
|
def test_copy(self):
|
2012-04-29 13:37:23 +00:00
|
|
|
self.assertIsInstance(copy.copy(timezone.UTC()), timezone.UTC)
|
|
|
|
self.assertIsInstance(copy.copy(timezone.LocalTimezone()), timezone.LocalTimezone)
|
2011-11-18 13:01:06 +00:00
|
|
|
|
|
|
|
def test_deepcopy(self):
|
2012-04-29 13:37:23 +00:00
|
|
|
self.assertIsInstance(copy.deepcopy(timezone.UTC()), timezone.UTC)
|
|
|
|
self.assertIsInstance(copy.deepcopy(timezone.LocalTimezone()), timezone.LocalTimezone)
|
2011-11-18 13:01:06 +00:00
|
|
|
|
|
|
|
def test_pickling_unpickling(self):
|
2012-04-29 13:37:23 +00:00
|
|
|
self.assertIsInstance(pickle.loads(pickle.dumps(timezone.UTC())), timezone.UTC)
|
|
|
|
self.assertIsInstance(pickle.loads(pickle.dumps(timezone.LocalTimezone())), timezone.LocalTimezone)
|