(self)
| 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): |
nothing calls this directly
no test coverage detected