Search in sources :

Example 36 with Code

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

the class ImportMagicCommandTest method removeImport.

@Test
public void removeImport() {
    // given
    String allCode = "%import com.twosigma.beakerx.widget.IntSlider\n";
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    code.execute(kernel, 1);
    assertThat(kernel.getImports().getImportPaths()).contains(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
    // when
    String allRemoveCode = "%unimport com.twosigma.beakerx.widget.IntSlider\n";
    Code codeToRemove = CodeFactory.create(allRemoveCode, new Message(), kernel);
    codeToRemove.execute(kernel, 2);
    // then
    assertThat(kernel.getImports().getImportPaths()).doesNotContain(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) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 37 with Code

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

the class ClasspathAddRepoMagicCommandTest method addMvnLocalShouldReturnWarningWhenLocalMavenRepositoryNotExist.

@Test
public void addMvnLocalShouldReturnWarningWhenLocalMavenRepositoryNotExist() {
    // given
    try {
        BeakerxSystemProperty.fixUserHome("/home/xxx");
        String allCode = CLASSPATH_CONFIG_RESOLVER + " " + MVN_LOCAL;
        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("Warning: directory");
    } finally {
        BeakerxSystemProperty.setSystemUserHome();
    }
}
Also used : Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 38 with Code

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

the class GroovyKernelTest method shouldNotImportStaticUnknownFieldDemoClassByMagicCommand.

@Test
public void shouldNotImportStaticUnknownFieldDemoClassByMagicCommand() throws Exception {
    // given
    addDemoJar();
    String path = pathToDemoClassFromAddedDemoJar() + ".STATIC_TEST_123_unknown";
    // when
    Code code = CodeFactory.create(ADD_STATIC_IMPORT + " " + path, new Message(), getKernel());
    code.execute(kernel, 1);
    // then
    verifyNotImportedStaticMagicCommand();
}
Also used : MessageFactoryTest.getExecuteRequestMessage(com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage) EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message) EvaluatorResultTestWatcher.waitForUpdateMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage) Code(com.twosigma.beakerx.kernel.Code) KernelExecutionTest(com.twosigma.beakerx.KernelExecutionTest) Test(org.junit.Test)

Example 39 with Code

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

the class GroovyKernelTest method shouldNotImportStaticUnknownClassByMagicCommand.

@Test
public void shouldNotImportStaticUnknownClassByMagicCommand() throws Exception {
    // given
    String allCode = ADD_STATIC_IMPORT + " " + pathToDemoClassFromAddedDemoJar() + "UnknownClass";
    // when
    Code code = CodeFactory.create(allCode, new Message(), getKernel());
    code.execute(kernel, 1);
    // then
    verifyNotImportedStaticMagicCommand();
}
Also used : MessageFactoryTest.getExecuteRequestMessage(com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage) EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message) EvaluatorResultTestWatcher.waitForUpdateMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage) Code(com.twosigma.beakerx.kernel.Code) KernelExecutionTest(com.twosigma.beakerx.KernelExecutionTest) Test(org.junit.Test)

Example 40 with Code

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

the class GroovyKernelTest method shouldNotImportStaticUnknownMethodDemoClassByMagicCommand.

@Test
public void shouldNotImportStaticUnknownMethodDemoClassByMagicCommand() throws Exception {
    // given
    addDemoJar();
    String path = pathToDemoClassFromAddedDemoJar() + ".staticTest_unknown";
    // when
    Code code = CodeFactory.create(ADD_STATIC_IMPORT + " " + path, new Message(), getKernel());
    code.execute(kernel, 1);
    // then
    verifyNotImportedStaticMagicCommand();
}
Also used : MessageFactoryTest.getExecuteRequestMessage(com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage) EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message) EvaluatorResultTestWatcher.waitForUpdateMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage) Code(com.twosigma.beakerx.kernel.Code) KernelExecutionTest(com.twosigma.beakerx.KernelExecutionTest) Test(org.junit.Test)

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