| 1255 | |
| 1256 | |
| 1257 | def test_os_file_writer(tmpdir): |
| 1258 | SIZE = 4096 |
| 1259 | arr = [random.randint(0, 255) for _ in range(SIZE)] |
| 1260 | data = bytes(arr[:SIZE]) |
| 1261 | |
| 1262 | path = os.path.join(str(tmpdir), guid()) |
| 1263 | with open(path, 'wb') as f: |
| 1264 | f.write(data) |
| 1265 | |
| 1266 | # Truncates file |
| 1267 | f2 = pa.OSFile(path, mode='w') |
| 1268 | f2.write(b'foo') |
| 1269 | |
| 1270 | with pa.OSFile(path) as f3: |
| 1271 | assert f3.size() == 3 |
| 1272 | |
| 1273 | with pytest.raises(IOError): |
| 1274 | f2.read(5) |
| 1275 | f2.close() |
| 1276 | |
| 1277 | # Append |
| 1278 | with pa.OSFile(path, mode='ab') as f4: |
| 1279 | f4.write(b'bar') |
| 1280 | with pa.OSFile(path) as f5: |
| 1281 | assert f5.size() == 6 # foo + bar |
| 1282 | |
| 1283 | |
| 1284 | def test_os_file_raw_fd(tmpdir): |