| 1282 | |
| 1283 | |
| 1284 | def test_os_file_raw_fd(tmpdir): |
| 1285 | path = os.path.join(str(tmpdir), guid()) |
| 1286 | binary_flag = getattr(os, "O_BINARY", 0) |
| 1287 | |
| 1288 | fd = os.open(path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC | binary_flag, |
| 1289 | 0o666) |
| 1290 | with pa.OSFile(fd, mode='wb') as f: |
| 1291 | assert f.fileno() == fd |
| 1292 | f.write(b'foo') |
| 1293 | |
| 1294 | with pytest.raises(OSError) as exc: |
| 1295 | os.fstat(fd) |
| 1296 | assert exc.value.errno == errno.EBADF |
| 1297 | |
| 1298 | fd = os.open(path, os.O_RDONLY | binary_flag) |
| 1299 | with pa.OSFile(fd, mode='rb') as f: |
| 1300 | assert f.fileno() == fd |
| 1301 | assert f.read() == b'foo' |
| 1302 | |
| 1303 | with pytest.raises(OSError) as exc: |
| 1304 | os.fstat(fd) |
| 1305 | assert exc.value.errno == errno.EBADF |
| 1306 | |
| 1307 | |
| 1308 | def test_native_file_write_reject_unicode(): |