MCPcopy Index your code
hub / github.com/numpy/numpy / test_fromfile_tofile_seeks

Method test_fromfile_tofile_seeks

numpy/_core/tests/test_regression.py:1587–1608  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1585 assert_equal(c1, c2)
1586
1587 def test_fromfile_tofile_seeks(self):
1588 # tofile/fromfile used to get (#1610) the Python file handle out of sync
1589 with tempfile.NamedTemporaryFile() as f:
1590 f.write(np.arange(255, dtype='u1').tobytes())
1591
1592 f.seek(20)
1593 ret = np.fromfile(f, count=4, dtype='u1')
1594 assert_equal(ret, np.array([20, 21, 22, 23], dtype='u1'))
1595 assert_equal(f.tell(), 24)
1596
1597 f.seek(40)
1598 np.array([1, 2, 3], dtype='u1').tofile(f)
1599 assert_equal(f.tell(), 43)
1600
1601 f.seek(40)
1602 data = f.read(3)
1603 assert_equal(data, b"\x01\x02\x03")
1604
1605 f.seek(80)
1606 f.read(4)
1607 data = np.fromfile(f, dtype='u1', count=4)
1608 assert_equal(data, np.array([84, 85, 86, 87], dtype='u1'))
1609
1610 def test_complex_scalar_warning(self):
1611 for tp in [np.csingle, np.cdouble, np.clongdouble]:

Callers

nothing calls this directly

Calls 6

assert_equalFunction · 0.90
seekMethod · 0.80
tofileMethod · 0.80
writeMethod · 0.45
tobytesMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected