use of org.apache.apex.malhar.python.test.JepPythonTestContext in project apex-malhar by apache.
the class InterpreterThreadTest method testRunCommands.
@JepPythonTestContext(jepPythonBasedTest = true)
@Test
public void testRunCommands() throws Exception {
long currentTime = System.currentTimeMillis();
File tempFile = File.createTempFile("apexpythonunittestruncommands-", ".txt");
tempFile.deleteOnExit();
String filePath = tempFile.getAbsolutePath();
assertEquals(0L, tempFile.length());
List<String> commands = new ArrayList();
commands.add("fileHandle = open('" + filePath + "', 'w')");
commands.add("fileHandle.write('" + currentTime + "')");
commands.add("fileHandle.flush()");
commands.add("fileHandle.close()");
runCommands(commands);
assertEquals(("" + currentTime).length(), tempFile.length());
List<String> errorCommands = new ArrayList();
errorCommands.add("1+2");
errorCommands.add("3+");
PythonRequestResponse<Void> response = runCommands(errorCommands);
Map<String, Boolean> responseStatus = response.getPythonInterpreterResponse().getCommandStatus();
assertTrue(responseStatus.get(errorCommands.get(0)));
assertFalse(responseStatus.get(errorCommands.get(1)));
}
Aggregations