source
Cell
def Cell(
kernel, code_w_magics, silent:bool=False
):
A class for managing execution of a single code cell
Some Cell functionality can be tested apart from a kernel:
from nbstata.config import launch_stata, Config
from fastcore.test import test_eq
from textwrap import dedent
from unittest.mock import Mock
kernel1 = Mock()
kernel1.nbstata_config = Config()
code_w_magics = '''disp "test output"'''
cell1 = Cell(kernel1, code_w_magics)
cell1.code
launch_stata(splash=False)
kernel1.stata_session = StataSession()
cell1a = Cell(kernel1, code_w_magics)
cell1a.run()
code_w_magics = dedent('''\
*%%quietly
disp "test output"
''')
cell2 = Cell(kernel1, code_w_magics)
test_eq(cell2.quietly, True)
kernel1.nbstata_config.env['echo'] = 'True'
code_w_magics = '''disp "test output"'''
cell3 = Cell(kernel1, code_w_magics)
test_eq(cell3.noecho, False)
. disp "test output"
test output
code_w_magics = dedent('''\
*%%noecho
#delimit cr
disp "test output"
''')
cell4 = Cell(kernel1, code_w_magics)
test_eq(cell4.noecho, True)