summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
diff options
context:
space:
mode:
authorMatthew Brett <matthew.brett@gmail.com>2011-03-29 18:23:07 -0700
committerMatthew Brett <matthew.brett@gmail.com>2011-03-30 10:21:36 -0700
commit354d7a311ef9a6dfd4695147c644ff0294c8c4ee (patch)
tree9eddffe03e85a7076ac43ca8229c42bd8184dc15 /numpy/lib/tests/test_io.py
parenta3889707c684bc3d4f885927c7d4692147be7e86 (diff)
downloadnumpy-354d7a311ef9a6dfd4695147c644ff0294c8c4ee.tar.gz
BUG: open genfromtxt file as binary; add test for filename use
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r--numpy/lib/tests/test_io.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 5001f6bac..96e92c776 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1,6 +1,7 @@
import numpy as np
import numpy.ma as ma
-from numpy.ma.testutils import *
+from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal,
+ assert_raises, run_module_suite)
from numpy.testing import assert_warns
import sys
@@ -1248,6 +1249,24 @@ M 33 21.99
self.assertTrue(isinstance(test, np.recarray))
assert_equal(test, control)
+ def test_gft_filename(self):
+ # Test that we can load data from a filename as well as a file object
+ data = '0 1 2\n3 4 5'
+ exp_res = np.arange(6).reshape((2,3))
+ assert_array_equal(np.genfromtxt(StringIO(data)), exp_res)
+ f, name = mkstemp()
+ # 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 string
+ # of the test reference array, write it to a securely opened file,
+ # which is then read from by the loadtxt function
+ try:
+ os.write(f, asbytes(data))
+ assert_array_equal(np.genfromtxt(name), exp_res)
+ finally:
+ os.close(f)
+ os.unlink(name)
+
def test_gzip_load():
a = np.random.random((5, 5))