summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-02-05 11:42:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-02-05 11:42:01 (GMT)
commit1812bd44d5cada6e8058c56fb13bba7be919c40d (patch)
treed4c3f2cc26d38cf187536abbc33a01429be2e6da
parentd33491ea76b3898d5fd0fe3ae75e73ea157a7186 (diff)
downloadcpython-1812bd44d5cada6e8058c56fb13bba7be919c40d.zip
cpython-1812bd44d5cada6e8058c56fb13bba7be919c40d.tar.gz
cpython-1812bd44d5cada6e8058c56fb13bba7be919c40d.tar.bz2
Issue #20498: Fixed io.StringIO tests for newline='\n'. Added new tests.
-rw-r--r--Lib/test/test_memoryio.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py
index 6a902b3..4fa9a19 100644
--- a/Lib/test/test_memoryio.py
+++ b/Lib/test/test_memoryio.py
@@ -536,6 +536,17 @@ class TextIOTestMixin:
self.assertIsNone(memio.errors)
self.assertFalse(memio.line_buffering)
+ def test_newline_default(self):
+ memio = self.ioclass("a\nb\r\nc\rd")
+ self.assertEqual(list(memio), ["a\n", "b\r\n", "c\rd"])
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
+
+ memio = self.ioclass()
+ self.assertEqual(memio.write("a\nb\r\nc\rd"), 8)
+ memio.seek(0)
+ self.assertEqual(list(memio), ["a\n", "b\r\n", "c\rd"])
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
+
def test_newline_none(self):
# newline=None
memio = self.ioclass("a\nb\r\nc\rd", newline=None)
@@ -545,6 +556,8 @@ class TextIOTestMixin:
self.assertEqual(memio.read(2), "\nb")
self.assertEqual(memio.read(2), "\nc")
self.assertEqual(memio.read(1), "\n")
+ self.assertEqual(memio.getvalue(), "a\nb\nc\nd")
+
memio = self.ioclass(newline=None)
self.assertEqual(2, memio.write("a\n"))
self.assertEqual(3, memio.write("b\r\n"))
@@ -552,6 +565,7 @@ class TextIOTestMixin:
memio.seek(0)
self.assertEqual(memio.read(), "a\nb\nc\nd")
self.assertEqual(memio.getvalue(), "a\nb\nc\nd")
+
memio = self.ioclass("a\r\nb", newline=None)
self.assertEqual(memio.read(3), "a\nb")
@@ -564,6 +578,7 @@ class TextIOTestMixin:
self.assertEqual(memio.read(2), "\nc")
self.assertEqual(memio.read(1), "\r")
self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
+
memio = self.ioclass(newline="")
self.assertEqual(2, memio.write("a\n"))
self.assertEqual(2, memio.write("b\r"))
@@ -571,11 +586,19 @@ class TextIOTestMixin:
self.assertEqual(2, memio.write("\rd"))
memio.seek(0)
self.assertEqual(list(memio), ["a\n", "b\r\n", "c\r", "d"])
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
def test_newline_lf(self):
# newline="\n"
- memio = self.ioclass("a\nb\r\nc\rd")
+ memio = self.ioclass("a\nb\r\nc\rd", newline="\n")
self.assertEqual(list(memio), ["a\n", "b\r\n", "c\rd"])
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
+
+ memio = self.ioclass(newline="\n")
+ self.assertEqual(memio.write("a\nb\r\nc\rd"), 8)
+ memio.seek(0)
+ self.assertEqual(list(memio), ["a\n", "b\r\n", "c\rd"])
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
def test_newline_cr(self):
# newline="\r"
@@ -583,6 +606,12 @@ class TextIOTestMixin:
self.assertEqual(memio.read(), "a\rb\r\rc\rd")
memio.seek(0)
self.assertEqual(list(memio), ["a\r", "b\r", "\r", "c\r", "d"])
+ self.assertEqual(memio.getvalue(), "a\rb\r\rc\rd")
+
+ memio = self.ioclass(newline="\r")
+ self.assertEqual(memio.write("a\nb\r\nc\rd"), 8)
+ memio.seek(0)
+ self.assertEqual(list(memio), ["a\r", "b\r", "\r", "c\r", "d"])
memio.seek(0)
self.assertEqual(memio.readlines(), ["a\r", "b\r", "\r", "c\r", "d"])
self.assertEqual(memio.getvalue(), "a\rb\r\rc\rd")
@@ -597,6 +626,12 @@ class TextIOTestMixin:
self.assertEqual(memio.readlines(), ["a\r\n", "b\r\r\n", "c\rd"])
self.assertEqual(memio.getvalue(), "a\r\nb\r\r\nc\rd")
+ memio = self.ioclass(newline="\r\n")
+ self.assertEqual(memio.write("a\nb\r\nc\rd"), 8)
+ memio.seek(0)
+ self.assertEqual(list(memio), ["a\r\n", "b\r\r\n", "c\rd"])
+ self.assertEqual(memio.getvalue(), "a\r\nb\r\r\nc\rd")
+
def test_issue5265(self):
# StringIO can duplicate newlines in universal newlines mode
memio = self.ioclass("a\r\nb\r\n", newline=None)