[pypy-svn] r49489 - in pypy/branch/clr-module-improvements/pypy/module/clr: . test

antocuni at codespeak.net antocuni at codespeak.net
Fri Dec 7 00:19:09 CET 2007


Author: antocuni
Date: Fri Dec  7 00:19:08 2007
New Revision: 49489

Modified:
   pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py
   pypy/branch/clr-module-improvements/pypy/module/clr/test/test_clr.py
Log:
don't crash if the type cannot be found



Modified: pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py	(original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py	Fri Dec  7 00:19:08 2007
@@ -206,14 +206,15 @@
 
 def build_cli_class(space, namespace, classname, fullname):
     b_type = System.Type.GetType(fullname)
-    hasIEnumerable = 0      # flag 
+    if b_type is None:
+        raise OperationError(space.w_ImportError, space.wrap("Cannot load .NET type: %s" % fullname))
 
     # this is where we locate the interfaces inherited by the class
     # set the flag hasIEnumerable if IEnumerable interface has been by the class
-    ifaces = b_type.GetInterfaces()
-    for interface in ifaces:
+    hasIEnumerable = False
+    for interface in b_type.GetInterfaces(i):
         if interface.ToString() == "System.Collections.IEnumerable":
-            hasIEnumerable = 1 
+            hasIEnumerable = True
 
     w_staticmethods, w_methods = get_methods(space, b_type)
     w_properties, w_indexers = get_properties(space, b_type)

Modified: pypy/branch/clr-module-improvements/pypy/module/clr/test/test_clr.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/test/test_clr.py	(original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/test/test_clr.py	Fri Dec  7 00:19:08 2007
@@ -17,6 +17,10 @@
         ArrayList2 = clr.load_cli_class('System.Collections', 'ArrayList')
         assert ArrayList is ArrayList2
 
+    def test_load_fail(self):
+        import clr
+        raises(ImportError, clr.load_cli_class, 'Foo', 'Bar')
+        
     def test_ArrayList(self):
         import clr
         ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
@@ -181,10 +185,3 @@
             sum += i
         assert sum == 1+54+21
 
-
-
-
-
-
-
-


More information about the pypy-svn mailing list