summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r--numpy/lib/tests/test_io.py57
1 files changed, 54 insertions, 3 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 8922070df..f8caeedb6 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -167,6 +167,52 @@ 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, 'wb')
+ np.savez(fp, data='LOVELY LOAD')
+ fp.close()
+
+ fp = open(tmp, 'rb', 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:
+ fp.close()
+ 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, 'wb')
+ 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)
@@ -1381,8 +1427,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."
@@ -1406,6 +1450,14 @@ 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'))
+ test = np.genfromtxt(StringIO("test1, testNonetherestofthedata"),
+ dtype=None, comments=None, delimiter=',')
+ assert_equal(test[1], asbytes(' testNonetherestofthedata'))
def test_recfromtxt(self):
#
@@ -1426,7 +1478,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')