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

Method test_bad_reduce_result

Lib/test/pickletester.py:1761–1790  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1759 # Subclass must define self.dumps, self.pickler.
1760
1761 def test_bad_reduce_result(self):
1762 obj = REX([print, ()])
1763 for proto in protocols:
1764 with self.subTest(proto=proto):
1765 with self.assertRaises(pickle.PicklingError) as cm:
1766 self.dumps(obj, proto)
1767 self.assertEqual(str(cm.exception),
1768 '__reduce__ must return a string or tuple, not list')
1769 self.assertEqual(cm.exception.__notes__, [
1770 f'when serializing {REX.__module__}.REX object'])
1771
1772 obj = REX((print,))
1773 for proto in protocols:
1774 with self.subTest(proto=proto):
1775 with self.assertRaises(pickle.PicklingError) as cm:
1776 self.dumps(obj, proto)
1777 self.assertEqual(str(cm.exception),
1778 'tuple returned by __reduce__ must contain 2 through 6 elements')
1779 self.assertEqual(cm.exception.__notes__, [
1780 f'when serializing {REX.__module__}.REX object'])
1781
1782 obj = REX((print, (), None, None, None, None, None))
1783 for proto in protocols:
1784 with self.subTest(proto=proto):
1785 with self.assertRaises(pickle.PicklingError) as cm:
1786 self.dumps(obj, proto)
1787 self.assertEqual(str(cm.exception),
1788 'tuple returned by __reduce__ must contain 2 through 6 elements')
1789 self.assertEqual(cm.exception.__notes__, [
1790 f'when serializing {REX.__module__}.REX object'])
1791
1792 def test_bad_reconstructor(self):
1793 obj = REX((42, ()))

Callers

nothing calls this directly

Calls 6

REXClass · 0.85
strFunction · 0.85
subTestMethod · 0.45
assertRaisesMethod · 0.45
dumpsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected