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

Method test_array_like_fromfile

numpy/core/tests/test_overrides.py:656–679  ·  view source on GitHub ↗
(self, numpy_ref)

Source from the content-addressed store, hash-verified

654
655 @pytest.mark.parametrize('numpy_ref', [True, False])
656 def test_array_like_fromfile(self, numpy_ref):
657 self.add_method('array', self.MyArray)
658 self.add_method("fromfile", self.MyArray)
659
660 if numpy_ref is True:
661 ref = np.array(1)
662 else:
663 ref = self.MyArray.array()
664
665 data = np.random.random(5)
666
667 with tempfile.TemporaryDirectory() as tmpdir:
668 fname = os.path.join(tmpdir, "testfile")
669 data.tofile(fname)
670
671 array_like = np.fromfile(fname, like=ref)
672 if numpy_ref is True:
673 assert type(array_like) is np.ndarray
674 np_res = np.fromfile(fname, like=ref)
675 assert_equal(np_res, data)
676 assert_equal(array_like, np_res)
677 else:
678 assert type(array_like) is self.MyArray
679 assert array_like.function is self.MyArray.fromfile
680
681 def test_exception_handling(self):
682 self.add_method('array', self.MyArray, enable_value_error=True)

Callers

nothing calls this directly

Calls 5

add_methodMethod · 0.95
assert_equalFunction · 0.90
randomMethod · 0.80
tofileMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected