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) {
}
}
Aggregations