Skip to content

Commit e28209f

Browse files
Issue python#9051: Added tests for pickling and copying the timezone objects.
1 parent a0c9caa commit e28209f

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 sys
78
import pickle
89
import random
@@ -223,7 +224,6 @@ def test_repr(self):
223224
tzrep = repr(tz)
224225
self.assertEqual(tz, eval(tzrep))
225226

226-
227227
def test_class_members(self):
228228
limit = timedelta(hours=23, minutes=59)
229229
self.assertEqual(timezone.utc.utcoffset(None), ZERO)
@@ -310,6 +310,33 @@ def test_aware_datetime(self):
310310
self.assertEqual(tz.dst(t),
311311
t.replace(tzinfo=tz).dst())
312312

313+
def test_pickle(self):
314+
for tz in self.ACDT, self.EST, timezone.min, timezone.max:
315+
for pickler, unpickler, proto in pickle_choices:
316+
tz_copy = unpickler.loads(pickler.dumps(tz, proto))
317+
self.assertEqual(tz_copy, tz)
318+
tz = timezone.utc
319+
for pickler, unpickler, proto in pickle_choices:
320+
tz_copy = unpickler.loads(pickler.dumps(tz, proto))
321+
self.assertIs(tz_copy, tz)
322+
323+
def test_copy(self):
324+
for tz in self.ACDT, self.EST, timezone.min, timezone.max:
325+
tz_copy = copy.copy(tz)
326+
self.assertEqual(tz_copy, tz)
327+
tz = timezone.utc
328+
tz_copy = copy.copy(tz)
329+
self.assertIs(tz_copy, tz)
330+
331+
def test_deepcopy(self):
332+
for tz in self.ACDT, self.EST, timezone.min, timezone.max:
333+
tz_copy = copy.deepcopy(tz)
334+
self.assertEqual(tz_copy, tz)
335+
tz = timezone.utc
336+
tz_copy = copy.deepcopy(tz)
337+
self.assertIs(tz_copy, tz)
338+
339+
313340
#############################################################################
314341
# Base class for testing a particular aspect of timedelta, time, date and
315342
# datetime comparisons.

0 commit comments

Comments
 (0)