Search in sources :

Example 6 with JepPythonTestContext

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)));
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) JepPythonTestContext(org.apache.apex.malhar.python.test.JepPythonTestContext) Test(org.junit.Test)

Aggregations

JepPythonTestContext (org.apache.apex.malhar.python.test.JepPythonTestContext)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Attribute (com.datatorrent.api.Attribute)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 Random (java.util.Random)1 EmbeddedAppLauncher (org.apache.apex.api.EmbeddedAppLauncher)1 Launcher (org.apache.apex.api.Launcher)1 EvalCommandRequestPayload (org.apache.apex.malhar.python.base.requestresponse.EvalCommandRequestPayload)1 MethodCallRequestPayload (org.apache.apex.malhar.python.base.requestresponse.MethodCallRequestPayload)1 Configuration (org.apache.hadoop.conf.Configuration)1