MCPcopy Create free account
hub / github.com/apache/arrow / test_native_file_TextIOWrapper

Function test_native_file_TextIOWrapper

python/pyarrow/tests/test_io.py:1435–1463  ·  view source on GitHub ↗
(tmpdir)

Source from the content-addressed store, hash-verified

1433
1434
1435def 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
1466def test_native_file_TextIOWrapper_perf(tmpdir):

Callers

nothing calls this directly

Calls 7

guidFunction · 0.90
listFunction · 0.85
writableMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45
encodeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected