test_pathological.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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 os.path import dirname, join as pjoin
  5. from numpy.testing import assert_
  6. from pytest import raises as assert_raises
  7. from scipy.io.matlab._mio import loadmat
  8. TEST_DATA_PATH = pjoin(dirname(__file__), 'data')
  9. def test_multiple_fieldnames():
  10. # Example provided by Dharhas Pothina
  11. # Extracted using mio5.varmats_from_mat
  12. multi_fname = pjoin(TEST_DATA_PATH, 'nasty_duplicate_fieldnames.mat')
  13. vars = loadmat(multi_fname)
  14. funny_names = vars['Summary'].dtype.names
  15. assert_(set(['_1_Station_Q', '_2_Station_Q',
  16. '_3_Station_Q']).issubset(funny_names))
  17. def test_malformed1():
  18. # Example from gh-6072
  19. # Contains malformed header data, which previously resulted into a
  20. # buffer overflow.
  21. #
  22. # Should raise an exception, not segfault
  23. fname = pjoin(TEST_DATA_PATH, 'malformed1.mat')
  24. with open(fname, 'rb') as f:
  25. assert_raises(ValueError, loadmat, f)