Search in sources :

Example 66 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class ClasspathMagicCommandTest method handleClasspathAddJarMagicCommand.

@Test
public void handleClasspathAddJarMagicCommand() {
    // given
    String allCode = "" + CLASSPATH_ADD_JAR + " " + CLASSPATH_TO_JAR_PATH + "\n" + "code code code";
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    // when
    code.execute(kernel, 1);
    // then
    PlainCode actual = (PlainCode) code.getCodeFrames().get(1);
    Assertions.assertThat(actual.getPlainCode()).isEqualTo("code code code");
    assertThat(kernel.getClasspath().get(0)).contains(FOO_JAR);
}
Also used : Message(com.twosigma.beakerx.message.Message) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 67 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class ClasspathMagicCommandTest method shouldCreateMsgWithWrongMagic.

@Test
public void shouldCreateMsgWithWrongMagic() {
    // given
    String jar = SRC_TEST_RESOURCES + "BeakerXClasspathTest.jar";
    Code code = CodeFactory.create("%classpath2 add jar" + " " + jar, new Message(), kernel);
    // when
    code.execute(kernel, 1);
    // then
    List<Message> std = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages());
    String text = (String) std.get(0).getContent().get("text");
    assertThat(text).contains("Inline magic %classpath2 add jar ./src/test/resources/BeakerXClasspathTest.jar not found\n");
    assertThat(kernel.getClasspath().size()).isEqualTo(0);
}
Also used : Message(com.twosigma.beakerx.message.Message) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 68 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class ImportMagicCommandTest method addImport.

@Test
public void addImport() {
    // given
    String allCode = "%import com.twosigma.beakerx.widget.IntSlider\n" + "w = new IntSlider()";
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    // when
    code.execute(kernel, 1);
    // then
    PlainCode actual = (PlainCode) code.getCodeFrames().get(1);
    assertThat(actual.getPlainCode()).isEqualTo("w = new IntSlider()");
    assertThat(kernel.getImports().getImportPaths()).contains(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
}
Also used : Message(com.twosigma.beakerx.message.Message) ImportPath(com.twosigma.beakerx.kernel.ImportPath) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) PlainCode(com.twosigma.beakerx.kernel.PlainCode) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 69 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class ImportMagicCommandTest method wrongImportFormat.

@Test
public void wrongImportFormat() {
    String allCode = "%import ";
    Code wrongFormatImport = CodeFactory.create(allCode, new Message(), kernel);
    wrongFormatImport.execute(kernel, 1);
    List<Message> std = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages());
    String text = (String) std.get(0).getContent().get("text");
    assertThat(text).contains("Wrong format.");
}
Also used : Message(com.twosigma.beakerx.message.Message) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 70 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class ClasspathAddDynamicMagicCommandTest method runCode.

private void runCode(String code) throws InterruptedException {
    Message message = JupyterHandlerTest.createExecuteRequestMessage(code);
    kernelSocketsService.handleMsg(message);
    Optional<Message> idleMessage = waitForIdleMessage(kernelSocketsService.getKernelSockets());
    assertThat(idleMessage).isPresent();
    kernelSocketsService.clear();
}
Also used : EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message)

Aggregations

Message (com.twosigma.beakerx.message.Message)270 Test (org.junit.Test)170 KernelTest (com.twosigma.beakerx.KernelTest)121 EvaluatorResultTestWatcher.waitForIdleMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage)64 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)57 Code (com.twosigma.beakerx.kernel.Code)55 Serializable (java.io.Serializable)36 MessageFactoryTest.getExecuteRequestMessage (com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage)35 EvaluatorResultTestWatcher.waitForErrorMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForErrorMessage)28 MessageTest (com.twosigma.beakerx.message.MessageTest)27 Map (java.util.Map)26 HashMap (java.util.HashMap)24 Header (com.twosigma.beakerx.message.Header)23 MessageAssertions.verifyExecuteReplyMessage (com.twosigma.MessageAssertions.verifyExecuteReplyMessage)19 EvaluatorResultTestWatcher.waitForSentMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForSentMessage)19 PlainCode (com.twosigma.beakerx.kernel.PlainCode)14 KernelExecutionTest (com.twosigma.beakerx.KernelExecutionTest)13 EvaluatorResultTestWatcher.waitForUpdateMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage)13 LinkedHashMap (java.util.LinkedHashMap)12 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)11