@@ -175,6 +175,40 @@ def readalllines(input, keepends=True, size=None):
175175 size * "a" ,
176176 )
177177
178+ def test_mixed_readline_and_read (self ):
179+ lines = ["Humpty Dumpty sat on a wall,\n " ,
180+ "Humpty Dumpty had a great fall.\r \n " ,
181+ "All the king's horses and all the king's men\r " ,
182+ "Couldn't put Humpty together again." ]
183+ data = '' .join (lines )
184+ def getreader ():
185+ stream = io .BytesIO (data .encode (self .encoding ))
186+ return codecs .getreader (self .encoding )(stream )
187+
188+ # Issue #8260: Test readline() followed by read()
189+ f = getreader ()
190+ self .assertEqual (f .readline (), lines [0 ])
191+ self .assertEqual (f .read (), '' .join (lines [1 :]))
192+ self .assertEqual (f .read (), '' )
193+
194+ # Issue #16636: Test readline() followed by readlines()
195+ f = getreader ()
196+ self .assertEqual (f .readline (), lines [0 ])
197+ self .assertEqual (f .readlines (), lines [1 :])
198+ self .assertEqual (f .read (), '' )
199+
200+ # Test read() followed by read()
201+ f = getreader ()
202+ self .assertEqual (f .read (size = 40 , chars = 5 ), data [:5 ])
203+ self .assertEqual (f .read (), data [5 :])
204+ self .assertEqual (f .read (), '' )
205+
206+ # Issue #12446: Test read() followed by readlines()
207+ f = getreader ()
208+ self .assertEqual (f .read (size = 40 , chars = 5 ), data [:5 ])
209+ self .assertEqual (f .readlines (), [lines [0 ][5 :]] + lines [1 :])
210+ self .assertEqual (f .read (), '' )
211+
178212 def test_bug1175396 (self ):
179213 s = [
180214 '<%!--===================================================\r \n ' ,
@@ -2370,8 +2404,6 @@ def test_read(self):
23702404
23712405 def test_readline (self ):
23722406 for encoding in bytes_transform_encodings :
2373- if encoding in ['uu_codec' , 'zlib_codec' ]:
2374- continue
23752407 with self .subTest (encoding = encoding ):
23762408 sin = codecs .encode (b"\x80 " , encoding )
23772409 reader = codecs .getreader (encoding )(io .BytesIO (sin ))
0 commit comments