Search in sources :

Example 1 with Code

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

the class TimeItCellModeMagicCommand method execute.

@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
    Code code = param.getCode();
    Message message = param.getCode().getMessage();
    int executionCount = param.getExecutionCount();
    try {
        return timeIt(buildTimeItOption(code), param.getCommandCodeBlock(), message, executionCount, param.isShowResult());
    } catch (IllegalArgumentException e) {
        return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, e.getMessage());
    }
}
Also used : MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code)

Example 2 with Code

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

the class ClasspathAddMagicCommandTest method errorWhenIncompleteMagicCommand.

@Test
public void errorWhenIncompleteMagicCommand() {
    // given
    String allCode = ClasspathAddJarMagicCommand.CLASSPATH + " add garbage";
    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(" 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 3 with Code

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

the class CodeFactoryTest method shouldBuildCodeWithCombinationOfCodeAndMagic.

@Test
public void shouldBuildCodeWithCombinationOfCodeAndMagic() {
    // given
    String codeAsString = "" + "println(1)\n" + "%time 1+1\n" + "println(2)\n" + "%time 1+2\n";
    // when
    Code code = CodeFactory.create(codeAsString, new Message(), kernel);
    // then
    assertThat(code.getCodeFrames().size()).isEqualTo(4);
}
Also used : Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 4 with Code

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

the class CodeFactoryTest method shouldNotModifyCode.

@Test
public void shouldNotModifyCode() {
    String codeAsString = "%time println(\"x  y\")";
    // when
    Code code = CodeFactory.create(codeAsString, new Message(), kernel);
    // then
    assertThat(((MagicCommand) code.getCodeFrames().get(0)).getCommand()).isEqualTo(codeAsString);
}
Also used : Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 5 with Code

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

the class MagicCommandResultOrderTest method classpathAddJarShouldBeLast.

@Test
public void classpathAddJarShouldBeLast() {
    // given
    String allCode = "" + "%classpath\n" + "%classpath add jar " + DOC_CONTENTS_DEMO_RESOURCES_BEAKERX_TEST_LIBRARY_JAR + "\n";
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    // when
    code.execute(kernel, 1);
    // then
    MagicCommand actual = (MagicCommand) code.getCodeFrames().get(1);
    assertThat(actual.getCommand()).contains("%classpath add jar");
}
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)

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