summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-01-14 11:55:45 -0600
committerSebastian Berg <sebastian@sipsolutions.net>2022-01-14 20:07:07 -0600
commitd58d3612cb3417c3516992b45ac04f7cbf1209a0 (patch)
tree3e1d2f8f08b62c8cc559e778b5ee2a0c2932f5c8 /numpy/lib
parent6e67e17475004035d76f8b51c315bedd1cb2809f (diff)
downloadnumpy-d58d3612cb3417c3516992b45ac04f7cbf1209a0.tar.gz
TST: Add test for hard/impossible to reach universal-newline support paths
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/tests/test_io.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 7f3f3e1f2..5f66e0b6a 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -3474,3 +3474,18 @@ class TestCReaderUnitTests:
with pytest.raises(TypeError, match="encoding must be a unicode"):
np.core._multiarray_umath._load_from_filelike(
object(), dtype=np.dtype("i"), filelike=False, encoding=123)
+
+ @pytest.mark.parametrize("newline", ["\r", "\n", "\r\n"])
+ def test_manual_universal_newlines(self, newline):
+ # This is currently not available to users, because we should always
+ # open files with universal newlines enabled `newlines=None`.
+ # (And reading from an iterator uses slightly different code paths.)
+ # We have no real support for `newline="\r"` or `newline="\n" as the
+ # user cannot specify those options.
+ data = StringIO('0\n1\n"2\n"\n3\n4 #\n'.replace("\n", newline),
+ newline="")
+
+ res = np.core._multiarray_umath._load_from_filelike(
+ data, dtype=np.dtype("U10"), filelike=True,
+ quote='"', comment="#", skiplines=1)
+ assert_array_equal(res[:, 0], ["1", f"2{newline}", "3", "4 "])