use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class EvaluatorBaseTest method shouldDivide16By2.
@Test
public void shouldDivide16By2() throws Exception {
// given
String code = codeForDivide16By2();
SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
// when
TryResult result = evaluator().evaluate(seo, code);
// then
assertThat(result.result().toString()).isEqualTo("8");
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class KotlinCodeRunner method interpretResult.
private TryResult interpretResult(Object o) {
TryResult either;
if (o == null) {
either = TryResult.createResult(null);
} else if (o instanceof ReplEvalResult.UnitResult) {
either = TryResult.createResult(null);
} else if (o instanceof ReplEvalResult.ValueResult) {
Object value = ((ReplEvalResult.ValueResult) o).getValue();
either = TryResult.createResult(value);
} else if (o instanceof ReplEvalResult.Error) {
String message = ((ReplEvalResult.Error) o).getMessage();
either = TryResult.createError(message);
} else {
either = TryResult.createError(o.toString());
}
return either;
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class ScalaEvaluatorTest method javaImports_shouldBeAdjustedForScala.
@Test
public void javaImports_shouldBeAdjustedForScala() throws Exception {
// given
Map<String, Object> paramMap = new HashMap<>();
// This import tests both "static" removal and "object" escaping.
List<String> imports = Arrays.asList("import static com.twosigma.beakerx.scala.evaluator.object.ImportTestHelper.staticMethod");
paramMap.put(IMPORTS, imports);
EvaluatorParameters kernelParameters = new EvaluatorParameters(paramMap);
// when
scalaEvaluator.setShellOptions(kernelParameters);
String code = "val x = staticMethod()";
SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
TryResult evaluate = scalaEvaluator.evaluate(seo, code);
// then
assertThat(evaluate.result()).isNull();
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class ScalaEvaluatorTest method evaluatePlot_shouldCreatePlotObject.
@Test
public void evaluatePlot_shouldCreatePlotObject() throws Exception {
// given
String code = "import com.twosigma.beakerx.chart.xychart.Plot;\n" + "val plot = new Plot();\n" + "plot.setTitle(\"test title\");";
SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
// when
TryResult evaluate = scalaEvaluator.evaluate(seo, code);
// then
assertThat(evaluate.result() instanceof Plot).isTrue();
assertThat(((Plot) evaluate.result()).getTitle()).isEqualTo("test title");
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class JavaWorkerThread method call.
@Override
public TryResult call() throws Exception {
NamespaceClient nc = null;
TryResult r;
try {
nc = NamespaceClient.getBeaker(javaEvaluator.getSessionId());
nc.setOutputObj(j.outputObject);
r = javaEvaluator.executeTask(new JavaCodeRunner(javaEvaluator, j.outputObject, j));
} catch (Throwable e) {
e.printStackTrace();
r = TryResult.createError(e.getLocalizedMessage());
} finally {
if (nc != null) {
nc.setOutputObj(null);
nc = null;
}
}
return r;
}
Aggregations