Search in sources :

Example 51 with TryResult

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

the class GroovyEvaluatorMagicCommandsTest method addJarToClasspath.

@Test
public void addJarToClasspath() throws Exception {
    // given
    String code = "" + "import com.example.Demo;\n" + "Demo demo = new Demo();\n" + "demo.getObjectTest()\n";
    TryResult seo = runCode(code);
    assertThat(seo.error()).contains("unable to resolve class");
    // when
    PathToJar path = new PathToJar(SRC_TEST_RESOURCES + "demo.jar");
    groovyEvaluator.addJarsToClasspath(singletonList(path));
    // then
    TryResult seo2 = runCode(code);
    assertThat(seo2.result()).isEqualTo("Demo_test_123");
}
Also used : TryResult(com.twosigma.beakerx.TryResult) PathToJar(com.twosigma.beakerx.kernel.PathToJar) Test(org.junit.Test)

Example 52 with TryResult

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

the class GroovyEvaluatorProgressReportingTest method progressReporting.

@Test
public void progressReporting() throws Exception {
    // given
    String code = "for ( int i = 0 ; i<5; i++) {\n" + "  " + BEAKER_VARIABLE_NAME + ".showProgressUpdate(\"msg\"+i, i)\n" + "}\n" + "\"finished\"";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = groovyEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isEqualTo("finished");
    verifyProgressReporting(groovyKernel.getPublishedMessages());
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 53 with TryResult

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

the class JavaCodeRunner method compileNewDefinitionClass.

private TryResult compileNewDefinitionClass(JobDescriptor j, Matcher m, Codev codev) {
    TryResult either;
    String cname = m.group(1);
    addTheRestOfCode(codev);
    org.abstractmeta.toolbox.compilation.compiler.JavaSourceCompiler javaSourceCompiler = new com.twosigma.beakerx.javash.evaluator.JavaSourceCompiler();
    JavaSourceCompiler.CompilationUnit compilationUnit = javaSourceCompiler.createCompilationUnit(new File(javaEvaluator.getOutDir()));
    buildClasspath(compilationUnit);
    compilationUnit.addJavaSource(codev.getPname() + "." + cname, codev.javaSourceCode.toString());
    try {
        javaSourceCompiler.compile(compilationUnit);
        javaSourceCompiler.persistCompiledClasses(compilationUnit);
        either = TryResult.createResult(codev.getPname() + "." + cname);
    } catch (CompilationException e) {
        either = TryResult.createError(buildErrorMessage(e, codev.lineNumbersMapping));
    } catch (Exception e) {
        either = TryResult.createError("ERROR: " + e.toString());
    }
    return either;
}
Also used : TryResult(com.twosigma.beakerx.TryResult) JavaSourceCompiler(org.abstractmeta.toolbox.compilation.compiler.JavaSourceCompiler) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaSourceCompiler(org.abstractmeta.toolbox.compilation.compiler.JavaSourceCompiler) File(java.io.File)

Example 54 with TryResult

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

the class GroovyEvaluatorPassingSimpleEvaluationObjectTest method shouldPassSimpleEvaluationObjectToShell.

@Test
public void shouldPassSimpleEvaluationObjectToShell() throws Exception {
    // given
    String code = "" + "import com.twosigma.beakerx.evaluator.InternalVariable\n" + "InternalVariable.getParentHeader()";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    Message message = new Message();
    seo.setJupyterMessage(message);
    // when
    TryResult evaluate = groovyEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isEqualTo(message);
}
Also used : Message(com.twosigma.beakerx.message.Message) TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 55 with TryResult

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

the class GroovyEvaluatorStackTraceTest method arithmeticException.

@Test
public void arithmeticException() throws Exception {
    String code = "1/0";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = groovyEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.isError()).isTrue();
    assertThat(evaluate.error()).contains("at this cell line 1");
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

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