fix unit test fail

This commit is contained in:
Jeff Zhang 2016-08-08 08:40:46 +08:00
parent 3e9f1699ee
commit b48b56fbe6
3 changed files with 10 additions and 7 deletions

View file

@ -134,10 +134,11 @@ public class PythonInterpreter extends Interpreter {
InterpreterResult result;
if (pythonErrorIn(output)) {
result = new InterpreterResult(Code.ERROR, output.replaceAll(">>> ", "").trim());
result = new InterpreterResult(Code.ERROR, output);
} else {
result = new InterpreterResult(Code.SUCCESS, output.replaceAll(">>> ", "")
.replaceAll("\\.\\.\\.", "").trim());
// TODO(zjffdu), we should not do string replacement operation in the result, as it is
// possible that the output contains the kind of pattern itself, e.g. print("...")
result = new InterpreterResult(Code.SUCCESS, output.replaceAll("\\.\\.\\.", ""));
}
return result;
}

View file

@ -30,6 +30,8 @@ def intHandler(signum, frame): # Set the signal handler
raise KeyboardInterrupt()
signal.signal(signal.SIGINT, intHandler)
# set prompt as empty string so that java side don't need to remove the prompt.
sys.ps1=""
def help():
print("""%html

View file

@ -115,7 +115,7 @@ public class PythonInterpreterTest {
*/
@Test
public void testPy4jInstalled() throws IOException, InterruptedException {
when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn(">>>");
when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn("");
pythonInterpreter.open();
Integer py4jPort = pythonInterpreter.getPy4jPort();
@ -137,7 +137,7 @@ public class PythonInterpreterTest {
@Test
public void testClose() throws IOException, InterruptedException {
//given: py4j is installed
when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn(">>>");
when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn("");
pythonInterpreter.open();
Integer py4jPort = pythonInterpreter.getPy4jPort();
@ -210,11 +210,11 @@ public class PythonInterpreterTest {
String output = "";
for (int i = 0; i < lines.length; i++) {
output += ">>>" + lines[i];
output += lines[i];
}
return output;
} else {
return ">>>";
return "";
}
}