test_byteordercodes.py 1003 B

12345678910111213141516171819202122232425262728293031
  1. ''' Tests for byteorder module '''
  2. from __future__ import division, print_function, absolute_import
  3. import sys
  4. from numpy.testing import assert_
  5. from pytest import raises as assert_raises
  6. import scipy.io.matlab.byteordercodes as sibc
  7. def test_native():
  8. native_is_le = sys.byteorder == 'little'
  9. assert_(sibc.sys_is_le == native_is_le)
  10. def test_to_numpy():
  11. if sys.byteorder == 'little':
  12. assert_(sibc.to_numpy_code('native') == '<')
  13. assert_(sibc.to_numpy_code('swapped') == '>')
  14. else:
  15. assert_(sibc.to_numpy_code('native') == '>')
  16. assert_(sibc.to_numpy_code('swapped') == '<')
  17. assert_(sibc.to_numpy_code('native') == sibc.to_numpy_code('='))
  18. assert_(sibc.to_numpy_code('big') == '>')
  19. for code in ('little', '<', 'l', 'L', 'le'):
  20. assert_(sibc.to_numpy_code(code) == '<')
  21. for code in ('big', '>', 'b', 'B', 'be'):
  22. assert_(sibc.to_numpy_code(code) == '>')
  23. assert_raises(ValueError, sibc.to_numpy_code, 'silly string')