[pypy-commit] pypy jumbo: rposix tests for pread/pwrite
nanjekye
pypy.commits at gmail.com
Mon Mar 13 12:30:49 EDT 2017
Author: Joannah Nanjekye <nanjekyejoannah at gmail.com>
Branch: jumbo
Changeset: r90656:459d7473aca8
Date: 2017-03-08 12:37 +0300
http://bitbucket.org/pypy/pypy/changeset/459d7473aca8/
Log: rposix tests for pread/pwrite
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -384,7 +384,7 @@
try:
s = rposix.pread(fd, length, offset)
except OSError as e:
- raise wrap_oserror(space, e, eintr_retry=True)
+ raise wrap_oserror(space, e, eintr_retry=False)
else:
return space.newbytes(s)
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -471,7 +471,6 @@
[rffi.INT, rffi.VOIDP, rffi.SIZE_T, OFF_T], rffi.SSIZE_T,
save_err=rffi.RFFI_SAVE_ERRNO)
- at replace_os_function('pread')
@enforceargs(int, int, None)
def pread(fd, count, offset):
if count < 0:
@@ -481,7 +480,6 @@
void_buf = rffi.cast(rffi.VOIDP, buf.raw)
return buf.str(handle_posix_error('pread', c_pread(fd, void_buf, count, offset)))
- at replace_os_function('pwrite')
@enforceargs(int, None, None)
def pwrite(fd, data, offset):
count = len(data)
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -676,3 +676,30 @@
prio = rposix.getpriority(rposix.PRIO_PROCESS, 0)
rposix.setpriority(rposix.PRIO_PROCESS, 0, prio)
py.test.raises(OSError, rposix.getpriority, rposix.PRIO_PGRP, 123456789)
+
+ at rposix_requires('pread')
+def test_pread():
+ fname = str(udir.join('os_test.txt'))
+ fd = os.open(fname, os.O_RDWR | os.O_CREAT)
+ try:
+ assert fd >= 0
+ os.write(fd, b'Hello world')
+ os.lseek(fd, 0, 0)
+ assert rposix.pread(fd, 2, 1) == b'el'
+ finally:
+ os.close(fd)
+ py.test.raises(OSError, rposix.pread, fd, 2, 1)
+
+ at rposix_requires('pwrite')
+def test_pwrite():
+ fname = str(udir.join('os_test.txt'))
+ fd = os.open(fname, os.O_RDWR | os.O_CREAT, 0777)
+ try:
+ assert fd >= 0
+ os.write(fd, b'Hello world')
+ os.lseek(fd, 0, 0)
+ rposix.pwrite(fd, b'ea', 1)
+ assert os.read(fd, 4) == b'Heal'
+ finally:
+ os.close(fd)
+ py.test.raises(OSError, rposix.pwrite, fd, b'ea', 1)
More information about the pypy-commit
mailing list