MCPcopy Index your code
hub / github.com/python/cpython / test_pickling

Method test_pickling

Lib/test/datetimetester.py:5131–5152  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5129 self.assertRaises(ValueError, lambda: t1 == t2)
5130
5131 def test_pickling(self):
5132 # Try one without a tzinfo.
5133 args = 6, 7, 23, 20, 59, 1, 64**2
5134 orig = self.theclass(*args)
5135 for pickler, unpickler, proto in pickle_choices:
5136 green = pickler.dumps(orig, proto)
5137 derived = unpickler.loads(green)
5138 self.assertEqual(orig, derived)
5139 self.assertEqual(orig.__reduce__(), orig.__reduce_ex__(2))
5140
5141 # Try one with a tzinfo.
5142 tinfo = PicklableFixedOffset(-300, 'cookie')
5143 orig = self.theclass(*args, **{'tzinfo': tinfo})
5144 derived = self.theclass(1, 1, 1, tzinfo=FixedOffset(0, "", 0))
5145 for pickler, unpickler, proto in pickle_choices:
5146 green = pickler.dumps(orig, proto)
5147 derived = unpickler.loads(green)
5148 self.assertEqual(orig, derived)
5149 self.assertIsInstance(derived.tzinfo, PicklableFixedOffset)
5150 self.assertEqual(derived.utcoffset(), timedelta(minutes=-300))
5151 self.assertEqual(derived.tzname(), 'cookie')
5152 self.assertEqual(orig.__reduce__(), orig.__reduce_ex__(2))
5153
5154 def test_compat_unpickle(self):
5155 tests = [

Callers

nothing calls this directly

Calls 11

timedeltaClass · 0.90
FixedOffsetClass · 0.85
assertIsInstanceMethod · 0.80
dumpsMethod · 0.45
loadsMethod · 0.45
assertEqualMethod · 0.45
__reduce__Method · 0.45
__reduce_ex__Method · 0.45
utcoffsetMethod · 0.45
tznameMethod · 0.45

Tested by

no test coverage detected