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