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());
}
}
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");
}
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);
}
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);
}
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");
}
Aggregations