diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-06 07:26:32 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-06 07:26:32 (GMT) |
commit | 6a036793b66683e238c7222eb38368e44127c0e7 (patch) | |
tree | 3f54081fdeb947ead1ba54e96d70b69d33849ee0 | |
parent | ddc697f212326a00689e3c542b8cc3103ef7c384 (diff) | |
download | cpython-6a036793b66683e238c7222eb38368e44127c0e7.zip cpython-6a036793b66683e238c7222eb38368e44127c0e7.tar.gz cpython-6a036793b66683e238c7222eb38368e44127c0e7.tar.bz2 |
Issue #20520: Fixed readline test in test_codecs.
-rw-r--r-- | Lib/test/test_codecs.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index d0f96af..7a4c70b 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -97,19 +97,20 @@ class ReadTest(unittest.TestCase): self.assertEqual(readalllines(s, True, 10), sexpected) self.assertEqual(readalllines(s, False, 10), sexpectednoends) + lineends = ("\n", "\r\n", "\r", u"\u2028") # Test long lines (multiple calls to read() in readline()) vw = [] vwo = [] - for (i, lineend) in enumerate(u"\n \r\n \r \u2028".split()): - vw.append((i*200)*u"\3042" + lineend) - vwo.append((i*200)*u"\3042") - self.assertEqual(readalllines("".join(vw), True), "".join(vw)) - self.assertEqual(readalllines("".join(vw), False),"".join(vwo)) + for (i, lineend) in enumerate(lineends): + vw.append((i*200+200)*u"\u3042" + lineend) + vwo.append((i*200+200)*u"\u3042") + self.assertEqual(readalllines("".join(vw), True), "|".join(vw)) + self.assertEqual(readalllines("".join(vw), False), "|".join(vwo)) # Test lines where the first read might end with \r, so the # reader has to look ahead whether this is a lone \r or a \r\n for size in xrange(80): - for lineend in u"\n \r\n \r \u2028".split(): + for lineend in lineends: s = 10*(size*u"a" + lineend + u"xxx\n") reader = getreader(s) for i in xrange(10): @@ -117,12 +118,20 @@ class ReadTest(unittest.TestCase): reader.readline(keepends=True), size*u"a" + lineend, ) + self.assertEqual( + reader.readline(keepends=True), + "xxx\n", + ) reader = getreader(s) for i in xrange(10): self.assertEqual( reader.readline(keepends=False), size*u"a", ) + self.assertEqual( + reader.readline(keepends=False), + "xxx", + ) def test_mixed_readline_and_read(self): lines = ["Humpty Dumpty sat on a wall,\n", |