Esempio n. 1
0
 def test_cycle(self):
     notebook = Notebook(
         cells=[Cell(code='a = b + 0'),
                Cell(code='b = a - 1')])
     notebook.run()
     assert notebook.cells[0].output == CycleError(notebook.cells)
     assert notebook.cells[1].output == CycleError(notebook.cells)
Esempio n. 2
0
 def test_error_propagation(self):
     notebook = Notebook(cells=[
         Cell(code='a = b + 0'),
         Cell(code='b = a - 1'),
         Cell(code='c = a + b')
     ])
     notebook.run()
     assert notebook.cells[0].output == CycleError(notebook.cells[:2])
     assert notebook.cells[1].output == CycleError(notebook.cells[:2])
     assert isinstance(notebook.cells[2].output, NameError)
Esempio n. 3
0
def from_file_format(file_format):
    assert intro_message in file_format
    no_intro = file_format.replace(intro_message, '')
    cell_info, order_info = no_intro.split(cell_order_header)
    cell_blocks = split_cell_blocks(cell_info)
    cell_ids = order_info.replace(cell_prefix, '').splitlines()[1:]
    assert len(cell_blocks) == len(cell_ids)
    return Notebook(cells=[Cell(id=cell_id, code=cell_blocks[cell_id]) for cell_id in cell_ids])
 def test_multiple_definition(self):
     notebook = Notebook(cells=[Cell(code='a = 0'), Cell(code='a = 1')])
     remake = Notebook.from_file_format(notebook.to_file_format())
     assert remake.cells == notebook.cells
 def test_cycle(self):
     notebook = Notebook(
         cells=[Cell(code='a = b - 0'),
                Cell(code='b = a + 1')])
     remake = Notebook.from_file_format(notebook.to_file_format())
     assert remake.cells == notebook.cells
 def test_format_stability(self):
     notebook = Notebook(cells=[Cell(code='a = 0'), Cell(code='b = a + 1')])
     remake = Notebook.from_file_format(notebook.to_file_format())
     assert remake.to_file_format() == notebook.to_file_format()
 def test_one_cell(self):
     notebook = Notebook(cells=[Cell(code='2 ** 5')])
     remake = Notebook.from_file_format(notebook.to_file_format())
     assert remake.cells == notebook.cells
Esempio n. 8
0
 def test_rerun(self):
     notebook = Notebook(cells=[Cell(code='a = 0'), Cell(code='b = a + 1')])
     notebook.run()
     notebook.run(cells={notebook.cells[0]: 'a = 17'})
     assert notebook.cells[0].output == {'a': 17}
     assert notebook.cells[1].output == {'b': 18}
Esempio n. 9
0
 def test_reverse(self):
     notebook = Notebook(cells=[Cell(code='b = a * 0'), Cell(code='a = 1')])
     notebook.run()
     assert notebook.cells[0].output == {'b': 0}
     assert notebook.cells[1].output == {'a': 1}