Search in sources :

Example 16 with TryResult

use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.

the class JavaEvaluatorTest method singleImport.

@Test
public void singleImport() throws Exception {
    // given
    String code = "import java.util.Date;";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 17 with TryResult

use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.

the class JavaEvaluatorTest method evaluateVoid.

@Test
public void evaluateVoid() throws Exception {
    // given
    String code = "System.out.println(\"Hello\");";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 18 with TryResult

use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.

the class ScalaEvaluatorTest method incompleteInput_shouldBeDetected.

@Test
public void incompleteInput_shouldBeDetected() throws Exception {
    // given
    String code = "1 to 10 map { i => i * 2";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = scalaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.error()).contains("incomplete");
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 19 with TryResult

use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.

the class ScalaEvaluatorTest method displayTable.

@Test
public void displayTable() throws Exception {
    // given
    String code = "val table = new TableDisplay(new CSV().readFile(\"src/test/resources/tableRowsTest.csv\"))\n" + "table";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = scalaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result() instanceof DisplayableWidget).isTrue();
}
Also used : DisplayableWidget(com.twosigma.beakerx.widget.DisplayableWidget) TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 20 with TryResult

use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.

the class BaseEvaluator method evaluate.

protected TryResult evaluate(SimpleEvaluationObject seo, Callable<TryResult> callable) {
    Future<TryResult> submit = executorService.submit(callable);
    TryResult either = null;
    try {
        either = submit.get();
    } catch (Exception e) {
        either = TryResult.createError(e.getLocalizedMessage());
    }
    return either;
}
Also used : TryResult(com.twosigma.beakerx.TryResult)

Aggregations

TryResult (com.twosigma.beakerx.TryResult)55 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)41 Test (org.junit.Test)30 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 NamespaceClient (com.twosigma.beakerx.NamespaceClient)5 PrintWriter (java.io.PrintWriter)5 StringWriter (java.io.StringWriter)5 KernelTest (com.twosigma.beakerx.KernelTest)4 EvaluatorParameters (com.twosigma.beakerx.kernel.EvaluatorParameters)3 PlainCode.createSimpleEvaluationObject (com.twosigma.beakerx.kernel.PlainCode.createSimpleEvaluationObject)3 MagicCommandOutput (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput)3 HashMap (java.util.HashMap)3 Plot (com.twosigma.beakerx.chart.xychart.Plot)2 MagicCommandOutcomeItem (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutcomeItem)2 Message (com.twosigma.beakerx.message.Message)2 ThreadMXBean (java.lang.management.ThreadMXBean)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 ReplEvalResult (org.jetbrains.kotlin.cli.common.repl.ReplEvalResult)2 Code (com.twosigma.beakerx.kernel.Code)1