diff options
author | Ross Barnowski <rossbar@berkeley.edu> | 2022-01-10 12:31:16 -0800 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-01-14 20:07:07 -0600 |
commit | 2912231adb4b4b1a89a48277d352f9c93248282f (patch) | |
tree | d59e72c03746453dfcd7005261f143f38a4fdd1b /numpy/lib/tests | |
parent | 942d4f8ab095f152f5e59e43cada49d3d15839d0 (diff) | |
download | numpy-2912231adb4b4b1a89a48277d352f9c93248282f.tar.gz |
Add tests for quote+multichar comments.
Also correct exception message.
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_io.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index a0bc2e135..d73d50959 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -3177,3 +3177,26 @@ def test_loadtxt_quote_support_default(): res = np.loadtxt(txt, dtype=dtype, delimiter=",", quotechar='"') assert_array_equal(res, expected) + + +def test_loadtxt_quotechar_multichar_error(): + txt = StringIO("1,2\n3,4") + msg = r".*must be a single unicode character or None" + with pytest.raises(TypeError, match=msg): + np.loadtxt(txt, delimiter=",", quotechar="''") + + +def test_loadtxt_comment_multichar_error_with_quote(): + txt = StringIO("1,2\n3,4") + msg = ( + "when multiple comments or a multi-character comment is given, " + "quotes are not supported." + ) + with pytest.raises(ValueError, match=msg): + np.loadtxt(txt, delimiter=",", comments="123", quotechar='"') + with pytest.raises(ValueError, match=msg): + np.loadtxt(txt, delimiter=",", comments=["#", "%"], quotechar='"') + + # A single character string in a tuple is unpacked though: + res = np.loadtxt(txt, delimiter=",", comments=("#",), quotechar="'") + assert_equal(res, [[1, 2], [3, 4]]) |