(self, tmp_path, param_filename)
| 6313 | np.fromfile, tmp_filename, dtype=object) |
| 6314 | |
| 6315 | def test_fromfile_offset(self, tmp_path, param_filename): |
| 6316 | tmp_filename = normalize_filename(tmp_path, param_filename) |
| 6317 | x = self._create_data() |
| 6318 | with open(tmp_filename, 'wb') as f: |
| 6319 | x.tofile(f) |
| 6320 | |
| 6321 | with open(tmp_filename, 'rb') as f: |
| 6322 | y = np.fromfile(f, dtype=x.dtype, offset=0) |
| 6323 | assert_array_equal(y, x.flat) |
| 6324 | |
| 6325 | with open(tmp_filename, 'rb') as f: |
| 6326 | count_items = len(x.flat) // 8 |
| 6327 | offset_items = len(x.flat) // 4 |
| 6328 | offset_bytes = x.dtype.itemsize * offset_items |
| 6329 | y = np.fromfile( |
| 6330 | f, dtype=x.dtype, count=count_items, offset=offset_bytes |
| 6331 | ) |
| 6332 | assert_array_equal( |
| 6333 | y, x.flat[offset_items:offset_items + count_items] |
| 6334 | ) |
| 6335 | |
| 6336 | # subsequent seeks should stack |
| 6337 | offset_bytes = x.dtype.itemsize |
| 6338 | z = np.fromfile(f, dtype=x.dtype, offset=offset_bytes) |
| 6339 | assert_array_equal(z, x.flat[offset_items + count_items + 1:]) |
| 6340 | |
| 6341 | with open(tmp_filename, 'wb') as f: |
| 6342 | x.tofile(f, sep=",") |
| 6343 | |
| 6344 | with open(tmp_filename, 'rb') as f: |
| 6345 | assert_raises_regex( |
| 6346 | TypeError, |
| 6347 | "'offset' argument only permitted for binary files", |
| 6348 | np.fromfile, tmp_filename, dtype=x.dtype, |
| 6349 | sep=",", offset=1) |
| 6350 | |
| 6351 | def test_fromfile_bad_dup(self, tmp_path, param_filename, monkeypatch): |
| 6352 | def dup_str(fd): |
nothing calls this directly
no test coverage detected