MCPcopy Create free account
hub / github.com/python/cpython / test_in_band_buffers

Method test_in_band_buffers

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

Source from the content-addressed store, hash-verified

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__)

Callers

nothing calls this directly

Calls 8

buffer_like_objectsMethod · 0.95
count_opcodeFunction · 0.85
assertInMethod · 0.80
assertIsNotMethod · 0.80
dumpsMethod · 0.45
assertEqualMethod · 0.45
loadsMethod · 0.45
assertIsMethod · 0.45

Tested by

no test coverage detected