adds tests for new bytestream handling

This commit is contained in:
jwittenbach
2016-04-16 19:02:31 -04:00
parent ad89b14d4f
commit ffd35b7c5b
2 changed files with 19 additions and 0 deletions
+18
View File
@@ -42,6 +42,8 @@ def test_extension():
class TestSave:
def roundtrip(self, dtype, x):
# input: file name
f = NamedTemporaryFile(suffix='.tif')
fname = f.name
f.close()
@@ -49,6 +51,22 @@ class TestSave:
y = imread(fname)
assert_array_equal(x, y)
# input: open file object
f = NamedTemporaryFile(suffix='.tif')
imsave(f, x)
f.seek(0)
y = imread(f)
assert_array_equal(x, y)
f.close()
#input: byte stream
from io import BytesIO
b = BytesIO()
imsave(b, x)
b.seek(0)
y = imread(b)
assert_array_equal(x, y)
def test_imsave_roundtrip(self):
for shape in [(10, 10), (10, 10, 3), (10, 10, 4)]:
for dtype in (np.uint8, np.uint16, np.float32, np.int16,
+1
View File
@@ -1264,6 +1264,7 @@ class TiffFile(object):
def close(self):
"""Close open file handle(s)."""
for tif in self._files.values():
tif._fh.close()
self._files = {}