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

Method test_pickle

Lib/test/test_decimal.py:2624–2673  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2622 self.assertNotIsInstance(Decimal(0), numbers.Real)
2623
2624 def test_pickle(self):
2625 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2626 Decimal = self.decimal.Decimal
2627
2628 savedecimal = sys.modules['decimal']
2629
2630 # Round trip
2631 sys.modules['decimal'] = self.decimal
2632 d = Decimal('-3.141590000')
2633 p = pickle.dumps(d, proto)
2634 e = pickle.loads(p)
2635 self.assertEqual(d, e)
2636
2637 if C:
2638 # Test interchangeability
2639 x = C.Decimal('-3.123e81723')
2640 y = P.Decimal('-3.123e81723')
2641
2642 sys.modules['decimal'] = C
2643 sx = pickle.dumps(x, proto)
2644 sys.modules['decimal'] = P
2645 r = pickle.loads(sx)
2646 self.assertIsInstance(r, P.Decimal)
2647 self.assertEqual(r, y)
2648
2649 sys.modules['decimal'] = P
2650 sy = pickle.dumps(y, proto)
2651 sys.modules['decimal'] = C
2652 r = pickle.loads(sy)
2653 self.assertIsInstance(r, C.Decimal)
2654 self.assertEqual(r, x)
2655
2656 x = C.Decimal('-3.123e81723').as_tuple()
2657 y = P.Decimal('-3.123e81723').as_tuple()
2658
2659 sys.modules['decimal'] = C
2660 sx = pickle.dumps(x, proto)
2661 sys.modules['decimal'] = P
2662 r = pickle.loads(sx)
2663 self.assertIsInstance(r, P.DecimalTuple)
2664 self.assertEqual(r, y)
2665
2666 sys.modules['decimal'] = P
2667 sy = pickle.dumps(y, proto)
2668 sys.modules['decimal'] = C
2669 r = pickle.loads(sy)
2670 self.assertIsInstance(r, C.DecimalTuple)
2671 self.assertEqual(r, x)
2672
2673 sys.modules['decimal'] = savedecimal
2674
2675 def test_int(self):
2676 Decimal = self.decimal.Decimal

Callers

nothing calls this directly

Calls 6

DecimalClass · 0.85
assertIsInstanceMethod · 0.80
dumpsMethod · 0.45
loadsMethod · 0.45
assertEqualMethod · 0.45
as_tupleMethod · 0.45

Tested by

no test coverage detected