diff options
author | David Cournapeau <cournape@gmail.com> | 2009-03-09 09:24:29 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-03-09 09:24:29 +0000 |
commit | 03c47e45987edf002f4094d3d39f4a1e3eff01f0 (patch) | |
tree | 4069ee6d16a62d4a57cc7e93eaf338173ab869c0 /numpy/lib/tests/test_io.py | |
parent | 2ef6634890ba294a72b67e7a314a1753faa1b985 (diff) | |
download | numpy-03c47e45987edf002f4094d3d39f4a1e3eff01f0.tar.gz |
BUG: Rewrite test_gzip_loadtxt to avoid NamedTemporaryFile which is unusable with windows IO semantics + add another test for compressed string argument to loadtxt.
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index d4f7f0e97..076f20e5e 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -4,8 +4,9 @@ from numpy.ma.testutils import * import StringIO import gzip +import os -from tempfile import NamedTemporaryFile +from tempfile import mkstemp import sys, time from datetime import datetime @@ -807,12 +808,9 @@ M 33 21.99 assert_equal(test, control) def test_gzip_load(): - import gzip - from StringIO import StringIO - a = np.random.random((5, 5)) - s = StringIO() + s = StringIO.StringIO() f = gzip.GzipFile(fileobj=s, mode="w") np.save(f, a) @@ -823,12 +821,35 @@ def test_gzip_load(): assert_array_equal(np.load(f), a) def test_gzip_loadtxt(): - f = NamedTemporaryFile(suffix='.gz') - g = gzip.GzipFile(fileobj=f) + # Thanks to another windows brokeness, we can't use + # NamedTemporaryFile: a file created from this function cannot be + # reopened by another open call. So we first put the gzipped string + # of the test reference array, write it to a securely opened file, + # which is then read from by the loadtxt function + s = StringIO.StringIO() + g = gzip.GzipFile(fileobj=s, mode='w') g.write('1 2 3\n') g.close() - f.seek(0) - assert_array_equal(np.loadtxt(f.name), [1, 2, 3]) + s.seek(0) + + f, name = mkstemp(suffix='.gz') + try: + os.write(f, s.read()) + s.close() + assert_array_equal(np.loadtxt(name), [1, 2, 3]) + finally: + os.close(f) + os.unlink(name) + +def test_gzip_loadtxt_from_string(): + s = StringIO.StringIO() + f = gzip.GzipFile(fileobj=s, mode="w") + f.write('1 2 3\n') + f.close() + s.seek(0) + + f = gzip.GzipFile(fileobj=s, mode="r") + assert_array_equal(np.loadtxt(f), [1, 2, 3]) if __name__ == "__main__": run_module_suite() |