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

Method test_py_methods

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

Source from the content-addressed store, hash-verified

4104 del Recursive.ref # break reference loop
4105
4106 def test_py_methods(self):
4107 if self.py_version < (3, 4):
4108 self.skipTest('not supported in Python < 3.4')
4109 py_methods = (
4110 PyMethodsTest.wine,
4111 PyMethodsTest().biscuits,
4112 )
4113 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
4114 for method in py_methods:
4115 with self.subTest(proto=proto, method=method):
4116 unpickled = self.loads(self.dumps(method, proto))
4117 self.assertEqual(method(), unpickled())
4118
4119 # required protocol 4 in Python 3.4
4120 py_methods = (
4121 PyMethodsTest.cheese,
4122 PyMethodsTest.Nested.ketchup,
4123 PyMethodsTest.Nested.maple,
4124 PyMethodsTest.Nested().pie
4125 )
4126 py_unbound_methods = (
4127 (PyMethodsTest.biscuits, PyMethodsTest),
4128 (PyMethodsTest.Nested.pie, PyMethodsTest.Nested)
4129 )
4130 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
4131 if self.py_version < (3, 5) and proto < 4:
4132 continue
4133 for method in py_methods:
4134 with self.subTest(proto=proto, method=method):
4135 unpickled = self.loads(self.dumps(method, proto))
4136 self.assertEqual(method(), unpickled())
4137 for method, cls in py_unbound_methods:
4138 obj = cls()
4139 with self.subTest(proto=proto, method=method):
4140 unpickled = self.loads(self.dumps(method, proto))
4141 self.assertEqual(method(obj), unpickled(obj))
4142
4143 descriptors = (
4144 PyMethodsTest.__dict__['cheese'], # static method descriptor
4145 PyMethodsTest.__dict__['wine'], # class method descriptor
4146 )
4147 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
4148 for descr in descriptors:
4149 with self.subTest(proto=proto, descr=descr):
4150 self.assertRaises(TypeError, self.dumps, descr, proto)
4151
4152 def test_c_methods(self):
4153 if self.py_version < (3, 4):

Callers

nothing calls this directly

Calls 9

PyMethodsTestClass · 0.85
methodFunction · 0.85
skipTestMethod · 0.80
clsClass · 0.50
subTestMethod · 0.45
loadsMethod · 0.45
dumpsMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected