Search in sources :

Example 41 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class ExecuteRequestHandler method handleMsg.

private void handleMsg(Message message) {
    kernel.sendBusyMessage(message);
    executionCount += 1;
    String codeString = takeCodeFrom(message);
    announceTheCode(message, codeString);
    Code code = CodeFactory.create(codeString, message, kernel);
    code.execute(kernel, executionCount);
    finishExecution(message);
}
Also used : Code(com.twosigma.beakerx.kernel.Code)

Example 42 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class ClasspathAddMagicCommandTest method errorWhenUnknownMagicCommand.

@Test
public void errorWhenUnknownMagicCommand() {
    // given
    String allCode = "%unknownClasspath params";
    Code code = CodeFactory.create(allCode, 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 " + allCode + " not found");
}
Also used : Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 43 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class TimeItCellModeMagicCommandTest method timeitInCellMode.

@Test
public void timeitInCellMode() {
    // given
    String allCode = "%%timeit -r3 -n10\n" + "a = 15;\n" + "b = 111;\n" + "a * b;";
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    // when
    code.execute(kernel, 1);
    // then
    List<Message> std = EvaluatorResultTestWatcher.getStdouts(kernel.getPublishedMessages());
    String text = (String) std.get(0).getContent().get("text");
    assertThat(text).contains("loop");
}
Also used : Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 44 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class TimeLineModeMagicCommandTest method timeLineMode.

@Test
public void timeLineMode() {
    // given
    String allCode = "%time 2*128";
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    // when
    code.getCodeFrames().get(code.getCodeFrames().size() - 1).executeLastFrame(code, this.kernel, new Message(), 1);
    code.execute(kernel, 1);
    // then
    List<Message> std = EvaluatorResultTestWatcher.getStdouts(kernel.getPublishedMessages());
    String text = (String) std.get(0).getContent().get("text");
    assertThat(text).contains("CPU times");
}
Also used : Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 45 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class ClasspathAddMvnDepsMagicCommandTest method unresolvedDependency.

@Test
public void unresolvedDependency() {
    // given
    String allCode = CLASSPATH_ADD_MVN + " com.google.code.XXXX gson 2.6.2";
    MagicCommand command = new MagicCommand(new ClasspathAddMvnMagicCommand(kernel.mavenResolverParam, kernel), allCode);
    Code code = Code.createCode(allCode, singletonList(command), NO_ERRORS, new Message());
    // when
    code.execute(kernel, 1);
    // then
    List<Message> stderr = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages());
    String text = (String) stderr.get(0).getContent().get("text");
    assertThat(text).contains("Could not resolve dependencies for:");
    assertThat(text).contains("com.google.code.XXXX : gson : 2.6.2");
}
Also used : ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Message(com.twosigma.beakerx.message.Message) ClasspathResetMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand) ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Aggregations

Code (com.twosigma.beakerx.kernel.Code)55 Message (com.twosigma.beakerx.message.Message)54 Test (org.junit.Test)47 KernelTest (com.twosigma.beakerx.KernelTest)33 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)29 MessageFactoryTest.getExecuteRequestMessage (com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage)16 EvaluatorResultTestWatcher.waitForIdleMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage)16 PlainCode (com.twosigma.beakerx.kernel.PlainCode)14 MessageAssertions.verifyExecuteReplyMessage (com.twosigma.MessageAssertions.verifyExecuteReplyMessage)9 EvaluatorResultTestWatcher.waitForErrorMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForErrorMessage)9 EvaluatorResultTestWatcher.waitForSentMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForSentMessage)9 KernelExecutionTest (com.twosigma.beakerx.KernelExecutionTest)7 EvaluatorResultTestWatcher.waitForUpdateMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage)7 ClasspathAddMvnMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand)4 ClasspathResetMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand)4 ImportPath (com.twosigma.beakerx.kernel.ImportPath)3 PathToJar (com.twosigma.beakerx.kernel.PathToJar)2 MagicCommand (com.twosigma.beakerx.kernel.magic.command.MagicCommand)2 ClassPathAddMvnCellMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClassPathAddMvnCellMagicCommand)2 EvaluatorResultTestWatcher (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher)1