(self)
| 4150 | self.assertRaises(TypeError, self.dumps, descr, proto) |
| 4151 | |
| 4152 | def test_c_methods(self): |
| 4153 | if self.py_version < (3, 4): |
| 4154 | self.skipTest('not supported in Python < 3.4') |
| 4155 | c_methods = ( |
| 4156 | # bound built-in method |
| 4157 | ("abcd".index, ("c",)), |
| 4158 | # unbound built-in method |
| 4159 | (str.index, ("abcd", "c")), |
| 4160 | # bound "slot" method |
| 4161 | ([1, 2, 3].__len__, ()), |
| 4162 | # unbound "slot" method |
| 4163 | (list.__len__, ([1, 2, 3],)), |
| 4164 | # bound "coexist" method |
| 4165 | ({1, 2}.__contains__, (2,)), |
| 4166 | # unbound "coexist" method |
| 4167 | (set.__contains__, ({1, 2}, 2)), |
| 4168 | # built-in class method |
| 4169 | (dict.fromkeys, (("a", 1), ("b", 2))), |
| 4170 | # built-in static method |
| 4171 | (bytearray.maketrans, (b"abc", b"xyz")), |
| 4172 | # subclass methods |
| 4173 | (Subclass([1,2,2]).count, (2,)), |
| 4174 | (Subclass.count, (Subclass([1,2,2]), 2)), |
| 4175 | (Subclass.Nested.count, (Subclass.Nested("sweet"), "e")), |
| 4176 | ) |
| 4177 | for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
| 4178 | for method, args in c_methods: |
| 4179 | with self.subTest(proto=proto, method=method): |
| 4180 | unpickled = self.loads(self.dumps(method, proto)) |
| 4181 | self.assertEqual(method(*args), unpickled(*args)) |
| 4182 | |
| 4183 | # required protocol 4 in Python 3.4 |
| 4184 | c_methods = ( |
| 4185 | (Subclass.Nested("sweet").count, ("e",)), |
| 4186 | ) |
| 4187 | for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
| 4188 | if self.py_version < (3, 5) and proto < 4: |
| 4189 | continue |
| 4190 | for method, args in c_methods: |
| 4191 | with self.subTest(proto=proto, method=method): |
| 4192 | unpickled = self.loads(self.dumps(method, proto)) |
| 4193 | self.assertEqual(method(*args), unpickled(*args)) |
| 4194 | |
| 4195 | descriptors = ( |
| 4196 | bytearray.__dict__['maketrans'], # built-in static method descriptor |
| 4197 | dict.__dict__['fromkeys'], # built-in class method descriptor |
| 4198 | ) |
| 4199 | for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
| 4200 | for descr in descriptors: |
| 4201 | with self.subTest(proto=proto, descr=descr): |
| 4202 | self.assertRaises(TypeError, self.dumps, descr, proto) |
| 4203 | |
| 4204 | def test_private_methods(self): |
| 4205 | if self.py_version < (3, 15): |
nothing calls this directly
no test coverage detected