Examples of PyBuiltinCallable


Examples of org.python.core.PyBuiltinCallable

        return createBound(createExposer(methodName, returnType, args));
    }

    public static PyBuiltinCallable createBound(MethodExposer me) throws Exception {
        Class<?> descriptor = me.load(new BytecodeLoader.Loader());
        PyBuiltinCallable func = instantiate(descriptor, me.getNames()[0]);
        if (me instanceof ClassMethodExposer) {
            return func.bind(new SimpleExposed().getType());
        }
        return func.bind(new SimpleExposed());
    }
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

        assertEquals("org/python/expose/generate/SimpleExposed$simple_method_exposer",
                     mp.getInternalName());
        assertEquals("org.python.expose.generate.SimpleExposed$simple_method_exposer",
                     mp.getClassName());
        Class descriptor = mp.load(new BytecodeLoader.Loader());
        PyBuiltinCallable instance = instantiate(descriptor, "simple_method");
        assertSame("simple_method", instance.__getattr__("__name__").toString());
        SimpleExposed simpleExposed = new SimpleExposed();
        PyBuiltinCallable bound = instance.bind(simpleExposed);
        assertEquals(instance.getClass(), bound.getClass());
        assertEquals(Py.None, bound.__call__());
        assertEquals(1, simpleExposed.timesCalled);
    }
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

    public void testBooleanReturn() throws Exception {
        assertEquals(Py.False, createBound("__nonzero__", BOOLEAN).__call__());
    }

    public void testArgumentPassing() throws Exception {
        PyBuiltinCallable bound = createBound("takesArgument", Type.DOUBLE_TYPE, PYOBJ);
        assertEquals(1.0, Py.py2double(bound.__call__(Py.One)));
        try {
            bound.__call__();
            fail("Need to pass an argument to takesArgument");
        } catch (Exception e) {}
    }
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

    }

    public void testBinary() throws Exception {
        InstanceMethodExposer exposer = createExposer("__add__", PYOBJ, PYOBJ);
        exposer.type = MethodType.BINARY;
        PyBuiltinCallable bound = createBound(exposer);
        assertEquals(Py.NotImplemented, bound.__call__(Py.None));
        assertEquals(Py.One, bound.__call__(Py.False));
    }
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

    }

    public void testCmp() throws Exception {
        InstanceMethodExposer exp = createExposer("__cmp__", INT, PYOBJ);
        exp.type = MethodType.CMP;
        PyBuiltinCallable bound = createBound(exp);
        try {
            bound.__call__(Py.None);
            fail("Returning -2 from __cmp__ should yield a type error");
        } catch (PyException e) {
            if (!e.match(Py.TypeError)) {
                fail("Returning -2 from __cmp__ should yield a type error");
            }
        }
        assertEquals(Py.One, bound.__call__(Py.False));
    }
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

    }

    public void testNoneDefault() throws Exception {
        InstanceMethodExposer exp = createExposer("defaultToNone", PYOBJ, PYOBJ);
        exp.defaults = new String[] {"Py.None"};
        PyBuiltinCallable bound = createBound(exp);
        assertEquals(Py.One, bound.__call__(Py.One));
        assertEquals(Py.None, bound.__call__());
    }
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

    }

    public void testNullDefault() throws Exception {
        InstanceMethodExposer exp = createExposer("defaultToNull", PYOBJ, PYOBJ);
        exp.defaults = new String[] {"null"};
        PyBuiltinCallable bound = createBound(exp);
        assertEquals(Py.One, bound.__call__(Py.One));
        assertEquals(null, bound.__call__());
    }
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

    }

    public void testIntDefault() throws Exception {
        InstanceMethodExposer exp = createExposer("defaultToOne", PYOBJ, INT);
        exp.defaults = new String[] {"1"};
        PyBuiltinCallable bound = createBound(exp);
        assertEquals(Py.Zero, bound.__call__(Py.Zero));
        assertEquals(Py.One, bound.__call__());
        exp.defaults = new String[] {"X"};
        try {
            createBound(exp);
            fail("Shouldn't be able to create the exposer with a non-int default value");
        } catch (NumberFormatException nfe) {}
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

                                                  CHAR,
                                                  SHORT,
                                                  Type.DOUBLE_TYPE,
                                                  BYTE);
        exp.defaults = new String[] {"a", "1", "2", "3"};
        PyBuiltinCallable bound = createBound(exp);
        assertEquals("a12.03", bound.__call__().toString());
        assertEquals("b12.03", bound.__call__(Py.newString('b')).toString());
        exp.defaults = new String[] {"ab", "1", "2", "3"};
        try {
            createBound(exp);
            fail("Char should only be one character");
        } catch (InvalidExposingException iee) {}
View Full Code Here

Examples of org.python.core.PyBuiltinCallable

                                                              "fullArgs",
                                                              Type.getMethodDescriptor(Type.LONG_TYPE,
                                                                                       new Type[] {APYOBJ,
                                                                                                   ASTRING}),
                                                              "simpleexposed");
        PyBuiltinCallable bound = createBound(exp);
        assertEquals(Py.Zero, bound.__call__());
        assertEquals(Py.One, bound.__call__(Py.One));
        try {
            new InstanceMethodExposer(Type.getType(SimpleExposed.class),
                                      Opcodes.ACC_PUBLIC,
                                      "fullArgs",
                                      Type.getMethodDescriptor(PYOBJ, new Type[] {APYOBJ, ASTRING}),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.