test_io.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from __future__ import division, print_function, absolute_import
  2. import pytest
  3. from numpy.testing import assert_array_equal
  4. from scipy._lib._numpy_compat import suppress_warnings
  5. import scipy.ndimage as ndi
  6. import os
  7. try:
  8. from PIL import Image
  9. pil_missing = False
  10. except ImportError:
  11. pil_missing = True
  12. @pytest.mark.skipif(pil_missing, reason="The Python Image Library could not be found.")
  13. def test_imread():
  14. lp = os.path.join(os.path.dirname(__file__), 'dots.png')
  15. with suppress_warnings() as sup:
  16. # PIL causes a Py3k ResourceWarning
  17. sup.filter(message="unclosed file")
  18. sup.filter(DeprecationWarning)
  19. img = ndi.imread(lp, mode="RGB")
  20. assert_array_equal(img.shape, (300, 420, 3))
  21. with suppress_warnings() as sup:
  22. # PIL causes a Py3k ResourceWarning
  23. sup.filter(message="unclosed file")
  24. sup.filter(DeprecationWarning)
  25. img = ndi.imread(lp, flatten=True)
  26. assert_array_equal(img.shape, (300, 420))
  27. with open(lp, 'rb') as fobj:
  28. with suppress_warnings() as sup:
  29. sup.filter(DeprecationWarning)
  30. img = ndi.imread(fobj, mode="RGB")
  31. assert_array_equal(img.shape, (300, 420, 3))