[pypy-svn] r69230 - in pypy/branch/faster-raise/pypy/module/exceptions: . test

afa at codespeak.net afa at codespeak.net
Thu Nov 12 15:08:58 CET 2009


Author: afa
Date: Thu Nov 12 15:08:57 2009
New Revision: 69230

Modified:
   pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py
   pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
Log:
Test and fix for WindowsError


Modified: pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py
==============================================================================
--- pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py	(original)
+++ pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py	Thu Nov 12 15:08:57 2009
@@ -283,20 +283,17 @@
             self.args_w = [args_w[0], args_w[1]]
 
     def descr_str(self, space):
-        return self.str(space, self.w_errno)
-    descr_str.unwrap_spec = ['self', ObjSpace]
-
-    def str(self, space, w_errno):    # for WindowsError
-        if (not space.is_w(w_errno, space.w_None) and
+        if (not space.is_w(self.w_errno, space.w_None) and
             not space.is_w(self.w_strerror, space.w_None)):
             if not space.is_w(self.w_filename, space.w_None):
                 return space.wrap("[Errno %d] %s: %s" % (
-                    space.int_w(w_errno),
+                    space.int_w(self.w_errno),
                     space.str_w(self.w_strerror),
                     space.str_w(self.w_filename)))
-            return space.wrap("[Errno %d] %s" % (space.int_w(w_errno),
+            return space.wrap("[Errno %d] %s" % (space.int_w(self.w_errno),
                                                  space.str_w(self.w_strerror)))
         return W_BaseException.descr_str(self, space)
+    descr_str.unwrap_spec = ['self', ObjSpace]
 
 W_EnvironmentError.typedef = TypeDef(
     'EnvironmentError',
@@ -329,7 +326,16 @@
         self.w_errno = space.wrap(errno)
 
     def descr_str(self, space):
-        return self.str(space, self.w_winerror)
+        if (not space.is_w(self.w_winerror, space.w_None) and
+            not space.is_w(self.w_strerror, space.w_None)):
+            if not space.is_w(self.w_filename, space.w_None):
+                return space.wrap("[Error %d] %s: %s" % (
+                    space.int_w(self.w_winerror),
+                    space.str_w(self.w_strerror),
+                    space.str_w(self.w_filename)))
+            return space.wrap("[Error %d] %s" % (space.int_w(self.w_winerror),
+                                                 space.str_w(self.w_strerror)))
+        return W_BaseException.descr_str(self, space)
     descr_str.unwrap_spec = ['self', ObjSpace]
 
     # copied from CPython: PC/errmap.h

Modified: pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
==============================================================================
--- pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py	(original)
+++ pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py	Thu Nov 12 15:08:57 2009
@@ -76,6 +76,18 @@
         assert ee.filename == "y"
         assert EnvironmentError(3, "x").filename is None
 
+    def test_windows_error(self):
+        try:
+            from exceptions import WindowsError
+        except ImportError:
+            skip('WindowsError not present')
+        ee = WindowsError(3, "x", "y")
+        assert str(ee) == "[Error 3] x: y"
+        # winerror=3 (ERROR_PATH_NOT_FOUND) maps to errno=2 (ENOENT)
+        assert ee.winerror == 3
+        assert ee.errno == 2
+        assert str(WindowsError(3, "x")) == "[Error 3] x"
+
     def test_syntax_error(self):
         from exceptions import SyntaxError
         s = SyntaxError(3)



More information about the Pypy-commit mailing list