cell

Class representing a single code cell

source

Cell

 Cell (kernel, code_w_magics, silent=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
'disp "test output"'
launch_stata(splash=False)
kernel1.stata_session = StataSession()
cell1a = Cell(kernel1, code_w_magics)
cell1a.run()
test output
code_w_magics = dedent('''\
    *%%quietly
    disp "test output"
    ''')
cell2 = Cell(kernel1, code_w_magics)
test_eq(cell2.quietly, True)
cell2.run()
kernel1.nbstata_config.env['echo'] = 'True'

code_w_magics = '''disp "test output"'''
cell3 = Cell(kernel1, code_w_magics)
test_eq(cell3.noecho, False)
cell3.run()
. 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)
cell4.run()
test output