"));
+ assertEquals(new String(out.getOutputAt(0).toByteArray()), InterpreterResult.Code.SUCCESS, ret.code());
+ assertEquals(new String(out.getOutputAt(0).toByteArray()), InterpreterResult.Type.TEXT, out.getOutputAt(0).getType());
+ assertEquals(new String(out.getOutputAt(1).toByteArray()), InterpreterResult.Type.HTML, out.getOutputAt(1).getType());
+ assertTrue(new String(out.getOutputAt(1).toByteArray()).contains("data:image/png;base64"));
+ assertTrue(new String(out.getOutputAt(1).toByteArray()).contains("
"));
}
@Test
// Test for when configuration is set to auto-close figures after show().
- public void testClose() {
+ public void testClose() throws IOException {
InterpreterResult ret;
InterpreterResult ret1;
InterpreterResult ret2;
@@ -116,25 +118,33 @@ public void testClose() {
ret = python.interpret("z.configure_mpl(interactive=False)", context);
ret = python.interpret("plt.plot([1, 2, 3])", context);
ret1 = python.interpret("plt.show()", context);
-
+
// Second call to show() should print nothing, and Type should be TEXT.
// This is because when close=True, there should be no living instances
// of FigureManager, causing show() to return before setting the output
// type to HTML.
ret = python.interpret("plt.show()", context);
+
+ assertEquals(new String(out.getOutputAt(0).toByteArray()), InterpreterResult.Code.SUCCESS, ret.code());
assertEquals(0, ret.message().size());
-
+
// Now test that new plot is drawn. It should be identical to the
// previous one.
ret = python.interpret("plt.plot([1, 2, 3])", context);
+ String msg1 = new String(out.getOutputAt(0).toByteArray());
+ InterpreterResult.Type type1 = out.getOutputAt(0).getType();
+
ret2 = python.interpret("plt.show()", context);
- assertEquals(ret1.message().get(0).getType(), ret2.message().get(0).getType());
- assertEquals(ret1.message().get(0).getData(), ret2.message().get(0).getData());
+ String msg2 = new String(out.getOutputAt(0).toByteArray());
+ InterpreterResult.Type type2 = out.getOutputAt(0).getType();
+
+ assertEquals(msg1, msg2);
+ assertEquals(type1, type2);
}
-
+
@Test
// Test for when configuration is set to not auto-close figures after show().
- public void testNoClose() {
+ public void testNoClose() throws IOException {
InterpreterResult ret;
InterpreterResult ret1;
InterpreterResult ret2;
@@ -142,19 +152,39 @@ public void testNoClose() {
ret = python.interpret("z.configure_mpl(interactive=False, close=False)", context);
ret = python.interpret("plt.plot([1, 2, 3])", context);
ret1 = python.interpret("plt.show()", context);
-
+
// Second call to show() should print nothing, and Type should be HTML.
// This is because when close=False, there should be living instances
// of FigureManager, causing show() to set the output
// type to HTML even though the figure is inactive.
ret = python.interpret("plt.show()", context);
- assertEquals("", ret.message().get(0).getData());
-
+ String msg1 = new String(out.getOutputAt(0).toByteArray());
+ assertNotSame("", msg1);
+
// Now test that plot can be reshown if it is updated. It should be
// different from the previous one because it will plot the same line
// again but in a different color.
ret = python.interpret("plt.plot([1, 2, 3])", context);
+ msg1 = new String(out.getOutputAt(1).toByteArray());
ret2 = python.interpret("plt.show()", context);
- assertNotSame(ret1.message().get(0).getData(), ret2.message().get(0).getData());
+ String msg2 = new String(out.getOutputAt(1).toByteArray());
+
+ assertNotSame(msg1, msg2);
+ }
+
+
+ @Override
+ public void onUpdateAll(InterpreterOutput out) {
+
+ }
+
+ @Override
+ public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {
+
+ }
+
+ @Override
+ public void onUpdate(int index, InterpreterResultMessageOutput out) {
+
}
}
diff --git a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterPandasSqlTest.java b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterPandasSqlTest.java
index 86fb22bc322..f200a0a9429 100644
--- a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterPandasSqlTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterPandasSqlTest.java
@@ -21,13 +21,16 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.List;
import java.util.Properties;
import org.apache.zeppelin.display.AngularObjectRegistry;
import org.apache.zeppelin.display.GUI;
+import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterContextRunner;
import org.apache.zeppelin.interpreter.InterpreterGroup;
@@ -35,7 +38,10 @@
import org.apache.zeppelin.interpreter.InterpreterOutputListener;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterResult.Type;
+import org.apache.zeppelin.interpreter.InterpreterResultMessageOutput;
+import org.apache.zeppelin.resource.LocalResourcePool;
import org.apache.zeppelin.user.AuthenticationInfo;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -53,13 +59,14 @@
* mvn -Dpython.test.exclude='' test -pl python -am
*
*/
-public class PythonInterpreterPandasSqlTest {
+public class PythonInterpreterPandasSqlTest implements InterpreterOutputListener {
private InterpreterGroup intpGroup;
private PythonInterpreterPandasSql sql;
private PythonInterpreter python;
private InterpreterContext context;
+ InterpreterOutput out;
@Before
public void setUp() throws Exception {
@@ -78,14 +85,27 @@ public void setUp() throws Exception {
intpGroup.put("note", Arrays.asList(python, sql));
- context = new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(),
- new HashMap(), new GUI(),
- new AngularObjectRegistry(intpGroup.getId(), null), null,
- new LinkedList(), new InterpreterOutput(null));
+ out = new InterpreterOutput(this);
+
+ context = new InterpreterContext("note", "id", null, "title", "text",
+ new AuthenticationInfo(),
+ new HashMap(),
+ new GUI(),
+ new AngularObjectRegistry(intpGroup.getId(), null),
+ new LocalResourcePool("id"),
+ new LinkedList(),
+ out);
+
+ // to make sure python is running.
+ InterpreterResult ret = python.interpret("\n", context);
+ assertEquals(ret.message().toString(), InterpreterResult.Code.SUCCESS, ret.code());
- //important to be last step
sql.open();
- //it depends on python interpreter presence in the same group
+ }
+
+ @After
+ public void afterTest() throws IOException {
+ sql.close();
}
@Test
@@ -97,23 +117,15 @@ public void dependenciesAreInstalled() {
@Test
public void errorMessageIfDependenciesNotInstalled() {
InterpreterResult ret;
- // given
- ret = python.interpret(
- "pysqldf = lambda q: print('Can not execute SQL as Python dependency is not installed')",
- context);
- assertEquals(ret.message().toString(), InterpreterResult.Code.SUCCESS, ret.code());
-
- // when
ret = sql.interpret("SELECT * from something", context);
- // then
assertNotNull(ret);
- assertEquals(ret.message().get(0).getData(), InterpreterResult.Code.SUCCESS, ret.code());
- assertTrue(ret.message().get(0).getData().contains("dependency is not installed"));
+ assertEquals(ret.message().get(0).getData(), InterpreterResult.Code.ERROR, ret.code());
+ assertTrue(ret.message().get(0).getData().contains("no such table: something"));
}
@Test
- public void sqlOverTestDataPrintsTable() {
+ public void sqlOverTestDataPrintsTable() throws IOException {
InterpreterResult ret;
// given
//String expectedTable = "name\tage\n\nmoon\t33\n\npark\t34";
@@ -121,36 +133,34 @@ public void sqlOverTestDataPrintsTable() {
ret = python.interpret("import numpy as np", context);
// DataFrame df2 \w test data
ret = python.interpret("df2 = pd.DataFrame({ 'age' : np.array([33, 51, 51, 34]), "+
- "'name' : pd.Categorical(['moon','jobs','gates','park'])})", context);
+ "'name' : pd.Categorical(['moon','jobs','gates','park'])})", context);
assertEquals(ret.message().toString(), InterpreterResult.Code.SUCCESS, ret.code());
//when
ret = sql.interpret("select name, age from df2 where age < 40", context);
//then
- assertEquals(ret.message().get(0).getData(), InterpreterResult.Code.SUCCESS, ret.code());
- assertEquals(ret.message().get(0).getData(), Type.TABLE, ret.message().get(0).getType());
- //assertEquals(expectedTable, ret.message()); //somehow it's same but not equal
- assertTrue(ret.message().get(0).getData().indexOf("moon\t33") > 0);
- assertTrue(ret.message().get(0).getData().indexOf("park\t34") > 0);
+ assertEquals(new String(out.getOutputAt(0).toByteArray()), InterpreterResult.Code.SUCCESS, ret.code());
+ assertEquals(new String(out.getOutputAt(0).toByteArray()), Type.TABLE, out.getOutputAt(0).getType());
+ assertTrue(new String(out.getOutputAt(0).toByteArray()).indexOf("moon\t33") > 0);
+ assertTrue(new String(out.getOutputAt(0).toByteArray()).indexOf("park\t34") > 0);
assertEquals(InterpreterResult.Code.SUCCESS, sql.interpret("select case when name==\"aa\" then name else name end from df2", context).code());
}
@Test
- public void badSqlSyntaxFails() {
+ public void badSqlSyntaxFails() throws IOException {
//when
InterpreterResult ret = sql.interpret("select wrong syntax", context);
//then
assertNotNull("Interpreter returned 'null'", ret);
- //System.out.println("\nInterpreter response: \n" + ret.message());
assertEquals(ret.toString(), InterpreterResult.Code.ERROR, ret.code());
- assertTrue(ret.message().get(0).getData().length() > 0);
+ assertTrue(out.toInterpreterResultMessage().size() == 0);
}
@Test
- public void showDataFrame() {
+ public void showDataFrame() throws IOException {
InterpreterResult ret;
ret = python.interpret("import pandas as pd", context);
ret = python.interpret("import numpy as np", context);
@@ -165,11 +175,25 @@ public void showDataFrame() {
ret = python.interpret("z.show(df1, show_index=True)", context);
// then
- assertEquals(ret.message().get(0).getData(), InterpreterResult.Code.SUCCESS, ret.code());
- assertEquals(ret.message().get(0).getData(), Type.TABLE, ret.message().get(0).getType());
- assertTrue(ret.message().get(0).getData().indexOf("index_name") == 0);
- assertTrue(ret.message().get(0).getData().indexOf("13") > 0);
- assertTrue(ret.message().get(0).getData().indexOf("nan") > 0);
- assertTrue(ret.message().get(0).getData().indexOf("6.7") > 0);
+ assertEquals(new String(out.getOutputAt(0).toByteArray()), InterpreterResult.Code.SUCCESS, ret.code());
+ assertEquals(new String(out.getOutputAt(0).toByteArray()), Type.TABLE, out.getOutputAt(0).getType());
+ assertTrue(new String(out.getOutputAt(0).toByteArray()).contains("index_name"));
+ assertTrue(new String(out.getOutputAt(0).toByteArray()).contains("nan"));
+ assertTrue(new String(out.getOutputAt(0).toByteArray()).contains("6.7"));
+ }
+
+ @Override
+ public void onUpdateAll(InterpreterOutput out) {
+
+ }
+
+ @Override
+ public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {
+
+ }
+
+ @Override
+ public void onUpdate(int index, InterpreterResultMessageOutput out) {
+
}
-}
+}
\ No newline at end of file
diff --git a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
index bf50c232581..b5cd680d8da 100644
--- a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.zeppelin.python;
@@ -21,52 +21,39 @@
import static org.apache.zeppelin.python.PythonInterpreter.MAX_RESULT;
import static org.apache.zeppelin.python.PythonInterpreter.ZEPPELIN_PYTHON;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import java.io.File;
import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.HashMap;
import java.util.LinkedList;
+import java.util.Map;
import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-import org.apache.zeppelin.interpreter.ClassloaderInterpreter;
+import org.apache.commons.exec.environment.EnvironmentUtils;
+import org.apache.zeppelin.display.AngularObjectRegistry;
+import org.apache.zeppelin.display.GUI;
import org.apache.zeppelin.interpreter.Interpreter;
+import org.apache.zeppelin.interpreter.InterpreterContext;
+import org.apache.zeppelin.interpreter.InterpreterContextRunner;
import org.apache.zeppelin.interpreter.InterpreterGroup;
+import org.apache.zeppelin.interpreter.InterpreterOutput;
+import org.apache.zeppelin.interpreter.InterpreterOutputListener;
import org.apache.zeppelin.interpreter.InterpreterResult;
+import org.apache.zeppelin.interpreter.InterpreterResultMessageOutput;
+import org.apache.zeppelin.resource.LocalResourcePool;
+import org.apache.zeppelin.user.AuthenticationInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Python interpreter unit test
- *
- * Important: ALL tests here DO NOT REQUIRE Python to be installed
- * If Python dependency is required, please look at PythonInterpreterWithPythonInstalledTest
- */
-public class PythonInterpreterTest {
- private static final Logger LOG = LoggerFactory.getLogger(PythonProcess.class);
- PythonInterpreter zeppelinPythonInterpreter = null;
+public class PythonInterpreterTest implements InterpreterOutputListener {
PythonInterpreter pythonInterpreter = null;
- PythonProcess mockPythonProcess;
String cmdHistory;
+ private InterpreterContext context;
+ InterpreterOutput out;
public static Properties getPythonTestProperties() {
Properties p = new Properties();
@@ -79,18 +66,8 @@ public static Properties getPythonTestProperties() {
public void beforeTest() throws IOException {
cmdHistory = "";
- /*Mock python process*/
- mockPythonProcess = mock(PythonProcess.class);
- when(mockPythonProcess.getPid()).thenReturn(1L);
- when(mockPythonProcess.sendAndGetResult(anyString())).thenAnswer(new Answer() {
- @Override public String answer(InvocationOnMock invocationOnMock) throws Throwable {
- return answerFromPythonMock(invocationOnMock);
- }
- });
-
// python interpreter
- pythonInterpreter = spy(new PythonInterpreter(getPythonTestProperties()));
- zeppelinPythonInterpreter = new PythonInterpreter(getPythonTestProperties());
+ pythonInterpreter = new PythonInterpreter(getPythonTestProperties());
// create interpreter group
InterpreterGroup group = new InterpreterGroup();
@@ -98,186 +75,49 @@ public void beforeTest() throws IOException {
group.get("note").add(pythonInterpreter);
pythonInterpreter.setInterpreterGroup(group);
- when(pythonInterpreter.getPythonProcess()).thenReturn(mockPythonProcess);
- when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn("ImportError");
- }
-
- @After
- public void afterTest() throws IOException {
- pythonInterpreter.close();
- zeppelinPythonInterpreter.close();
- }
-
- @Test
- public void testOpenInterpreter() {
- pythonInterpreter.open();
- assertEquals(pythonInterpreter.getPythonProcess().getPid(), 1);
- }
-
- /**
- * If Py4J is not installed, bootstrap_input.py
- * is not sent to Python process and py4j JavaGateway is not running
- */
- @Test
- public void testPy4jIsNotInstalled() {
- pythonInterpreter.open();
- assertNull(pythonInterpreter.getPy4jPort());
- assertTrue(cmdHistory.contains("def help()"));
- assertTrue(cmdHistory.contains("class PyZeppelinContext(object):"));
- assertTrue(cmdHistory.contains("z = PyZeppelinContext"));
- assertTrue(cmdHistory.contains("def show"));
- assertFalse(cmdHistory.contains("GatewayClient"));
- }
-
- /**
- * If Py4J installed, bootstrap_input.py
- * is sent to interpreter and JavaGateway is running
- */
- @Test
- public void testPy4jInstalled() throws IOException, InterruptedException {
- when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn("");
+ out = new InterpreterOutput(this);
+ context = new InterpreterContext("note", "id", null, "title", "text",
+ new AuthenticationInfo(),
+ new HashMap(),
+ new GUI(),
+ new AngularObjectRegistry(group.getId(), null),
+ new LocalResourcePool("id"),
+ new LinkedList(),
+ out);
pythonInterpreter.open();
- Integer py4jPort = pythonInterpreter.getPy4jPort();
- assertNotNull(py4jPort);
-
- assertTrue(cmdHistory.contains("def help()"));
- assertTrue(cmdHistory.contains("class PyZeppelinContext(object):"));
- assertTrue(cmdHistory.contains("z = Py4jZeppelinContext"));
- assertTrue(cmdHistory.contains("def show"));
- assertTrue(cmdHistory.contains("GatewayClient(port=" + py4jPort + ")"));
- assertTrue(cmdHistory.contains("org.apache.zeppelin.display.Input"));
-
- assertTrue(serverIsListeningOn(py4jPort));
- pythonInterpreter.close();
- TimeUnit.MILLISECONDS.sleep(100);
- assertFalse(serverIsListeningOn(py4jPort));
}
- @Test
- public void testClose() throws IOException, InterruptedException {
- //given: py4j is installed
- when(mockPythonProcess.sendAndGetResult(eq("\n\nimport py4j\n"))).thenReturn("");
-
- pythonInterpreter.open();
- Integer py4jPort = pythonInterpreter.getPy4jPort();
- assertNotNull(py4jPort);
-
- //when
+ @After
+ public void afterTest() throws IOException {
pythonInterpreter.close();
- TimeUnit.MILLISECONDS.sleep(100);
-
- //then
- assertFalse(serverIsListeningOn(py4jPort));
- verify(mockPythonProcess, times(1)).close();
}
@Test
- public void testInterpret() {
- pythonInterpreter.open();
- cmdHistory = "";
- InterpreterResult result = pythonInterpreter.interpret("print a", null);
+ public void testInterpret() throws InterruptedException, IOException {
+ InterpreterResult result = pythonInterpreter.interpret("print (\"hi\")", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
- assertEquals("%text print a", result.message().get(0).toString());
}
@Test
- public void testInterpretInvalidSyntax() {
- zeppelinPythonInterpreter.open();
- InterpreterResult result = zeppelinPythonInterpreter.interpret("for x in range(0,3): print (\"hi\")\n\nz._displayhook()", null);
+ public void testInterpretInvalidSyntax() throws IOException {
+ InterpreterResult result = pythonInterpreter.interpret("for x in range(0,3): print (\"hi\")\n", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
- assertTrue(result.message().get(0).toString().contains("hi\nhi\nhi"));
-
- result = zeppelinPythonInterpreter.interpret("for x in range(0,3): print (\"hi\")\nz._displayhook()", null);
- assertEquals(InterpreterResult.Code.ERROR, result.code());
- assertTrue(result.message().get(0).toString().contains("SyntaxError: invalid syntax"));
- }
-
- /**
- * Checks if given port is open on 'localhost'
- * @param port
- */
- private boolean serverIsListeningOn(Integer port) {
- Socket s = new Socket();
- boolean serverIsListening = false;
+ assertTrue(new String(out.getOutputAt(0).toByteArray()).contains("hi\nhi\nhi"));
+ }
- int retryCount = 0;
- boolean connected = false;
- while (connected = tryToConnect(s, port) && retryCount < 10) {
- serverIsListening = connected;
- tryToClose(s);
- retryCount++;
- s = new Socket();
- }
- return serverIsListening;
- }
-
- private boolean tryToConnect(Socket s, Integer port) {
- boolean connected = false;
- SocketAddress sa = new InetSocketAddress("localhost", port);
- try {
- s.connect(sa, 10000);
- connected = true;
- } catch (IOException e) {
- //LOG.warn("Can't open connection to " + sa, e);
- }
- return connected;
- }
+ @Override
+ public void onUpdateAll(InterpreterOutput out) {
- private void tryToClose(Socket s) {
- try {
- s.close();
- } catch (IOException e) {
- LOG.error("Can't close connection to " + s.getInetAddress(), e);
- }
}
- private String answerFromPythonMock(InvocationOnMock invocationOnMock) {
- Object[] inputs = invocationOnMock.getArguments();
- String cmdToExecute = (String) inputs[0];
+ @Override
+ public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {
- if (cmdToExecute != null) {
- cmdHistory += cmdToExecute;
- String[] lines = cmdToExecute.split("\\n");
- String output = "";
-
- for (int i = 0; i < lines.length; i++) {
- output += lines[i];
- }
- return output;
- } else {
- return "";
- }
}
- @Test
- public void checkMultiRowErrorFails() {
-
- PythonInterpreter pythonInterpreter = new PythonInterpreter(
- PythonInterpreterTest.getPythonTestProperties()
- );
- // create interpreter group
- InterpreterGroup group = new InterpreterGroup();
- group.put("note", new LinkedList());
- group.get("note").add(pythonInterpreter);
- pythonInterpreter.setInterpreterGroup(group);
-
- pythonInterpreter.open();
-
- String codeRaiseException = "raise Exception(\"test exception\")";
- InterpreterResult ret = pythonInterpreter.interpret(codeRaiseException, null);
+ @Override
+ public void onUpdate(int index, InterpreterResultMessageOutput out) {
- assertNotNull("Interpreter result for raise exception is Null", ret);
-
- System.err.println("ret = '" + ret + "'");
- assertEquals(InterpreterResult.Code.ERROR, ret.code());
- assertTrue(ret.message().get(0).getData().length() > 0);
-
- assertNotNull("Interpreter result for text is Null", ret);
- String codePrintText = "print (\"Exception(\\\"test exception\\\")\")";
- ret = pythonInterpreter.interpret(codePrintText, null);
- assertEquals(InterpreterResult.Code.SUCCESS, ret.code());
- assertTrue(ret.message().get(0).getData().length() > 0);
}
-
}
diff --git a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterWithPythonInstalledTest.java b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterWithPythonInstalledTest.java
deleted file mode 100644
index 7b889ad724b..00000000000
--- a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterWithPythonInstalledTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.zeppelin.python;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.zeppelin.interpreter.Interpreter;
-import org.apache.zeppelin.interpreter.InterpreterGroup;
-import org.apache.zeppelin.interpreter.InterpreterResult;
-import org.junit.Test;
-
-import java.util.Arrays;
-
-/**
- * Python interpreter unit test that user real Python
- *
- * Important: ALL tests here REQUIRE Python to be installed
- * They are excluded from default build, to run them manually do:
- *
- *
- * mvn "-Dtest=org.apache.zeppelin.python.PythonInterpreterWithPythonInstalledTest" test -pl python
- *
- *
- * or
- *
- * mvn -Dpython.test.exclude='' test -pl python -am
- *
- */
-public class PythonInterpreterWithPythonInstalledTest {
-
- @Test
- public void badPythonSyntaxFails() {
- //given
- PythonInterpreter realPython = new PythonInterpreter(
- PythonInterpreterTest.getPythonTestProperties());
- // create interpreter group
- InterpreterGroup group = new InterpreterGroup();
- group.put("note", Arrays.asList((Interpreter) realPython));
- realPython.setInterpreterGroup(group);
-
- realPython.open();
-
- //when
- InterpreterResult ret = realPython.interpret("select wrong syntax", null);
-
- //then
- assertNotNull("Interpreter returned 'null'", ret);
- //System.out.println("\nInterpreter response: \n" + ret.message());
- assertEquals(InterpreterResult.Code.ERROR, ret.code());
- assertTrue(ret.message().get(0).getData().length() > 0);
-
- realPython.close();
- }
-
- @Test
- public void goodPythonSyntaxRuns() {
- //given
- PythonInterpreter realPython = new PythonInterpreter(
- PythonInterpreterTest.getPythonTestProperties());
- InterpreterGroup group = new InterpreterGroup();
- group.put("note", Arrays.asList((Interpreter) realPython));
- realPython.setInterpreterGroup(group);
- realPython.open();
-
- //when
- InterpreterResult ret = realPython.interpret("help()", null);
-
- //then
- assertNotNull("Interpreter returned 'null'", ret);
- //System.out.println("\nInterpreter response: \n" + ret.message());
- assertEquals(InterpreterResult.Code.SUCCESS, ret.code());
- assertTrue(ret.message().get(0).getData().length() > 0);
-
- realPython.close();
- }
-
- @Test
- public void testZeppelin1555() {
- //given
- PythonInterpreter realPython = new PythonInterpreter(
- PythonInterpreterTest.getPythonTestProperties());
- InterpreterGroup group = new InterpreterGroup();
- group.put("note", Arrays.asList((Interpreter) realPython));
- realPython.setInterpreterGroup(group);
- realPython.open();
-
- //when
- InterpreterResult ret1 = realPython.interpret("print(\"...\")", null);
-
- //then
- //System.out.println("\nInterpreter response: \n" + ret.message());
- assertEquals(InterpreterResult.Code.SUCCESS, ret1.code());
- assertEquals("...\n", ret1.message().get(0).getData());
-
-
- InterpreterResult ret2 = realPython.interpret("for i in range(5):", null);
- //then
- //System.out.println("\nInterpreterResultterpreter response: \n" + ret2.message());
- assertEquals(InterpreterResult.Code.ERROR, ret2.code());
- assertEquals(" File \"\", line 2\n" +
- " \n" +
- " ^\n" +
- "IndentationError: expected an indented block\n", ret2.message().get(0).getData());
-
- realPython.close();
- }
-
-}