From 0e3a3d96c7a8e522184c7ca0388cd9d401e902cd Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 2 Jul 2012 16:38:09 -0400 Subject: ENH: unittest for preceeding commit fixing #2178 --- numpy/lib/tests/test_io.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 8922070df..e9158baa8 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -167,6 +167,27 @@ class TestSavezLoad(RoundtripTest, TestCase): if errors: raise AssertionError(errors) + def test_not_closing_opened_fid(self): + # Test that issue #2178 is fixed: + # verify could seek on 'loaded' file + + fd, tmp = mkstemp(suffix='.npz') + os.close(fd) + try: + fp = open(tmp, 'w') + np.savez(fp, data='LOVELY LOAD') + fp.close() + + fp = open(tmp, 'r', 10000) + fp.seek(0) + assert_(not fp.closed) + _ = np.load(fp)['data'] + assert_(not fp.closed) # must not get closed by .load(opened fp) + fp.seek(0) + assert_(not fp.closed) + finally: + os.remove(tmp) + class TestSaveTxt(TestCase): def test_array(self): a = np.array([[1, 2], [3, 4]], float) -- cgit v1.2.1 From 81a03cff05e250fd9982042c332bd4e15e0b3962 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 5 Jul 2012 09:56:26 -0400 Subject: ENH: added a rudimentary test for having #1517 (too many open files) fixed --- numpy/lib/tests/test_io.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index e9158baa8..f6cc365ef 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -185,9 +185,33 @@ class TestSavezLoad(RoundtripTest, TestCase): assert_(not fp.closed) # must not get closed by .load(opened fp) fp.seek(0) assert_(not fp.closed) + + finally: + os.remove(tmp) + + def test_closing_fid(self): + # Test that issue #1517 (too many opened files) remains closed + # It might be a "week" test since failed to get triggered on + # e.g. Debian sid of 2012 Jul 05 but was reported to + # trigger the failure on Ubuntu 10.04: + # http://projects.scipy.org/numpy/ticket/1517#comment:2 + fd, tmp = mkstemp(suffix='.npz') + os.close(fd) + + try: + fp = open(tmp, 'w') + np.savez(fp, data='LOVELY LOAD') + fp.close() + + for i in range(1, 1025): + try: + np.load(tmp)["data"] + except Exception, e: + raise AssertionError("Failed to load data from a file: %s" % e) finally: os.remove(tmp) + class TestSaveTxt(TestCase): def test_array(self): a = np.array([[1, 2], [3, 4]], float) -- cgit v1.2.1 From 613589e2286b03171829bf4ff8cb5c9c863df4be Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 6 Jul 2012 15:26:26 -0400 Subject: BF(PY3): open file handles in tests in binary mode otherwise zipfile of python3 gets confused to receive bytes for the header whenever handle is opened for a text (unicode) file --- numpy/lib/tests/test_io.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index f6cc365ef..c539c040a 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -174,11 +174,11 @@ class TestSavezLoad(RoundtripTest, TestCase): fd, tmp = mkstemp(suffix='.npz') os.close(fd) try: - fp = open(tmp, 'w') + fp = open(tmp, 'wb') np.savez(fp, data='LOVELY LOAD') fp.close() - fp = open(tmp, 'r', 10000) + fp = open(tmp, 'rb', 10000) fp.seek(0) assert_(not fp.closed) _ = np.load(fp)['data'] @@ -199,7 +199,7 @@ class TestSavezLoad(RoundtripTest, TestCase): os.close(fd) try: - fp = open(tmp, 'w') + fp = open(tmp, 'wb') np.savez(fp, data='LOVELY LOAD') fp.close() -- cgit v1.2.1 From 1a70875974aecec81de1866ad9847d511d420f65 Mon Sep 17 00:00:00 2001 From: martingoodson Date: Tue, 10 Jul 2012 16:31:03 +0200 Subject: BUG: make genfromtxt work with comments=None. Closes Github issue 329. --- numpy/lib/tests/test_io.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index c539c040a..aeda7663c 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1426,8 +1426,6 @@ M 33 21.99 usecols=("A", "C", "E"), names=True) assert_equal(test.dtype.names, ctrl_names) - - def test_fixed_width_names(self): "Test fix-width w/ names" data = " A B C\n 0 1 2.3\n 45 67 9." @@ -1451,6 +1449,11 @@ M 33 21.99 test = np.ndfromtxt(StringIO(data), **kwargs) assert_equal(test, ctrl) + def test_comments_is_none(self): + # Github issue 329 (None was previously being converted to 'None'). + test = np.genfromtxt(StringIO("test1,testNonetherestofthedata"), + dtype=None, comments=None, delimiter=',') + assert_equal(test[1], asbytes('testNonetherestofthedata')) def test_recfromtxt(self): # @@ -1471,7 +1474,6 @@ M 33 21.99 assert_equal(test.mask, control.mask) assert_equal(test.A, [0, 2]) - def test_recfromcsv(self): # data = StringIO('A,B\n0,1\n2,3') -- cgit v1.2.1 From 3556a2bc6605ac7267f420b3fb8d406b74616b47 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Wed, 11 Jul 2012 18:49:32 +0200 Subject: BUG: genfromtxt: make comments=None work with spaces in strings. --- numpy/lib/tests/test_io.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index aeda7663c..0762c82e1 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1454,6 +1454,9 @@ M 33 21.99 test = np.genfromtxt(StringIO("test1,testNonetherestofthedata"), dtype=None, comments=None, delimiter=',') assert_equal(test[1], asbytes('testNonetherestofthedata')) + test = np.genfromtxt(StringIO("test1, testNonetherestofthedata"), + dtype=None, comments=None, delimiter=',') + assert_equal(test[1], asbytes(' testNonetherestofthedata')) def test_recfromtxt(self): # -- cgit v1.2.1 From 08c507b740a1a8f1f55217f683938c375a006975 Mon Sep 17 00:00:00 2001 From: cgohlke Date: Mon, 16 Jul 2012 13:48:47 -0700 Subject: Fix `WindowsError: [Error 32]` in test_not_closing_opened_fid (test_io.TestSavezLoad) --- numpy/lib/tests/test_io.py | 1 + 1 file changed, 1 insertion(+) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 0762c82e1..f8caeedb6 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -187,6 +187,7 @@ class TestSavezLoad(RoundtripTest, TestCase): assert_(not fp.closed) finally: + fp.close() os.remove(tmp) def test_closing_fid(self): -- cgit v1.2.1