Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc3fcec

Browse filesBrowse files
committed
TST: add tests for file read failures in read_array
1 parent 018a202 commit fc3fcec
Copy full SHA for fc3fcec

File tree

Expand file treeCollapse file tree

1 file changed

+16
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-1
lines changed

‎numpy/lib/tests/test_format.py

Copy file name to clipboardExpand all lines: numpy/lib/tests/test_format.py
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
import numpy as np
284284
from numpy.testing import (
285285
assert_, assert_array_equal, assert_raises, assert_raises_regex,
286-
assert_warns, IS_PYPY, IS_WASM
286+
assert_warns, temppath, IS_PYPY, IS_WASM
287287
)
288288
from numpy.testing._private.utils import requires_memory
289289
from numpy.lib import format
@@ -428,6 +428,17 @@ def roundtrip_truncated(arr):
428428
arr2 = format.read_array(f2)
429429
return arr2
430430

431+
def file_truncated(arr):
432+
with temppath() as path:
433+
with open(path, 'wb') as f:
434+
format.write_array(f, arr)
435+
#truncate the file by one byte
436+
with open(path, 'rb+') as f:
437+
f.seek(-1, os.SEEK_END)
438+
f.truncate()
439+
with open(path, 'rb') as f:
440+
arr2 = format.read_array(f)
441+
return arr2
431442

432443
def assert_equal_(o1, o2):
433444
assert_(o1 == o2)
@@ -451,6 +462,10 @@ def test_roundtrip_truncated():
451462
if arr.dtype != object:
452463
assert_raises(ValueError, roundtrip_truncated, arr)
453464

465+
def test_file_truncated():
466+
for arr in basic_arrays:
467+
if arr.dtype != object:
468+
assert_raises(ValueError, file_truncated, arr)
454469

455470
def test_long_str():
456471
# check items larger than internal buffer size, gh-4027

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.