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

Method test_fromfile_tofile_seeks

numpy/core/tests/test_regression.py:1600–1625  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1598 assert_equal(c1, c2)
1599
1600 def test_fromfile_tofile_seeks(self):
1601 # On Python 3, tofile/fromfile used to get (#1610) the Python
1602 # file handle out of sync
1603 f0 = tempfile.NamedTemporaryFile()
1604 f = f0.file
1605 f.write(np.arange(255, dtype='u1').tobytes())
1606
1607 f.seek(20)
1608 ret = np.fromfile(f, count=4, dtype='u1')
1609 assert_equal(ret, np.array([20, 21, 22, 23], dtype='u1'))
1610 assert_equal(f.tell(), 24)
1611
1612 f.seek(40)
1613 np.array([1, 2, 3], dtype='u1').tofile(f)
1614 assert_equal(f.tell(), 43)
1615
1616 f.seek(40)
1617 data = f.read(3)
1618 assert_equal(data, b"\x01\x02\x03")
1619
1620 f.seek(80)
1621 f.read(4)
1622 data = np.fromfile(f, dtype='u1', count=4)
1623 assert_equal(data, np.array([84, 85, 86, 87], dtype='u1'))
1624
1625 f.close()
1626
1627 def test_complex_scalar_warning(self):
1628 for tp in [np.csingle, np.cdouble, np.clongdouble]:

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected