Search in sources :

Example 1 with CompileMode

use of org.python.core.CompileMode in project scisoft-core by DawnScience.

the class PythonUtilsTest method testCompile.

private void testCompile(boolean isSingle) throws Exception {
    // NB "eval" is not available in Jython nor documented in CPython
    CompileMode mode = isSingle ? CompileMode.single : CompileMode.exec;
    String filename = "<input>";
    CompilerFlags flags = new CompilerFlags();
    PyObject ret = Py.compile_command_flags("", filename, mode, flags, false);
    System.out.println(ret);
    ret = Py.compile_command_flags("1", filename, mode, flags, false);
    System.out.println(ret);
    ret = Py.compile_command_flags("print 2", filename, mode, flags, false);
    System.out.println(ret);
    ret = Py.compile_command_flags("if True: print 42", filename, mode, flags, false);
    if (isSingle) {
        assertEquals(Py.None, ret);
    }
    System.out.println(ret);
    try {
        ret = Py.compile_command_flags("if True:", filename, mode, flags, false);
        if (isSingle) {
            assertEquals(Py.None, ret);
        } else {
            fail();
        }
        System.out.println(ret);
    } catch (Exception e) {
    }
}
Also used : CompileMode(org.python.core.CompileMode) CompilerFlags(org.python.core.CompilerFlags) PyObject(org.python.core.PyObject) DatasetException(org.eclipse.january.DatasetException)

Aggregations

DatasetException (org.eclipse.january.DatasetException)1 CompileMode (org.python.core.CompileMode)1 CompilerFlags (org.python.core.CompilerFlags)1 PyObject (org.python.core.PyObject)1