Search in sources :

Example 1 with MagicCommand

use of com.twosigma.beakerx.kernel.magic.command.MagicCommand in project beakerx by twosigma.

the class SQLMagicCommandTest method handleDefaultDatasourceMagicCommand.

@Test
public void handleDefaultDatasourceMagicCommand() throws Exception {
    // given
    String codeAsString = DEFAULT_DATASOURCE + " jdbc:h2:mem:db1";
    MagicCommand command = new MagicCommand(new DefaultDataSourcesMagicCommand(kernel), codeAsString);
    Code code = Code.createCode(codeAsString, singletonList(command), NO_ERRORS, new Message());
    // when
    code.execute(kernel, 1);
    // then
    assertThat(getDefaultDatasource().get()).isEqualTo("jdbc:h2:mem:db1");
}
Also used : Message(com.twosigma.beakerx.message.Message) MagicCommand(com.twosigma.beakerx.kernel.magic.command.MagicCommand) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 2 with MagicCommand

use of com.twosigma.beakerx.kernel.magic.command.MagicCommand in project beakerx by twosigma.

the class SQLMagicCommandTest method handleDatasourceMagicCommand.

@Test
public void handleDatasourceMagicCommand() throws Exception {
    // given
    String codeAsString = DATASOURCES + " jdbc:h2:mem:db2";
    MagicCommand command = new MagicCommand(new DataSourcesMagicCommand(kernel), codeAsString);
    Code code = Code.createCode(codeAsString, singletonList(command), NO_ERRORS, new Message());
    // when
    code.execute(kernel, 1);
    // then
    assertThat(getDatasource().get()).isEqualTo("jdbc:h2:mem:db2");
}
Also used : Message(com.twosigma.beakerx.message.Message) MagicCommand(com.twosigma.beakerx.kernel.magic.command.MagicCommand) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 3 with MagicCommand

use of com.twosigma.beakerx.kernel.magic.command.MagicCommand in project beakerx by twosigma.

the class CodeTest method shouldReadAllMagicCommands.

@Test
public void shouldReadAllMagicCommands() throws Exception {
    // give
    String allCode = "" + CLASSPATH_ADD_JAR + " lib1.jar\n" + CLASSPATH_ADD_JAR + " lib2.jar\n" + CLASSPATH_ADD_JAR + " lib3.jar\n" + "code code code";
    // when
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    // then
    assertThat(code.getCodeFrames().size()).isEqualTo(4);
    assertThat(((MagicCommand) code.getCodeFrames().get(0)).getCommand()).isEqualTo("%classpath add jar lib1.jar");
    assertThat(((MagicCommand) code.getCodeFrames().get(1)).getCommand()).isEqualTo("%classpath add jar lib2.jar");
    assertThat(((MagicCommand) code.getCodeFrames().get(2)).getCommand()).isEqualTo("%classpath add jar lib3.jar");
    assertThat(((PlainCode) code.getCodeFrames().get(3)).getPlainCode()).isEqualTo("code code code");
}
Also used : Message(com.twosigma.beakerx.message.Message) MagicCommand(com.twosigma.beakerx.kernel.magic.command.MagicCommand) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 4 with MagicCommand

use of com.twosigma.beakerx.kernel.magic.command.MagicCommand in project beakerx by twosigma.

the class CodeTest method shouldReadJavaScriptCommand.

@Test
public void shouldReadJavaScriptCommand() {
    // give
    String jsCode = "require.config({\n" + "  paths: {\n" + "      d3: '//cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min'\n" + "  }});";
    // when
    Code code = CodeFactory.create(JAVASCRIPT + "\n" + jsCode, new Message(), kernel);
    // then
    assertThat(code.getCodeFrames().size()).isEqualTo(1);
    MagicCommand magicCommand = (MagicCommand) code.getCodeFrames().get(0);
    assertThat(magicCommand.getCommand()).isEqualTo(JAVASCRIPT);
    String toCompare = magicCommand.getCommandCodeBlock().replaceAll("\\s+", "");
    jsCode = jsCode.replaceAll("\\s+", "");
    assertThat(toCompare).isEqualTo(jsCode);
// assertThat(result.takeCodeWithoutCommand()).isEqualTo(new Code(jsCode));
}
Also used : Message(com.twosigma.beakerx.message.Message) MagicCommand(com.twosigma.beakerx.kernel.magic.command.MagicCommand) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Aggregations

EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)4 MagicCommand (com.twosigma.beakerx.kernel.magic.command.MagicCommand)4 Message (com.twosigma.beakerx.message.Message)4 Test (org.junit.Test)4 KernelTest (com.twosigma.beakerx.KernelTest)2 Code (com.twosigma.beakerx.kernel.Code)2