use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class ClasspathAddMvnDepsMagicCommandTest method handleClasspathReset.
@Test
public void handleClasspathReset() throws Exception {
// given
String allCode = CLASSPATH_ADD_MVN + " com.google.code.gson:gson:2.6.2";
handleClasspathAddMvnDep(allCode, "gson-2.6.2.jar");
kernel.clearMessages();
ClasspathAddMvnMagicCommand mvnMagicCommand = MagicCommandTypesFactory.getClasspathAddMvnMagicCommand(kernel);
mvnMagicCommand.addRepo("jcenter", "jcenter");
// when
String resetCode = CLASSPATH_RESET;
ClasspathResetMagicCommand resetMagicCommand = MagicCommandTypesFactory.getClasspathResetMagicCommand(kernel);
MagicCommand command = new MagicCommand(resetMagicCommand, resetCode);
Code code = Code.createCode(resetCode, singletonList(command), NO_ERRORS, new Message());
code.execute(kernel, 1);
// then
List<Message> stderr = EvaluatorResultTestWatcher.getStdouts(kernel.getPublishedMessages());
String text = (String) stderr.get(0).getContent().get("text");
assertThat(text).contains("Reset done");
boolean cache = Files.exists(Paths.get(mvnMagicCommand.getCommandParams().getPathToCache()));
Assert.assertFalse(cache);
boolean jars = Files.exists(Paths.get(mvnMagicCommand.getCommandParams().getPathToNotebookJars()));
Assert.assertFalse(jars);
Assert.assertTrue(mvnMagicCommand.getRepos().get().isEmpty());
}
use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class ClasspathAddMvnDepsMagicCommandTest method wrongCommandFormat.
@Test
public void wrongCommandFormat() {
// given
String allCode = CLASSPATH_ADD_MVN + " com.google.code.XXXX gson";
MagicCommand command = new MagicCommand(new ClasspathAddMvnMagicCommand(kernel.mavenResolverParam, kernel), allCode);
Code code = Code.createCode(allCode, singletonList(command), NO_ERRORS, new Message());
// when
code.execute(kernel, 1);
// then
List<Message> stderr = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages());
String text = (String) stderr.get(0).getContent().get("text");
assertThat(text).contains(ADD_MVN_FORMAT_ERROR_MESSAGE + "\n");
}
use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class ClasspathAddMvnDepsMagicCommandTest method handleClasspathAddMvnDep.
private void handleClasspathAddMvnDep(String allCode, String expected) throws IOException {
MagicCommand command = new MagicCommand(new ClasspathAddMvnMagicCommand(kernel.mavenResolverParam, kernel), allCode);
Code code = Code.createCode(allCode, singletonList(command), NO_ERRORS, new Message());
// when
code.execute(kernel, 1);
// then
List<Message> stderr = EvaluatorResultTestWatcher.getStdouts(kernel.getPublishedMessages());
String text = (String) stderr.get(0).getContent().get("text");
assertThat(text).contains("Added jar");
assertThat(text).contains(expected);
String mvnDir = kernel.getTempFolder().toString() + MavenJarResolver.MVN_DIR;
Stream<Path> paths = Files.walk(Paths.get(mvnDir));
Optional<Path> dep = paths.filter(file -> (file.getFileName().toFile().getName().contains("gson") || file.getFileName().toFile().getName().contains("slf4j"))).findFirst();
assertThat(dep).isPresent();
assertThat(kernel.getClasspath().get(0)).contains(mvnDir);
dep.ifPresent(path -> {
try {
FileUtils.forceDelete(path.toFile());
} catch (IOException e) {
e.printStackTrace();
}
});
}
use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class CodeFactoryTest method shouldBuildCodeWithMagicCommandInsideIfStatement.
@Test
public void shouldBuildCodeWithMagicCommandInsideIfStatement() {
// given
String codeAsString = "" + "println(1)\n" + "if(true){\n" + " %time println(221)\n" + "}\n" + "println(2)\n" + " %time 1+2";
// when
Code code = CodeFactory.create(codeAsString, new Message(), kernel);
// then
assertThat(code.getCodeFrames().size()).isEqualTo(4);
}
use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class CodeFactoryTest method shouldBuildCodeWithIfStatement.
@Test
public void shouldBuildCodeWithIfStatement() {
// given
String codeAsString = "" + "println(1)\n" + "%time 1+1\n" + "if(true){\n" + " println(2)\n" + "}\n" + "println(3)\n" + "%time 1+2\n" + "println(4)\n";
// when
Code code = CodeFactory.create(codeAsString, new Message(), kernel);
// then
assertThat(code.getCodeFrames().size()).isEqualTo(5);
}
Aggregations