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

Function test_subclasses

numpy/lib/tests/test_stride_tricks.py:535–569  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

533
534
535def test_subclasses():
536 # test that subclass is preserved only if subok=True
537 a = VerySimpleSubClass([1, 2, 3, 4])
538 assert_(type(a) is VerySimpleSubClass)
539 a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,))
540 assert_(type(a_view) is np.ndarray)
541 a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,), subok=True)
542 assert_(type(a_view) is VerySimpleSubClass)
543 # test that if a subclass has __array_finalize__, it is used
544 a = SimpleSubClass([1, 2, 3, 4])
545 a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,), subok=True)
546 assert_(type(a_view) is SimpleSubClass)
547 assert_(a_view.info == 'simple finalized')
548
549 # similar tests for broadcast_arrays
550 b = np.arange(len(a)).reshape(-1, 1)
551 a_view, b_view = broadcast_arrays(a, b)
552 assert_(type(a_view) is np.ndarray)
553 assert_(type(b_view) is np.ndarray)
554 assert_(a_view.shape == b_view.shape)
555 a_view, b_view = broadcast_arrays(a, b, subok=True)
556 assert_(type(a_view) is SimpleSubClass)
557 assert_(a_view.info == 'simple finalized')
558 assert_(type(b_view) is np.ndarray)
559 assert_(a_view.shape == b_view.shape)
560
561 # and for broadcast_to
562 shape = (2, 4)
563 a_view = broadcast_to(a, shape)
564 assert_(type(a_view) is np.ndarray)
565 assert_(a_view.shape == shape)
566 a_view = broadcast_to(a, shape, subok=True)
567 assert_(type(a_view) is SimpleSubClass)
568 assert_(a_view.info == 'simple finalized')
569 assert_(a_view.shape == shape)
570
571
572def test_writeable():

Callers

nothing calls this directly

Calls 7

assert_Function · 0.90
as_stridedFunction · 0.90
broadcast_arraysFunction · 0.90
broadcast_toFunction · 0.90
VerySimpleSubClassClass · 0.85
SimpleSubClassClass · 0.85
reshapeMethod · 0.80

Tested by

no test coverage detected