use of org.python.core.PyObject in project gda-core by openGDA.
the class ScannableMotionWithScannableFieldsBaseTest method testGetFieldPositionWithPyArray.
@Test
public void testGetFieldPositionWithPyArray() throws Exception {
PyObject[] position = new PyObject[] { new PyFloat(0.), new PyInteger(1), new PyFloat(2.), new PyInteger(3) };
doReturn(position).when(scn).rawGetPosition();
assertEquals(new PyFloat(0.), scn.getFieldPosition(0));
assertEquals(new PyInteger(1), scn.getFieldPosition(1));
assertEquals(new PyFloat(2.), scn.getFieldPosition(2));
assertEquals(new PyInteger(3), scn.getFieldPosition(3));
}
use of org.python.core.PyObject in project gda-core by openGDA.
the class ScannableSnapshotTest method testJythonScannableInitialization.
@Test
public void testJythonScannableInitialization() throws Exception {
PyFloat flt = new PyFloat(100.);
PyString str = new PyString("test");
PyList listOutput = new PyList(new PyObject[] { flt, str });
Scannable jscn = generateMockScannable("jscn", new String[] { "in" }, new String[] { "extra" }, new String[] { "%5.5g", "%s" }, false, "", listOutput);
ScannableSnapshot s = new ScannableSnapshot(jscn);
assertEquals("jscn", s.name);
assertArrayEquals(new String[] { "in" }, s.inputNames);
assertArrayEquals(new String[] { "extra" }, s.extraNames);
assertArrayEquals(new String[] { "%5.5g", "%s" }, s.outputFormat);
assertArrayEquals(new String[] { "", "" }, s.units);
assertEquals(false, s.busy);
assertArrayEquals(new Object[] { 100., "test" }, (Object[]) s.lastPosition);
PyTuple tupleOutput = new PyTuple(new PyObject[] { flt, str });
jscn = generateMockScannable("jscn", new String[] { "in" }, new String[] { "extra" }, new String[] { "%5.5g", "%s" }, false, "", tupleOutput);
s = new ScannableSnapshot(jscn);
assertArrayEquals(new Object[] { 100., "test" }, (Object[]) s.lastPosition);
}
use of org.python.core.PyObject in project gda-core by openGDA.
the class GdaBuiltinTest method testOverloadedDocString.
@Test
public void testOverloadedDocString() throws Exception {
PyObject foo = builtinFor(Commands.class, "foo");
String docs = "Foo strings\n\n" + "foo(String)\n" + " Foo a single String\n" + "foo(String, String) -> String\n" + " Foo two strings into one\n" + "\n" + "from gda.jython.GdaBuiltinTest.Commands";
assertThat(foo.__getattr__("__doc__").toString(), is(docs));
}
use of org.python.core.PyObject in project gda-core by openGDA.
the class GdaBuiltinTest method correctFunctionIsCalled.
@Test
public void correctFunctionIsCalled() throws Exception {
GdaBuiltin foo = builtinFor(Commands.class, "foo");
PyObject first = foo.__call__(Py.java2py("helloWorld"));
// void methods return None
assertThat(first, is(Py.None));
PyObject second = foo.__call__(Py.javas2pys("hello", "World"));
// return as jython object
assertThat(second, is(Py.java2py("helloWorld")));
}
use of org.python.core.PyObject in project bowler-script-kernel by CommonWealthRobotics.
the class JythonHelper method inlineScriptRun.
@Override
public Object inlineScriptRun(String code, ArrayList<Object> args) {
Properties props = new Properties();
PythonInterpreter.initialize(System.getProperties(), props, new String[] { "" });
if (interp == null) {
interp = new PythonInterpreter();
interp.exec("import sys");
}
for (String pm : DeviceManager.listConnectedDevice(null)) {
BowlerAbstractDevice bad = DeviceManager.getSpecificDevice(null, pm);
// passing into the scipt
try {
interp.set(bad.getScriptingName(), Class.forName(bad.getClass().getName()).cast(bad));
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.err.println("Device " + bad.getScriptingName() + " is " + bad);
}
interp.set("args", args);
interp.exec(code);
ArrayList<Object> results = new ArrayList<>();
PyObject localVariables = interp.getLocals();
try {
results.add(interp.get("csg", CSG.class));
} catch (Exception e) {
e.printStackTrace();
}
try {
results.add(interp.get("tab", Tab.class));
} catch (Exception e) {
e.printStackTrace();
}
try {
results.add(interp.get("device", BowlerAbstractDevice.class));
} catch (Exception e) {
e.printStackTrace();
}
Log.debug("Jython return = " + results);
return results;
}
Aggregations