From d4b976f0d539ecea13cdc8c4e6ce7770427ded2d Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Tue, 5 Apr 2011 11:17:30 -0700 Subject: [PATCH 1/2] TST: test for different line endings in genfromtxt input file --- numpy/lib/tests/test_io.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 4894f8939650..4c3a01b801d7 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1313,21 +1313,18 @@ def test_recfromcsv(self): 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) + for sep in ('\n', '\r', '\r\n'): + data = '0 1 2' + sep + '3 4 5' + f, name = mkstemp() + # We can't use NamedTemporaryFile on windows, because we cannot + # reopen the file. + try: + os.write(f, asbytes(data)) + assert_array_equal(np.genfromtxt(name), exp_res) + finally: + os.close(f) + os.unlink(name) def test_gft_generator_source(self): def count(): From 87ac1f565182cb6be115b556db9ec97d88edddbe Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Wed, 6 Apr 2011 15:31:25 -0700 Subject: [PATCH 2/2] TST - add skiptest for failing py3k \n line endings --- numpy/lib/tests/test_io.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 4c3a01b801d7..b582ceea2b2d 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1,23 +1,22 @@ -import numpy as np -import numpy.ma as ma -from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal, - assert_raises, run_module_suite) -from numpy.testing import assert_warns, assert_ - import sys - import gzip import os import threading - from tempfile import mkstemp, NamedTemporaryFile import time from datetime import datetime +import numpy as np +import numpy.ma as ma from numpy.lib._iotools import ConverterError, ConverterLockError, \ ConversionWarning from numpy.compat import asbytes, asbytes_nested, bytes +from nose import SkipTest +from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal, + assert_raises, run_module_suite) +from numpy.testing import assert_warns, assert_ + if sys.version_info[0] >= 3: from io import BytesIO def StringIO(s=""): @@ -1313,15 +1312,18 @@ def test_recfromcsv(self): def test_gft_filename(self): # Test that we can load data from a filename as well as a file object - exp_res = np.arange(6).reshape((2,3)) - for sep in ('\n', '\r', '\r\n'): + wanted = np.arange(6).reshape((2,3)) + is_py3 = sys.version_info[0] >= 3 + for sep in ('\n', '\r\n', '\r'): + if sep == '\r' and is_py3: + raise SkipTest(r'Py3 version does not split lines on \r') data = '0 1 2' + sep + '3 4 5' f, name = mkstemp() # We can't use NamedTemporaryFile on windows, because we cannot # reopen the file. try: os.write(f, asbytes(data)) - assert_array_equal(np.genfromtxt(name), exp_res) + assert_array_equal(np.genfromtxt(name), wanted) finally: os.close(f) os.unlink(name)