[pypy-commit] pypy reflex-support: more error reporting improvements

wlav noreply at buildbot.pypy.org
Wed Jul 20 19:17:42 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r45782:99b892c7fff4
Date: 2011-07-20 10:17 -0700
http://bitbucket.org/pypy/pypy/changeset/99b892c7fff4/

Log:	more error reporting improvements

diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -142,7 +142,7 @@
         self.name = name
 
     def convert_argument(self, space, w_obj, address):
-        raise OperationError(space.w_RuntimeError,
+        raise OperationError(space.w_NotImplementedError,
                              space.wrap('no converter available for type "%s"' % self.name))
 
 
diff --git a/pypy/module/cppyy/interp_cppyy.py b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -111,7 +111,7 @@
             raise OperationError(self.space.w_TypeError,
                                  self.space.wrap("return type not handled"))
         if len(self.arg_types) < len(args_w) or len(args_w) < self.args_required:
-            raise OperationError(self.space.w_TypeError, self.space.wrap("wrong number of args"))
+            raise OperationError(self.space.w_TypeError, self.space.wrap("wrong number of arguments"))
 
         if self.methgetter and cppthis: # only for methods
             try:
@@ -261,7 +261,8 @@
                         return cppinstance  # recycle object to preserve identity
                 return cppresult
             except OperationError, e:
-                if not e.match(space, space.w_TypeError):
+                if not (e.match(space, space.w_TypeError) or \
+                        e.match(space, space.w_NotImplementedError)):
                     raise
                 errmsg += '\n\t'+str(e)
             except KeyError:
diff --git a/pypy/module/cppyy/test/fragile.h b/pypy/module/cppyy/test/fragile.h
--- a/pypy/module/cppyy/test/fragile.h
+++ b/pypy/module/cppyy/test/fragile.h
@@ -13,4 +13,19 @@
     no_such_class* gime_no_such() { return 0; }
 };
 
+class C {
+public:
+    virtual int check() { return (int)'C'; }
+    void use_no_such(no_such_class*) {}
+};
+
+class D {
+public:
+    virtual int check() { return (int)'D'; }
+    void overload() {}
+    void overload(no_such_class*) {}
+    void overload(char, int i = 0) {}  // Reflex requires a named arg
+    void overload(int, no_such_class* p = 0) {}
+};
+
 } // namespace fragile
diff --git a/pypy/module/cppyy/test/fragile.xml b/pypy/module/cppyy/test/fragile.xml
--- a/pypy/module/cppyy/test/fragile.xml
+++ b/pypy/module/cppyy/test/fragile.xml
@@ -4,5 +4,7 @@
 
   <class name="fragile::A" />
   <class name="fragile::B" />
+  <class name="fragile::C" />
+  <class name="fragile::D" />
 
 </lcgdict>
diff --git a/pypy/module/cppyy/test/test_fragile.py b/pypy/module/cppyy/test/test_fragile.py
--- a/pypy/module/cppyy/test/test_fragile.py
+++ b/pypy/module/cppyy/test/test_fragile.py
@@ -41,7 +41,27 @@
 
         raises(AttributeError, getattr, fragile, "no_such_class")
 
+        assert fragile.C == fragile.C
+        assert fragile.C().check() == ord('C')
+
         assert fragile.B == fragile.B
         assert fragile.B().check() == ord('B')
+        raises(TypeError, fragile.B().gime_no_such)
 
-        raises(NotImplementedError, fragile.B().gime_no_such)
+        assert fragile.C == fragile.C
+        assert fragile.C().check() == ord('C')
+        raises(TypeError, fragile.C().use_no_such, None)
+
+    def test03_arguments(self):
+        """Test reporting when providing wrong arguments"""
+
+        import cppyy
+
+        assert cppyy.gbl.fragile == cppyy.gbl.fragile
+        fragile = cppyy.gbl.fragile
+
+        assert fragile.D == fragile.D
+        assert fragile.D().check() == ord('D')
+
+        d = fragile.D()
+        raises(TypeError, d.overload, None)


More information about the pypy-commit mailing list