MCPcopy Index your code
hub / github.com/python/cpython / test_readline

Method test_readline

Lib/test/test_fileinput.py:282–303  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

280 self.assertTrue(custom_open_hook.invoked, "openhook not invoked")
281
282 def test_readline(self):
283 with open(TESTFN, 'wb') as f:
284 f.write(b'A\nB\r\nC\r')
285 # Fill TextIOWrapper buffer.
286 f.write(b'123456789\n' * 1000)
287 # Issue #20501: readline() shouldn't read whole file.
288 f.write(b'\x80')
289 self.addCleanup(safe_unlink, TESTFN)
290
291 with FileInput(files=TESTFN,
292 openhook=hook_encoded('ascii')) as fi:
293 try:
294 self.assertEqual(fi.readline(), 'A\n')
295 self.assertEqual(fi.readline(), 'B\n')
296 self.assertEqual(fi.readline(), 'C\n')
297 except UnicodeDecodeError:
298 self.fail('Read to end of file')
299 with self.assertRaises(UnicodeDecodeError):
300 # Read to the end of file.
301 list(fi)
302 self.assertEqual(fi.readline(), '')
303 self.assertEqual(fi.readline(), '')
304
305 def test_readline_binary_mode(self):
306 with open(TESTFN, 'wb') as f:

Callers

nothing calls this directly

Calls 10

FileInputClass · 0.90
hook_encodedFunction · 0.90
listClass · 0.85
addCleanupMethod · 0.80
openFunction · 0.50
writeMethod · 0.45
assertEqualMethod · 0.45
readlineMethod · 0.45
failMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected