(self)
| 3944 | flags=flags) |
| 3945 | |
| 3946 | def test_in_band_buffers(self): |
| 3947 | # Test in-band buffers (PEP 574) |
| 3948 | for obj in self.buffer_like_objects(): |
| 3949 | for proto in range(0, pickle.HIGHEST_PROTOCOL + 1): |
| 3950 | data = self.dumps(obj, proto) |
| 3951 | if obj.c_contiguous and proto >= 5: |
| 3952 | # The raw memory bytes are serialized in physical order |
| 3953 | self.assertIn(b"abcdefgh", data) |
| 3954 | self.assertEqual(count_opcode(pickle.NEXT_BUFFER, data), 0) |
| 3955 | if proto >= 5: |
| 3956 | self.assertEqual(count_opcode(pickle.SHORT_BINBYTES, data), |
| 3957 | 1 if obj.readonly else 0) |
| 3958 | self.assertEqual(count_opcode(pickle.BYTEARRAY8, data), |
| 3959 | 0 if obj.readonly else 1) |
| 3960 | # Return a true value from buffer_callback should have |
| 3961 | # the same effect |
| 3962 | def buffer_callback(obj): |
| 3963 | return True |
| 3964 | data2 = self.dumps(obj, proto, |
| 3965 | buffer_callback=buffer_callback) |
| 3966 | self.assertEqual(data2, data) |
| 3967 | |
| 3968 | new = self.loads(data) |
| 3969 | # It's a copy |
| 3970 | self.assertIsNot(new, obj) |
| 3971 | self.assertIs(type(new), type(obj)) |
| 3972 | self.assertEqual(new, obj) |
| 3973 | |
| 3974 | # XXX Unfortunately cannot test non-contiguous array |
| 3975 | # (see comment in PicklableNDArray.__reduce_ex__) |
nothing calls this directly
no test coverage detected