| 1481 | |
| 1482 | |
| 1483 | def test_native_file_read1(tmpdir): |
| 1484 | # ARROW-16272: read1() should not exhaust the input stream if there |
| 1485 | # is a large amount of data remaining. |
| 1486 | data = b'123\n' * 1_000_000 |
| 1487 | path = str(tmpdir / 'largefile.txt') |
| 1488 | with open(path, 'wb') as f: |
| 1489 | f.write(data) |
| 1490 | |
| 1491 | chunks = [] |
| 1492 | with pa.OSFile(path, mode='rb') as f: |
| 1493 | while True: |
| 1494 | b = f.read1() |
| 1495 | assert len(b) < len(data) |
| 1496 | chunks.append(b) |
| 1497 | b = f.read1(30_000) |
| 1498 | assert len(b) <= 30_000 |
| 1499 | chunks.append(b) |
| 1500 | if not b: |
| 1501 | break |
| 1502 | |
| 1503 | assert b"".join(chunks) == data |
| 1504 | |
| 1505 | |
| 1506 | @pytest.mark.pandas |