Author: Armin Rigo <[email protected]>
Branch: py3k
Changeset: r86395:daf7eb91064e
Date: 2016-08-22 10:15 +0200
http://bitbucket.org/pypy/pypy/changeset/daf7eb91064e/
Log: Test and fix for os.listdir(fd)
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
@@ -872,9 +872,9 @@
"argument should be string, bytes or integer, not %T", w_path)
fd = unwrap_fd(space, w_path)
try:
- result = rposix.fdlistdir(fd)
+ result = rposix.fdlistdir(os.dup(fd))
except OSError as e:
- raise wrap_oserror2(space, e, w_path)
+ raise wrap_oserror(space, e)
else:
dirname = FileEncoder(space, w_path)
try:
diff --git a/pypy/module/posix/test/test_posix2.py
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -325,6 +325,17 @@
expected = b'caf%E9' if sys.platform == 'darwin' else b'caf\xe9'
assert expected in result
+ def test_fdlistdir(self):
+ posix = self.posix
+ dirfd = posix.open('.', posix.O_RDONLY)
+ lst1 = posix.listdir(dirfd) # does not close dirfd
+ lst2 = posix.listdir('.')
+ assert lst1 == lst2
+ #
+ lst3 = posix.listdir(dirfd) # rewinddir() was used
+ assert lst3 == lst1
+ posix.close(dirfd)
+
def test_undecodable_filename(self):
import sys
posix = self.posix
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit