(self)
| 4349 | flags=flags) |
| 4350 | |
| 4351 | def test_in_band_buffers(self): |
| 4352 | # Test in-band buffers (PEP 574) |
| 4353 | for obj in self.buffer_like_objects(): |
| 4354 | for proto in range(0, pickle.HIGHEST_PROTOCOL + 1): |
| 4355 | data = self.dumps(obj, proto) |
| 4356 | if obj.c_contiguous and proto >= 5: |
| 4357 | # The raw memory bytes are serialized in physical order |
| 4358 | self.assertIn(b"abcdefgh", data) |
| 4359 | self.assertEqual(count_opcode(pickle.NEXT_BUFFER, data), 0) |
| 4360 | if proto >= 5: |
| 4361 | self.assertEqual(count_opcode(pickle.SHORT_BINBYTES, data), |
| 4362 | 1 if obj.readonly else 0) |
| 4363 | self.assertEqual(count_opcode(pickle.BYTEARRAY8, data), |
| 4364 | 0 if obj.readonly else 1) |
| 4365 | # Return a true value from buffer_callback should have |
| 4366 | # the same effect |
| 4367 | def buffer_callback(obj): |
| 4368 | return True |
| 4369 | data2 = self.dumps(obj, proto, |
| 4370 | buffer_callback=buffer_callback) |
| 4371 | self.assertEqual(data2, data) |
| 4372 | |
| 4373 | new = self.loads(data) |
| 4374 | # It's a copy |
| 4375 | self.assertIsNot(new, obj) |
| 4376 | self.assertIs(type(new), type(obj)) |
| 4377 | self.assertEqual(new, obj) |
| 4378 | |
| 4379 | # XXX Unfortunately cannot test non-contiguous array |
| 4380 | # (see comment in PicklableNDArray.__reduce_ex__) |
nothing calls this directly
no test coverage detected