Skip to content

Commit f242aeb

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

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)
@@ -322,6 +322,33 @@ def test_aware_datetime(self):
322322
self.assertEqual(tz.dst(t),
323323
t.replace(tzinfo=tz).dst())
324324

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

0 commit comments

Comments
 (0)