Skip to content

Commit 51eca24

Browse files
Issue python#9051: Added tests for pickling and copying the timezone objects.
2 parents d798dc1 + f242aeb commit 51eca24

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

Lib/test/datetimetester.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
44
"""
55

6+
import copy
67
import decimal
78
import sys
89
import pickle
@@ -235,7 +236,6 @@ def test_repr(self):
235236
tzrep = repr(tz)
236237
self.assertEqual(tz, eval(tzrep))
237238

238-
239239
def test_class_members(self):
240240
limit = timedelta(hours=23, minutes=59)
241241
self.assertEqual(timezone.utc.utcoffset(None), ZERO)
@@ -323,6 +323,33 @@ def test_aware_datetime(self):
323323
self.assertEqual(tz.dst(t),
324324
t.replace(tzinfo=tz).dst())
325325

326+
def test_pickle(self):
327+
for tz in self.ACDT, self.EST, timezone.min, timezone.max:
328+
for pickler, unpickler, proto in pickle_choices:
329+
tz_copy = unpickler.loads(pickler.dumps(tz, proto))
330+
self.assertEqual(tz_copy, tz)
331+
tz = timezone.utc
332+
for pickler, unpickler, proto in pickle_choices:
333+
tz_copy = unpickler.loads(pickler.dumps(tz, proto))
334+
self.assertIs(tz_copy, tz)
335+
336+
def test_copy(self):
337+
for tz in self.ACDT, self.EST, timezone.min, timezone.max:
338+
tz_copy = copy.copy(tz)
339+
self.assertEqual(tz_copy, tz)
340+
tz = timezone.utc
341+
tz_copy = copy.copy(tz)
342+
self.assertIs(tz_copy, tz)
343+
344+
def test_deepcopy(self):
345+
for tz in self.ACDT, self.EST, timezone.min, timezone.max:
346+
tz_copy = copy.deepcopy(tz)
347+
self.assertEqual(tz_copy, tz)
348+
tz = timezone.utc
349+
tz_copy = copy.deepcopy(tz)
350+
self.assertIs(tz_copy, tz)
351+
352+
326353
#############################################################################
327354
# Base class for testing a particular aspect of timedelta, time, date and
328355
# datetime comparisons.

0 commit comments

Comments
 (0)