| 1433 | |
| 1434 | |
| 1435 | def test_native_file_TextIOWrapper(tmpdir): |
| 1436 | data = ('foooo\n' |
| 1437 | 'barrr\n' |
| 1438 | 'bazzz\n') |
| 1439 | |
| 1440 | path = os.path.join(str(tmpdir), guid()) |
| 1441 | with open(path, 'wb') as f: |
| 1442 | f.write(data.encode('utf-8')) |
| 1443 | |
| 1444 | with TextIOWrapper(pa.OSFile(path, mode='rb')) as fil: |
| 1445 | assert fil.readable() |
| 1446 | res = fil.read() |
| 1447 | assert res == data |
| 1448 | assert fil.closed |
| 1449 | |
| 1450 | with TextIOWrapper(pa.OSFile(path, mode='rb')) as fil: |
| 1451 | # Iteration works |
| 1452 | lines = list(fil) |
| 1453 | assert ''.join(lines) == data |
| 1454 | |
| 1455 | # Writing |
| 1456 | path2 = os.path.join(str(tmpdir), guid()) |
| 1457 | with TextIOWrapper(pa.OSFile(path2, mode='wb')) as fil: |
| 1458 | assert fil.writable() |
| 1459 | fil.write(data) |
| 1460 | |
| 1461 | with TextIOWrapper(pa.OSFile(path2, mode='rb')) as fil: |
| 1462 | res = fil.read() |
| 1463 | assert res == data |
| 1464 | |
| 1465 | |
| 1466 | def test_native_file_TextIOWrapper_perf(tmpdir): |