Question

I am using Marathon to test a Java Swing Application. A testing tool for Java Swing applications using Jython. Throughout the scope of this question I'm only concerned with two python files.

CallingFile.py:

    testObject = getParentOfFooJPanel(get_component('...'))
    print(testObject.getClass().getSimpleName()) #this is only here for testing
                                                 #if my code works, but this is
                                                 #where I get the errors

FileWithMethod.py

    def getParentOfFooJPanel(startingComponent):
        if (startingComponent.getClass().getSimpleName() == 'FooJPanel')

            print(startingComponent.getClass().getSimpleName()) #prints what I would expect
            print(startingComponent.getParent().getClass().getSimpleName()) #prints what I would expect
            return(startingComponent.getParent())

        else:

            getParentOfFooJPanel(startingComponent.getParent())

Whenever I try to reference the object in the FileWithMethod.py it behaves as I would expect it to. However, when I return the component(Java object) and try to use it in the CallingFile.py (for now where I call to print the simple name) it says that 'NoneType' object has no attribute 'getClass'. Can Jython not return Java objects? If not, are there any work arounds?

Était-ce utile?

La solution

Jython can definitely return Java objects. Below is an example of returning an object.

Your error most likely means some other bug in your code is returning None.

CallingFile.py:

from FileWithMethod import getStringReader
testObject = getStringReader("Hello World")
print(type(testObject))

FileWithMethod.py

import java.io.StringReader
def getStringReader(string):
    return java.io.StringReader(string)

Running it:

$ jython CallingFile.py
<type 'java.io.StringReader'>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top