summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authorDaniel da Silva <daniel@meltingwax.net>2014-04-04 23:48:58 -0400
committerDaniel da Silva <daniel@meltingwax.net>2014-04-05 14:39:35 -0400
commit079ca4d2da488ffb7af1fc923728c3abde867231 (patch)
treeef28ee1f3d849e3c71f2fe8fd7c6f95ef86c8492 /numpy/lib/tests
parenta0794f63d548e688e2eed76a9dc4e8df0ea33846 (diff)
downloadnumpy-079ca4d2da488ffb7af1fc923728c3abde867231.tar.gz
ENH: Better error w/ line num for bad column count in np.loadtxt()
Resolves #2591. Adds more explicit error handling in line parsing loop.
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_io.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 418386e35..d0f81bde3 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -19,10 +19,13 @@ from numpy.lib._iotools import (ConverterError, ConverterLockError,
ConversionWarning)
from numpy.compat import asbytes, asbytes_nested, bytes, asstr
from nose import SkipTest
-from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal,
- assert_raises, run_module_suite)
+from numpy.ma.testutils import (
+ TestCase, assert_equal, assert_array_equal,
+ assert_raises, assert_raises_regex, run_module_suite
+)
from numpy.testing import assert_warns, assert_, build_err_msg
+
@contextlib.contextmanager
def tempdir(change_dir=False):
tmpdir = mkdtemp()
@@ -759,6 +762,14 @@ class TestLoadTxt(TestCase):
res = np.loadtxt(count())
assert_array_equal(res, np.arange(10))
+ def test_bad_line(self):
+ c = TextIO()
+ c.write('1 2 3\n4 5 6\n2 3')
+ c.seek(0)
+
+ # Check for exception and that exception contains line number
+ assert_raises_regex(ValueError, "3", np.loadtxt, c)
+
class Testfromregex(TestCase):
# np.fromregex expects files opened in binary mode.