use of org.jetbrains.plugins.ipnb.format.IpnbFile in project intellij-community by JetBrains.
the class CellOperationTest method testRemoveCell.
public void testRemoveCell() throws IOException {
final String fileName = "testData/emptyFile.ipynb";
final String fileText = IpnbTestCase.getFileText(fileName);
final IpnbFile ipnbFile = IpnbParser.parseIpnbFile(fileText, new LightVirtualFile());
ipnbFile.addCell(IpnbCodeCell.createEmptyCodeCell(), ipnbFile.getCells().size());
ipnbFile.removeCell(ipnbFile.getCells().size() - 1);
assertEquals(fileText, IpnbTestCase.getFileText(fileName));
}
use of org.jetbrains.plugins.ipnb.format.IpnbFile in project intellij-community by JetBrains.
the class JsonParserTest method testOutputs.
public void testOutputs() throws IOException {
final String fileName = "testData/outputs.ipynb";
final String fileText = IpnbTestCase.getFileText(fileName);
final IpnbFile ipnbFile = IpnbParser.parseIpnbFile(fileText, new LightVirtualFile());
assertNotNull(ipnbFile);
final List<IpnbCell> cells = ipnbFile.getCells();
assertEquals(1, cells.size());
final IpnbCell cell = cells.get(0);
assertTrue(cell instanceof IpnbCodeCell);
final List<IpnbOutputCell> outputs = ((IpnbCodeCell) cell).getCellOutputs();
assertEquals(1, outputs.size());
final IpnbOutputCell output = outputs.get(0);
final List<String> text = output.getText();
assertNotNull(text);
final String joined = StringUtil.join(text, "");
assertEquals("\"Add(Symbol('x'), Mul(Integer(2), Symbol('y')))\"", joined);
}
use of org.jetbrains.plugins.ipnb.format.IpnbFile in project intellij-community by JetBrains.
the class JsonParserTest method testCodeCell.
public void testCodeCell() throws IOException {
final String fileName = "testData/code.ipynb";
final String fileText = IpnbTestCase.getFileText(fileName);
final IpnbFile ipnbFile = IpnbParser.parseIpnbFile(fileText, new LightVirtualFile());
assertNotNull(ipnbFile);
final List<IpnbCell> cells = ipnbFile.getCells();
assertEquals(1, cells.size());
final IpnbCell cell = cells.get(0);
assertTrue(cell instanceof IpnbCodeCell);
final List<IpnbOutputCell> outputs = ((IpnbCodeCell) cell).getCellOutputs();
assertEquals(0, outputs.size());
final List<String> source = ((IpnbCodeCell) cell).getSource();
final String joined = StringUtil.join(source, "");
assertEquals("e = x + 2*y", joined);
final String language = ((IpnbCodeCell) cell).getLanguage();
assertEquals("python", language);
final Integer number = ((IpnbCodeCell) cell).getPromptNumber();
assertEquals(new Integer(4), number);
}
use of org.jetbrains.plugins.ipnb.format.IpnbFile in project intellij-community by JetBrains.
the class JsonParserTest method testMarkdownCell.
public void testMarkdownCell() throws IOException {
final String fileName = "testData/markdown.ipynb";
final String fileText = IpnbTestCase.getFileText(fileName);
final IpnbFile ipnbFile = IpnbParser.parseIpnbFile(fileText, new LightVirtualFile());
assertNotNull(ipnbFile);
final List<IpnbCell> cells = ipnbFile.getCells();
assertEquals(1, cells.size());
final IpnbCell cell = cells.get(0);
assertTrue(cell instanceof IpnbMarkdownCell);
final List<String> source = ((IpnbMarkdownCell) cell).getSource();
final String joined = StringUtil.join(source, "");
assertEquals("<img src=\"images/ipython_logo.png\">", joined);
}
use of org.jetbrains.plugins.ipnb.format.IpnbFile in project intellij-community by JetBrains.
the class CellOperationTest method testAddCell.
public void testAddCell() throws IOException {
final String fileName = "testData/emptyFile.ipynb";
final String fileText = IpnbTestCase.getFileText(fileName);
final IpnbFile ipnbFile = IpnbParser.parseIpnbFile(fileText, new LightVirtualFile());
ipnbFile.addCell(IpnbCodeCell.createEmptyCodeCell(), ipnbFile.getCells().size());
final IpnbCodeCell cell = (IpnbCodeCell) ipnbFile.getCells().get(ipnbFile.getCells().size() - 1);
assertTrue(cell.getCellOutputs().isEmpty());
assertNull(cell.getPromptNumber());
assertTrue(cell.getMetadata().isEmpty());
}
Aggregations