Package org.python.core

Examples of org.python.core.PyDataDescr


        assertNull(se.toString());
        assertTrue(instance.implementsDescrDelete());
    }

    public void testInt() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addFieldGetter("i", INT);
                de.addFieldSetter("i", INT);
            }
        }, "i");
        assertEquals(7, instance.__get__(se, PY_TYPE).asInt());
        instance.__set__(se, Py.newInteger(12));
        assertEquals(12, instance.__get__(se, PY_TYPE).asInt());
    }
View Full Code Here


        instance.__set__(se, Py.newInteger(12));
        assertEquals(12, instance.__get__(se, PY_TYPE).asInt());
    }

    public void testByte() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addFieldGetter("b", BYTE);
                de.addMethodSetter("setB", "(B)");
            }
        }, "b");
        assertEquals(0, instance.__get__(se, PY_TYPE).asInt());
        instance.__set__(se, Py.newInteger(-1));
        assertEquals(-1, instance.__get__(se, PY_TYPE).asInt());
    }
View Full Code Here

        instance.__set__(se, Py.newInteger(-1));
        assertEquals(-1, instance.__get__(se, PY_TYPE).asInt());
    }

    public void testLong() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addMethodGetter("l", "()J");
                de.addFieldSetter("l", Type.LONG_TYPE);
            }
        }, "l");
        assertEquals(0, instance.__get__(se, PY_TYPE).asInt());
        instance.__set__(se, Py.newInteger(12));
        assertEquals(12, instance.__get__(se, PY_TYPE).asInt());
    }
View Full Code Here

        instance.__set__(se, Py.newInteger(12));
        assertEquals(12, instance.__get__(se, PY_TYPE).asInt());
    }

    public void testDouble() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addMethodGetter("getD", "()D");
                de.addMethodSetter("setD", "(D)");
            }
        }, "d");
        assertEquals(98.7, Py.py2double(instance.__get__(se, PY_TYPE)));
        instance.__set__(se, Py.newInteger(12));
        assertEquals(12.0, Py.py2double(instance.__get__(se, PY_TYPE)));
    }
View Full Code Here

        instance.__set__(se, Py.newInteger(12));
        assertEquals(12.0, Py.py2double(instance.__get__(se, PY_TYPE)));
    }

    public void testBool() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addFieldGetter("bool", BOOLEAN);
                de.addFieldSetter("bool", BOOLEAN);
            }
        }, "bool");
        assertEquals(false, Py.py2boolean(instance.__get__(se, PY_TYPE)));
        instance.__set__(se, Py.True);
        assertEquals(true, Py.py2boolean(instance.__get__(se, PY_TYPE)));
    }
View Full Code Here

    public PyDataDescr makeDescriptor(DescSetup setup, String name) throws Exception {
        DescriptorExposer de = new DescriptorExposer(ASM_TYPE, name);
        setup.setup(de);
        Class descriptor = de.load(new BytecodeLoader.Loader());
        PyDataDescr descr = (PyDataDescr)descriptor.newInstance();
        descr.setType(PY_TYPE);
        return descr;
    }
View Full Code Here

            // Should be thrown when a getter isn't added.
        }
    }

    public void testMethodGetter() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addMethodGetter("toString", RETURN_STRING_DESCRIPTOR);
            }
        });
        assertEquals(SimpleExposed.TO_STRING_RETURN, instance.__get__(se, PY_TYPE).toString());
        assertFalse(instance.implementsDescrSet());
        assertFalse(instance.implementsDescrDelete());
    }
View Full Code Here

        assertFalse(instance.implementsDescrSet());
        assertFalse(instance.implementsDescrDelete());
    }

    public void testFieldGetter() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addFieldGetter("toStringVal", STRING);
            }
        });
        assertEquals(SimpleExposed.TO_STRING_RETURN, instance.__get__(new DescExposed(), PY_TYPE)
                .toString());
        assertFalse(instance.implementsDescrSet());
        assertFalse(instance.implementsDescrDelete());
    }
View Full Code Here

        assertFalse(instance.implementsDescrSet());
        assertFalse(instance.implementsDescrDelete());
    }
   
    public void testNullReturns() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addFieldGetter("nullString", STRING);
            }
        });
        assertEquals(Py.None, instance.__get__(se, PY_TYPE));
    }
View Full Code Here

        });
        assertEquals(Py.None, instance.__get__(se, PY_TYPE));
    }

    public void testMethodSetter() throws Exception {
        PyDataDescr instance = makeDescriptor(new DescSetup() {

            public void setup(DescriptorExposer de) {
                de.addMethodGetter("toString", RETURN_STRING_DESCRIPTOR);
                de.addMethodSetter("setToString", "(Ljava/lang/String;)V");
            }
        });
        instance.__set__(se, Py.newString(NEW_VAL));
        assertEquals(NEW_VAL, se.toString());
        assertTrue(instance.implementsDescrSet());
        assertFalse(instance.implementsDescrDelete());
    }
View Full Code Here

TOP

Related Classes of org.python.core.PyDataDescr

Copyright © 2018 www.massapicom. 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.