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

Function test_native_file_TextIOWrapper

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

Source from the content-addressed store, hash-verified

1425
1426
1427def test_native_file_TextIOWrapper(tmpdir):
1428 data = ('foooo\n'
1429 'barrr\n'
1430 'bazzz\n')
1431
1432 path = os.path.join(str(tmpdir), guid())
1433 with open(path, 'wb') as f:
1434 f.write(data.encode('utf-8'))
1435
1436 with TextIOWrapper(pa.OSFile(path, mode='rb')) as fil:
1437 assert fil.readable()
1438 res = fil.read()
1439 assert res == data
1440 assert fil.closed
1441
1442 with TextIOWrapper(pa.OSFile(path, mode='rb')) as fil:
1443 # Iteration works
1444 lines = list(fil)
1445 assert ''.join(lines) == data
1446
1447 # Writing
1448 path2 = os.path.join(str(tmpdir), guid())
1449 with TextIOWrapper(pa.OSFile(path2, mode='wb')) as fil:
1450 assert fil.writable()
1451 fil.write(data)
1452
1453 with TextIOWrapper(pa.OSFile(path2, mode='rb')) as fil:
1454 res = fil.read()
1455 assert res == data
1456
1457
1458def 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