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