Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3dcb0cf

Browse files
Issue #20520: Fixed readline test in test_codecs.
2 parents bfafa61 + 5b4fab1 commit 3dcb0cf

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

Lib/test/test_codecs.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,32 +148,41 @@ def readalllines(input, keepends=True, size=None):
148148
self.assertEqual(readalllines(s, True, 10), sexpected)
149149
self.assertEqual(readalllines(s, False, 10), sexpectednoends)
150150

151+
lineends = ("\n", "\r\n", "\r", "\u2028")
151152
# Test long lines (multiple calls to read() in readline())
152153
vw = []
153154
vwo = []
154-
for (i, lineend) in enumerate("\n \r\n \r \u2028".split()):
155-
vw.append((i*200)*"\3042" + lineend)
156-
vwo.append((i*200)*"\3042")
157-
self.assertEqual(readalllines("".join(vw), True), "".join(vw))
158-
self.assertEqual(readalllines("".join(vw), False),"".join(vwo))
155+
for (i, lineend) in enumerate(lineends):
156+
vw.append((i*200+200)*"\u3042" + lineend)
157+
vwo.append((i*200+200)*"\u3042")
158+
self.assertEqual(readalllines("".join(vw), True), "|".join(vw))
159+
self.assertEqual(readalllines("".join(vw), False), "|".join(vwo))
159160

160161
# Test lines where the first read might end with \r, so the
161162
# reader has to look ahead whether this is a lone \r or a \r\n
162163
for size in range(80):
163-
for lineend in "\n \r\n \r \u2028".split():
164+
for lineend in lineends:
164165
s = 10*(size*"a" + lineend + "xxx\n")
165166
reader = getreader(s)
166167
for i in range(10):
167168
self.assertEqual(
168169
reader.readline(keepends=True),
169170
size*"a" + lineend,
170171
)
172+
self.assertEqual(
173+
reader.readline(keepends=True),
174+
"xxx\n",
175+
)
171176
reader = getreader(s)
172177
for i in range(10):
173178
self.assertEqual(
174179
reader.readline(keepends=False),
175180
size*"a",
176181
)
182+
self.assertEqual(
183+
reader.readline(keepends=False),
184+
"xxx",
185+
)
177186

178187
def test_mixed_readline_and_read(self):
179188
lines = ["Humpty Dumpty sat on a wall,\n",

0 commit comments

Comments
 (0)