tests.java.org.python.expose.generate.NewExposerTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython Show documentation
Show all versions of jython Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
package org.python.expose.generate;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.python.core.BytecodeLoader;
import org.python.core.Py;
import org.python.core.PyNewWrapper;
import org.python.core.PyObject;
import org.python.core.PyType;
import org.python.expose.ExposedType;
public class NewExposerTest extends InterpTestCase implements Opcodes {
public void testSimple() throws Exception {
NewExposer ne = new NewExposer(Type.getType(Instantiable.class),
ACC_STATIC | ACC_PUBLIC,
"creator",
NewExposer.NEW_DESCRIPTOR,
new String[] {});
assertEquals("org/python/expose/generate/NewExposerTest$Instantiable$exposed___new__",
ne.getInternalName());
assertEquals("org.python.expose.generate.NewExposerTest$Instantiable$exposed___new__",
ne.getClassName());
Class descriptor = ne.load(new BytecodeLoader.Loader());
PyNewWrapper instance = (PyNewWrapper)descriptor.getDeclaredConstructor().newInstance();
instance.setWrappedType(PyType.fromClass(Instantiable.class));
assertSame("__new__", instance.__getattr__("__name__").toString());
assertEquals(Py.One, instance.__call__(PyType.fromClass(Instantiable.class)));
}
@ExposedType()
public static class Instantiable extends PyObject {
public static PyObject creator(PyNewWrapper new_,
boolean init,
PyType subtype,
PyObject[] args,
String[] keywords) {
return Py.One;
}
}
}