summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@gmail.com>2016-05-15 10:45:21 +0200
committerRalf Gommers <ralf.gommers@gmail.com>2016-05-15 10:45:21 +0200
commit1e8d544a4adc396813b61b93611f5f41f147de56 (patch)
treec38998fc26b6d478da66080e4fdbcbf992ddac2e /numpy/lib/tests/test_io.py
parente96ebfc233412e8da98ae96f5c640d00f5411f6e (diff)
downloadnumpy-1e8d544a4adc396813b61b93611f5f41f147de56.tar.gz
TST: fix test errors for Pathlib usage tests in io.py.
Pathlib was only added to the stdlib in Python 3.4, and there it can handle string type input for a file with UTF8 encoding. But the Patlib version on PyPi that can be installed for Python 2.7 doesn't accept strings, gives errors like: ====================================================================== ERROR: test_ndfromtxt (test_io.TestPathUsage) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/rgommers/Code/numpy/numpy/testing/decorators.py", line 147, in skipper_func return f(*args, **kwargs) File "/home/rgommers/Code/numpy/numpy/lib/tests/test_io.py", line 1888, in test_ndfromtxt f.write('1 2\n3 4') TypeError: must be unicode, not str
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r--numpy/lib/tests/test_io.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 720f2e74e..3b0b83712 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1869,7 +1869,7 @@ class TestPathUsage(TestCase):
data = np.load(path)
assert_array_equal(data['lab'], 'place holder')
data.close()
-
+
@np.testing.dec.skipif(Path is None, "No pathlib.Path")
def test_genfromtxt(self):
with temppath(suffix='.txt') as path:
@@ -1878,49 +1878,52 @@ class TestPathUsage(TestCase):
np.savetxt(path, a)
data = np.genfromtxt(path)
assert_array_equal(a, data)
-
+
@np.testing.dec.skipif(Path is None, "No pathlib.Path")
def test_ndfromtxt(self):
# Test outputing a standard ndarray
with temppath(suffix='.txt') as path:
path = Path(path)
with path.open('w') as f:
- f.write('1 2\n3 4')
+ f.write(u'1 2\n3 4')
+
control = np.array([[1, 2], [3, 4]], dtype=int)
test = np.ndfromtxt(path, dtype=int)
assert_array_equal(test, control)
-
+
@np.testing.dec.skipif(Path is None, "No pathlib.Path")
def test_mafromtxt(self):
# From `test_fancy_dtype_alt` above
with temppath(suffix='.txt') as path:
path = Path(path)
with path.open('w') as f:
- f.write('1,2,3.0\n4,5,6.0\n')
-
+ f.write(u'1,2,3.0\n4,5,6.0\n')
+
test = np.mafromtxt(path, delimiter=',')
control = ma.array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)])
assert_equal(test, control)
-
+
@np.testing.dec.skipif(Path is None, "No pathlib.Path")
def test_recfromtxt(self):
with temppath(suffix='.txt') as path:
path = Path(path)
with path.open('w') as f:
- f.write('A,B\n0,1\n2,3')
+ f.write(u'A,B\n0,1\n2,3')
+
kwargs = dict(delimiter=",", missing_values="N/A", names=True)
test = np.recfromtxt(path, **kwargs)
control = np.array([(0, 1), (2, 3)],
dtype=[('A', np.int), ('B', np.int)])
self.assertTrue(isinstance(test, np.recarray))
assert_equal(test, control)
-
+
@np.testing.dec.skipif(Path is None, "No pathlib.Path")
def test_recfromcsv(self):
with temppath(suffix='.txt') as path:
path = Path(path)
with path.open('w') as f:
- f.write('A,B\n0,1\n2,3')
+ f.write(u'A,B\n0,1\n2,3')
+
kwargs = dict(missing_values="N/A", names=True, case_sensitive=True)
test = np.recfromcsv(path, dtype=None, **kwargs)
control = np.array([(0, 1), (2, 3)],