Skip to content

Commit d0645f7

Browse files
astrofrogRalf Gommers
authored andcommitted
TST: added regression test for io.readsav issue with invalid pointers.
1 parent e83e981 commit d0645f7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed
1.25 KB
Binary file not shown.

scipy/io/tests/test_idl.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import division, print_function, absolute_import
22

33
from os import path
4-
4+
from warnings import catch_warnings
55

66
DATA_PATH = path.join(path.dirname(__file__), 'data')
77

@@ -408,12 +408,27 @@ def test_description(self):
408408

409409

410410
def test_null_pointer():
411-
"""
412-
Regression test for null pointers.
413-
"""
411+
# Regression test for null pointers.
414412
s = readsav(path.join(DATA_PATH, 'null_pointer.sav'), verbose=False)
415413
assert_identical(s.point, None)
416414
assert_identical(s.check, np.int16(5))
417415

416+
417+
def test_invalid_pointer():
418+
# Regression test for invalid pointers (gh-4613).
419+
420+
# In some files in the wild, pointers can sometimes refer to a heap
421+
# variable that does not exist. In that case, we now gracefully fail for
422+
# that variable and replace the variable with None and emit a warning.
423+
# Since it's difficult to artificially produce such files, the file used
424+
# here has been edited to force the pointer reference to be invalid.
425+
with catch_warnings(record=True) as w:
426+
s = readsav(path.join(DATA_PATH, 'invalid_pointer.sav'), verbose=False)
427+
assert_(len(w) == 1)
428+
assert_(str(w[0].message) == ("Variable referenced by pointer not found in "
429+
"heap: variable will be set to None"))
430+
assert_identical(s['a'], np.array([None, None]))
431+
432+
418433
if __name__ == "__main__":
419434
run_module_suite()

0 commit comments

Comments
 (0)