Revision: 4074
Author: pekka.klarck
Date: Sun Sep 19 03:55:41 2010
Log: Needed to change the algorithm to validate handlers because inspect.isroutine works correctly with methods from java classes starting from Jython 2.5.2. With this fix all tests passed with Jython 2.5.2 on my machine, except for the one that fails also with 2.5.1 after my previous commit...
http://code.google.com/p/robotframework/source/detail?r=4074

Modified:
 /trunk/src/robot/running/testlibraries.py

=======================================
--- /trunk/src/robot/running/testlibraries.py   Sat Sep 18 16:36:48 2010
+++ /trunk/src/robot/running/testlibraries.py   Sun Sep 19 03:55:41 2010
@@ -225,19 +225,31 @@
         raise TypeError('Not a method or function')

     def _is_valid_handler(self, handler):
-        if inspect.isroutine(handler):
-            return True
- if not (utils.is_jython and isinstance(handler, PyReflectedFunction)):
+        if not utils.is_jython:
+            return inspect.isroutine(handler)
+        return self._is_jython_method(handler) \
+            and not self._is_implicit_java_method(handler)
+
+    def _is_jython_method(self, handler):
+        # inspect.isroutine doesn't work with methods from Java classes
+        # prior to Jython 2.5.2: http://bugs.jython.org/issue1223
+        return inspect.isroutine(handler) \
+            or isinstance(handler, PyReflectedFunction)
+
+    def _is_implicit_java_method(self, handler):
+        if not self._is_created_in_java(handler):
             return False
-        # When we get here, the handler is created in a Java class possibly
-        # extended in Python. This code ignores handlers defined only in
-        # java.lang.Object or generated by Jython (in org.python.proxies).
         for signature in handler.argslist[:handler.nargs]:
             cls = signature.declaringClass
-            if not (cls is Object or
-                    cls.__name__.startswith('org.python.proxies.')):
-                return True
-        return False
+            if not (cls is Object or self._is_created_by_jython(cls)):
+                return False
+        return True
+
+    def _is_created_in_java(self, handler):
+        return hasattr(handler, 'argslist')
+
+    def _is_created_by_jython(self, cls):
+        return cls.__name__.startswith('org.python.proxies.')


 class _ModuleLibrary(_BaseTestLibrary):

Reply via email to