(self)
| 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: |
nothing calls this directly
no test coverage detected