[pypy-svn] r72946 - in pypy/trunk/pypy: interpreter module/posix module/posix/test
arigo at codespeak.net
arigo at codespeak.net
Sat Mar 27 13:03:57 CET 2010
Author: arigo
Date: Sat Mar 27 13:03:55 2010
New Revision: 72946
Modified:
pypy/trunk/pypy/interpreter/error.py
pypy/trunk/pypy/module/posix/interp_posix.py
pypy/trunk/pypy/module/posix/test/test_posix2.py
Log:
A function to raise OSError with the correct 'filename' attribute.
Use it in os.stat() to test it.
Modified: pypy/trunk/pypy/interpreter/error.py
==============================================================================
--- pypy/trunk/pypy/interpreter/error.py (original)
+++ pypy/trunk/pypy/interpreter/error.py Sat Mar 27 13:03:55 2010
@@ -375,3 +375,10 @@
space.wrap(msg))
return OperationError(exc, w_error)
wrap_oserror._annspecialcase_ = 'specialize:arg(2)'
+
+def wrap_oserror_filename(space, e, filename, exception_name='w_OSError'):
+ operr = wrap_oserror(space, e, exception_name)
+ space.setattr(operr.get_w_value(space), space.wrap('filename'),
+ space.wrap(filename))
+ return operr
+wrap_oserror_filename._annspecialcase_ = 'specialize:arg(2)'
Modified: pypy/trunk/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/trunk/pypy/module/posix/interp_posix.py (original)
+++ pypy/trunk/pypy/module/posix/interp_posix.py Sat Mar 27 13:03:55 2010
@@ -3,6 +3,7 @@
from pypy.rlib.rarithmetic import r_longlong
from pypy.rlib.unroll import unrolling_iterable
from pypy.interpreter.error import OperationError, wrap_oserror
+from pypy.interpreter.error import wrap_oserror_filename
from pypy.rpython.module.ll_os import RegisterOs
from pypy.rpython.module import ll_os_stat
from pypy.rpython.lltypesystem import rffi, lltype
@@ -177,7 +178,7 @@
try:
st = os.stat(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror_filename(space, e, path)
else:
return build_stat_result(space, st)
stat.unwrap_spec = [ObjSpace, str]
Modified: pypy/trunk/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/trunk/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/trunk/pypy/module/posix/test/test_posix2.py Sat Mar 27 13:03:55 2010
@@ -139,6 +139,7 @@
self.posix.stat("nonexistentdir/nonexistentfile")
except OSError, e:
assert e.errno == errno.ENOENT
+ assert e.filename == "nonexistentdir/nonexistentfile"
# On Windows, when the parent directory does not exist,
# the winerror is 3 (cannot find the path specified)
# instead of 2 (cannot find the file specified)
More information about the Pypy-commit
mailing list