MCPcopy Create free account
hub / github.com/numpy/numpy / test_pickle_void

Method test_pickle_void

numpy/core/tests/test_records.py:413–436  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

411 assert_(pa.flags.aligned)
412
413 def test_pickle_void(self):
414 # issue gh-13593
415 dt = np.dtype([('obj', 'O'), ('int', 'i')])
416 a = np.empty(1, dtype=dt)
417 data = (bytearray(b'eman'),)
418 a['obj'] = data
419 a['int'] = 42
420 ctor, args = a[0].__reduce__()
421 # check the constructor is what we expect before interpreting the arguments
422 assert ctor is np.core.multiarray.scalar
423 dtype, obj = args
424 # make sure we did not pickle the address
425 assert not isinstance(obj, bytes)
426
427 assert_raises(RuntimeError, ctor, dtype, 13)
428
429 # Test roundtrip:
430 dump = pickle.dumps(a[0])
431 unpickled = pickle.loads(dump)
432 assert a[0] == unpickled
433
434 # Also check the similar (impossible) "object scalar" path:
435 with pytest.warns(DeprecationWarning):
436 assert ctor(np.dtype("O"), data) is data
437
438 def test_objview_record(self):
439 # https://github.com/numpy/numpy/issues/2599

Callers

nothing calls this directly

Calls 3

assert_raisesFunction · 0.90
dtypeMethod · 0.45
__reduce__Method · 0.45

Tested by

no test coverage detected