Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(26)

Unified Diff: Lib/test/test_memoryio.py

Issue 20435: Discrepancy between io.StringIO and _pyio.StringIO with univeral newlines
Patch Set: Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/_pyio.py ('k') | Modules/_io/stringio.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_memoryio.py Wed Jan 29 11:45:31 2014 +0200
+++ b/Lib/test/test_memoryio.py Wed Jan 29 12:16:31 2014 +0200
@@ -539,53 +539,81 @@
def test_newline_none(self):
# newline=None
memio = self.ioclass("a\nb\r\nc\rd", newline=None)
+ #self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
self.assertEqual(list(memio), ["a\n", "b\n", "c\n", "d"])
memio.seek(0)
self.assertEqual(memio.read(1), "a")
self.assertEqual(memio.read(2), "\nb")
self.assertEqual(memio.read(2), "\nc")
self.assertEqual(memio.read(1), "\n")
+
memio = self.ioclass(newline=None)
self.assertEqual(2, memio.write("a\n"))
self.assertEqual(3, memio.write("b\r\n"))
self.assertEqual(3, memio.write("c\rd"))
+ #self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
memio.seek(0)
self.assertEqual(memio.read(), "a\nb\nc\nd")
+
memio = self.ioclass("a\r\nb", newline=None)
self.assertEqual(memio.read(3), "a\nb")
def test_newline_empty(self):
# newline=""
memio = self.ioclass("a\nb\r\nc\rd", newline="")
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
self.assertEqual(list(memio), ["a\n", "b\r\n", "c\r", "d"])
memio.seek(0)
self.assertEqual(memio.read(4), "a\nb\r")
self.assertEqual(memio.read(2), "\nc")
self.assertEqual(memio.read(1), "\r")
+
memio = self.ioclass(newline="")
self.assertEqual(2, memio.write("a\n"))
self.assertEqual(2, memio.write("b\r"))
self.assertEqual(2, memio.write("\nc"))
self.assertEqual(2, memio.write("\rd"))
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
memio.seek(0)
self.assertEqual(list(memio), ["a\n", "b\r\n", "c\r", "d"])
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(memio.getvalue(), "a\nb\r\nc\rd")
+ self.assertEqual(list(memio), ["a\n", "b\r\n", "c\rd"])
+
+ memio = self.ioclass(newline="\n")
+ self.assertEqual(memio.write("a\nb\r\nc\rd"), 8)
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
+ memio.seek(0)
self.assertEqual(list(memio), ["a\n", "b\r\n", "c\rd"])
def test_newline_cr(self):
# newline="\r"
memio = self.ioclass("a\nb\r\nc\rd", newline="\r")
- self.assertEqual(memio.read(), "a\rb\r\rc\rd")
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
+ self.assertEqual(memio.read(), "a\nb\r\nc\rd")
+ memio.seek(0)
+ self.assertEqual(list(memio),['a\nb\r', '\nc\r', 'd'])
+
+ memio = self.ioclass(newline="\r")
+ self.assertEqual(memio.write("a\nb\r\nc\rd"), 8)
+ self.assertEqual(memio.getvalue(), "a\rb\r\rc\rd")
memio.seek(0)
self.assertEqual(list(memio), ["a\r", "b\r", "\r", "c\r", "d"])
def test_newline_crlf(self):
# newline="\r\n"
memio = self.ioclass("a\nb\r\nc\rd", newline="\r\n")
- self.assertEqual(memio.read(), "a\r\nb\r\r\nc\rd")
+ self.assertEqual(memio.getvalue(), "a\nb\r\nc\rd")
+ self.assertEqual(memio.read(), "a\nb\r\nc\rd")
+ memio.seek(0)
+ self.assertEqual(list(memio), ['a\nb\r\n', 'c\rd'])
+
+ memio = self.ioclass(newline="\r\n")
+ self.assertEqual(memio.write("a\nb\r\nc\rd"), 8)
+ self.assertEqual(memio.getvalue(), "a\r\nb\r\r\nc\rd")
memio.seek(0)
self.assertEqual(list(memio), ["a\r\n", "b\r\r\n", "c\rd"])
« no previous file with comments | « Lib/_pyio.py ('k') | Modules/_io/stringio.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+