test_compat.py 691 B

1234567891011121314151617181920212223242526
  1. from __future__ import division, absolute_import, print_function
  2. from os.path import join
  3. from numpy.compat import isfileobj, os_fspath
  4. from numpy.testing import assert_
  5. from numpy.testing import tempdir
  6. def test_isfileobj():
  7. with tempdir(prefix="numpy_test_compat_") as folder:
  8. filename = join(folder, 'a.bin')
  9. with open(filename, 'wb') as f:
  10. assert_(isfileobj(f))
  11. with open(filename, 'ab') as f:
  12. assert_(isfileobj(f))
  13. with open(filename, 'rb') as f:
  14. assert_(isfileobj(f))
  15. def test_os_fspath_strings():
  16. for string_path in (b'/a/b/c.d', u'/a/b/c.d'):
  17. assert_(os_fspath(string_path) == string_path)