diff options
author | Walter Dörwald <walter@livinglogic.de> | 2006-03-06 22:39:12 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2006-03-06 22:39:12 (GMT) |
commit | ca199432c23fa00ab3702e64a136c377950e5068 (patch) | |
tree | d46c22940fbd7bca5c5913cdda3f501ce26ffb37 /Lib/test/test_codecs.py | |
parent | f8d767198f11ab1011164d907de8332138162d94 (diff) | |
download | cpython-ca199432c23fa00ab3702e64a136c377950e5068.zip cpython-ca199432c23fa00ab3702e64a136c377950e5068.tar.gz cpython-ca199432c23fa00ab3702e64a136c377950e5068.tar.bz2 |
If size is specified, try to read at least size characters.
This is a alternative version of patch #1379332.
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r-- | Lib/test/test_codecs.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index ded5d19..3944d65 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -46,19 +46,23 @@ class ReadTest(unittest.TestCase): stream = StringIO.StringIO(input.encode(self.encoding)) return codecs.getreader(self.encoding)(stream) - def readalllines(input, keepends=True): + def readalllines(input, keepends=True, size=None): reader = getreader(input) lines = [] while True: - line = reader.readline(keepends=keepends) + line = reader.readline(size=size, keepends=keepends) if not line: break lines.append(line) - return "".join(lines) + return "|".join(lines) s = u"foo\nbar\r\nbaz\rspam\u2028eggs" - self.assertEqual(readalllines(s, True), s) - self.assertEqual(readalllines(s, False), u"foobarbazspameggs") + sexpected = u"foo\n|bar\r\n|baz\r|spam\u2028|eggs" + sexpectednoends = u"foo|bar|baz|spam|eggs" + self.assertEqual(readalllines(s, True), sexpected) + self.assertEqual(readalllines(s, False), sexpectednoends) + self.assertEqual(readalllines(s, True, 10), sexpected) + self.assertEqual(readalllines(s, False, 10), sexpectednoends) # Test long lines (multiple calls to read() in readline()) vw = [] |