]> granicus.if.org Git - python/commitdiff
Issue #9051: Added tests for pickling and copying the timezone objects.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 16 Nov 2015 09:12:58 +0000 (11:12 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 16 Nov 2015 09:12:58 +0000 (11:12 +0200)
Lib/test/datetimetester.py

index 3d50fc15d8b1378ef12735e32f37c3d16599bb14..289b0ca182007d6f45a506d2b0bb98eb97bedd52 100644 (file)
@@ -3,6 +3,7 @@
 See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
 """
 
+import copy
 import sys
 import pickle
 import random
@@ -223,7 +224,6 @@ class TestTimeZone(unittest.TestCase):
             tzrep = repr(tz)
             self.assertEqual(tz, eval(tzrep))
 
-
     def test_class_members(self):
         limit = timedelta(hours=23, minutes=59)
         self.assertEqual(timezone.utc.utcoffset(None), ZERO)
@@ -310,6 +310,33 @@ class TestTimeZone(unittest.TestCase):
             self.assertEqual(tz.dst(t),
                              t.replace(tzinfo=tz).dst())
 
+    def test_pickle(self):
+        for tz in self.ACDT, self.EST, timezone.min, timezone.max:
+            for pickler, unpickler, proto in pickle_choices:
+                tz_copy = unpickler.loads(pickler.dumps(tz, proto))
+                self.assertEqual(tz_copy, tz)
+        tz = timezone.utc
+        for pickler, unpickler, proto in pickle_choices:
+            tz_copy = unpickler.loads(pickler.dumps(tz, proto))
+            self.assertIs(tz_copy, tz)
+
+    def test_copy(self):
+        for tz in self.ACDT, self.EST, timezone.min, timezone.max:
+            tz_copy = copy.copy(tz)
+            self.assertEqual(tz_copy, tz)
+        tz = timezone.utc
+        tz_copy = copy.copy(tz)
+        self.assertIs(tz_copy, tz)
+
+    def test_deepcopy(self):
+        for tz in self.ACDT, self.EST, timezone.min, timezone.max:
+            tz_copy = copy.deepcopy(tz)
+            self.assertEqual(tz_copy, tz)
+        tz = timezone.utc
+        tz_copy = copy.deepcopy(tz)
+        self.assertIs(tz_copy, tz)
+
+
 #############################################################################
 # Base class for testing a particular aspect of timedelta, time, date and
 # datetime comparisons.