test_pathological.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """ Test reading of files not conforming to matlab specification
  2. We try and read any file that matlab reads, these files included
  3. """
  4. from __future__ import division, print_function, absolute_import
  5. from os.path import dirname, join as pjoin
  6. from numpy.testing import assert_
  7. from pytest import raises as assert_raises
  8. from scipy.io.matlab.mio import loadmat
  9. TEST_DATA_PATH = pjoin(dirname(__file__), 'data')
  10. def test_multiple_fieldnames():
  11. # Example provided by Dharhas Pothina
  12. # Extracted using mio5.varmats_from_mat
  13. multi_fname = pjoin(TEST_DATA_PATH, 'nasty_duplicate_fieldnames.mat')
  14. vars = loadmat(multi_fname)
  15. funny_names = vars['Summary'].dtype.names
  16. assert_(set(['_1_Station_Q', '_2_Station_Q',
  17. '_3_Station_Q']).issubset(funny_names))
  18. def test_malformed1():
  19. # Example from gh-6072
  20. # Contains malformed header data, which previously resulted into a
  21. # buffer overflow.
  22. #
  23. # Should raise an exception, not segfault
  24. fname = pjoin(TEST_DATA_PATH, 'malformed1.mat')
  25. with open(fname, 'rb') as f:
  26. assert_raises(ValueError, loadmat, f)