diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2019-07-22 20:03:22 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-22 20:03:22 -0500 |
commit | 1f584139324a4b818ec39dec2a2d9f3e30b57297 (patch) | |
tree | 828a85ec24f36aafac70639f4de9b543f13c68bd /numpy/lib/tests | |
parent | a06c949bbfca81db4e9c000f27f3c417788ce6b7 (diff) | |
parent | 71a825224e0b38bd21b6144c2563e04d954c7baf (diff) | |
download | numpy-1f584139324a4b818ec39dec2a2d9f3e30b57297.tar.gz |
Merge pull request #14063 from luispedro/fix_save_duck_check
BUG: Fix file-like object check when saving arrays
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_io.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 38d4c19fa..78f9f85f3 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -2472,6 +2472,44 @@ def test_gzip_load(): assert_array_equal(np.load(f), a) +# These next two classes encode the minimal API needed to save()/load() arrays. +# The `test_ducktyping` ensures they work correctly +class JustWriter(object): + def __init__(self, base): + self.base = base + + def write(self, s): + return self.base.write(s) + + def flush(self): + return self.base.flush() + +class JustReader(object): + def __init__(self, base): + self.base = base + + def read(self, n): + return self.base.read(n) + + def seek(self, off, whence=0): + return self.base.seek(off, whence) + + +def test_ducktyping(): + a = np.random.random((5, 5)) + + s = BytesIO() + f = JustWriter(s) + + np.save(f, a) + f.flush() + s.seek(0) + + f = JustReader(s) + assert_array_equal(np.load(f), a) + + + def test_gzip_loadtxt(): # Thanks to another windows brokenness, we can't use # NamedTemporaryFile: a file created from this function cannot be |