Search in sources :

Example 6 with EvaluatorParameters

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

the class KotlinEvaluatorTest method evaluatePlot_shouldCreatePlotObject.

@Test
public void evaluatePlot_shouldCreatePlotObject() throws Exception {
    // given
    Map<String, Object> paramMap = new HashMap<>();
    paramMap.put(IMPORTS, asList("import com.twosigma.beakerx.chart.xychart.*"));
    evaluator.setShellOptions(new EvaluatorParameters(paramMap));
    String code = "val plot = Plot()\n" + "plot.setTitle(\"test title\");\n" + "plot.display();";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = evaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : EvaluatorParameters(com.twosigma.beakerx.kernel.EvaluatorParameters) HashMap(java.util.HashMap) TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 7 with EvaluatorParameters

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

the class KotlinEvaluatorTest method javaImports_shouldBeAdjustedForKotlin.

@Test
public void javaImports_shouldBeAdjustedForKotlin() throws Exception {
    // given
    Map<String, Object> paramMap = new HashMap<>();
    // This import tests both "static" removal and "object" escaping.
    List<String> imports = asList("import static com.twosigma.beakerx.kotlin.evaluator.object.ImportTestHelper.staticMethod");
    paramMap.put(IMPORTS, imports);
    EvaluatorParameters kernelParameters = new EvaluatorParameters(paramMap);
    // when
    evaluator.setShellOptions(kernelParameters);
    String code = "val x = staticMethod()";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    TryResult evaluate = evaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : EvaluatorParameters(com.twosigma.beakerx.kernel.EvaluatorParameters) HashMap(java.util.HashMap) TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 8 with EvaluatorParameters

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

the class GroovyEvaluatorTest method initClassStubData.

@BeforeClass
public static void initClassStubData() throws IOException {
    GroovyDefaultVariables var = new GroovyDefaultVariables();
    HashMap<String, Object> params = new HashMap<>();
    params.put(IMPORTS, var.getImports());
    params.put(CLASSPATH, var.getClassPath());
    EvaluatorParameters kernelParameters = new EvaluatorParameters(params);
    GroovyEvaluator groovyEvaluator = new GroovyEvaluator("123", "345", cellExecutor(), getTestTempFolderFactory(), kernelParameters);
    groovyEvaluator.setShellOptions(kernelParameters);
    groovyClassLoader = newEvaluator(groovyEvaluator.getImports(), groovyEvaluator.getClasspath(), groovyEvaluator.getOutDir(), icz, newParentClassLoader(groovyEvaluator.getClasspath()));
    scriptBinding = new Binding();
    scriptBinding.setVariable("beaker", NamespaceClient.getBeaker("345"));
    groovyKernel = new GroovyKernelMock("groovyEvaluatorTest", groovyEvaluator);
    KernelManager.register(groovyKernel);
}
Also used : EvaluatorParameters(com.twosigma.beakerx.kernel.EvaluatorParameters) Binding(groovy.lang.Binding) GroovyDefaultVariables(com.twosigma.beakerx.groovy.kernel.GroovyDefaultVariables) GroovyKernelMock(com.twosigma.beakerx.groovy.kernel.GroovyKernelMock) HashMap(java.util.HashMap) BeforeClass(org.junit.BeforeClass)

Example 9 with EvaluatorParameters

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

the class GroovyCompleteHandlerTest method setUpClass.

@BeforeClass
public static void setUpClass() {
    GroovyEvaluator groovyEvaluator = new GroovyEvaluator("id", "sid", cellExecutor(), EvaluatorTest.getTestTempFolderFactory(), new EvaluatorParameters(new HashedMap()));
    groovyKernel = new GroovyKernelMock("sid", groovyEvaluator);
}
Also used : EvaluatorParameters(com.twosigma.beakerx.kernel.EvaluatorParameters) GroovyKernelMock(com.twosigma.beakerx.groovy.kernel.GroovyKernelMock) GroovyEvaluator(com.twosigma.beakerx.groovy.evaluator.GroovyEvaluator) HashedMap(org.apache.commons.collections.map.HashedMap) BeforeClass(org.junit.BeforeClass)

Aggregations

EvaluatorParameters (com.twosigma.beakerx.kernel.EvaluatorParameters)9 HashMap (java.util.HashMap)8 TryResult (com.twosigma.beakerx.TryResult)3 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.Test)3 GroovyKernelMock (com.twosigma.beakerx.groovy.kernel.GroovyKernelMock)2 Before (org.junit.Before)2 KernelTest (com.twosigma.beakerx.KernelTest)1 BaseEvaluator (com.twosigma.beakerx.evaluator.BaseEvaluator)1 EvaluatorManager (com.twosigma.beakerx.evaluator.EvaluatorManager)1 GroovyEvaluator (com.twosigma.beakerx.groovy.evaluator.GroovyEvaluator)1 GroovyDefaultVariables (com.twosigma.beakerx.groovy.kernel.GroovyDefaultVariables)1 JavaEvaluator (com.twosigma.beakerx.javash.evaluator.JavaEvaluator)1 JavaDefaultVariables (com.twosigma.beakerx.javash.kernel.JavaDefaultVariables)1 MagicCommandOutput (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput)1 Binding (groovy.lang.Binding)1 HashedMap (org.apache.commons.collections.map.HashedMap)1