Revision: 444
          http://rpy.svn.sourceforge.net/rpy/?rev=444&view=rev
Author:   lgautier
Date:     2008-03-15 14:29:39 -0700 (Sat, 15 Mar 2008)

Log Message:
-----------
- Use R-1.7's R_has_slot
- Unit test (to cover its use)

Modified Paths:
--------------
    branches/rpy_nextgen/rpy/rinterface/rinterface.c
    branches/rpy_nextgen/rpy/rinterface/tests/test_Sexp.py

Modified: branches/rpy_nextgen/rpy/rinterface/rinterface.c
===================================================================
--- branches/rpy_nextgen/rpy/rinterface/rinterface.c    2008-03-15 19:01:08 UTC 
(rev 443)
+++ branches/rpy_nextgen/rpy/rinterface/rinterface.c    2008-03-15 21:29:39 UTC 
(rev 444)
@@ -291,6 +291,10 @@
 "\n\
 Returns the R internal SEXPREC type.");
 
+/*FIXME: own definition. It should probably be in one of
+  R's includes*/
+extern int R_has_slot(SEXP obj, SEXP name);
+
 static PyObject*
 Sexp_do_slot(PyObject *self, PyObject *name)
 {
@@ -304,12 +308,13 @@
     return NULL;
   }
   char *name_str = PyString_AS_STRING(name);
+
+  if (! R_has_slot(sexp, install(name_str))) {
+    PyErr_SetString(PyExc_LookupError, "The object has no such attribute.");
+    return NULL;
+  }
   SEXP res_R = GET_SLOT(sexp, install(name_str));
-  if (!res_R) {
-    PyErr_Format(PyExc_ValueError, "R Error.");
-    return NULL;;
-  }
-  
+
   PyObject *res = (PyObject *)newSexpObject(res_R);
   return res;
 }

Modified: branches/rpy_nextgen/rpy/rinterface/tests/test_Sexp.py
===================================================================
--- branches/rpy_nextgen/rpy/rinterface/tests/test_Sexp.py      2008-03-15 
19:01:08 UTC (rev 443)
+++ branches/rpy_nextgen/rpy/rinterface/tests/test_Sexp.py      2008-03-15 
21:29:39 UTC (rev 444)
@@ -33,7 +33,7 @@
         for i, n in enumerate(iris_names):
             self.assertEquals(iris_names[i], names[i])
 
-        missing = sexp.do_slot("foo")       
+        self.assertRaises(LookupError, sexp.do_slot, "foo")       
 
 if __name__ == '__main__':
      unittest.main()


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to