def test_code_cell_with_outputs(): cell = new_code_cell( execution_count=10, outputs=[ new_output("display_data", mimebundle), new_output("stream", text="hello"), new_output("execute_result", mimebundle, execution_count=10), ], ) assert cell.execution_count == 10 assert len(cell.outputs) == 3 er = cell.outputs[-1] assert er.execution_count == 10 assert er["output_type"] == "execute_result"
def test_error(): o = new_output( output_type="error", ename="NameError", evalue="Name not found", traceback=["frame 0", "frame 1", "frame 2"], ) assert o.output_type == "error" assert o.ename == "NameError" assert o.evalue == "Name not found" assert o.traceback == ["frame 0", "frame 1", "frame 2"]
def notebook_with_outputs(): return new_notebook( cells=[ new_code_cell( "1+1", execution_count=1, outputs=[ new_output( data={"text/plain": ["2"]}, execution_count=1, output_type="execute_result", ) ], ) ], metadata={ "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python_kernel", } }, )
def test_execute_result(): output = new_output("execute_result", mimebundle, execution_count=10) assert output.execution_count == 10 for key, expected in mimebundle.items(): assert output.data[key] == expected
def test_display_data(): output = new_output("display_data", mimebundle) for key, expected in mimebundle.items(): assert output.data[key] == expected
def test_empty_execute_result(): output = new_output("execute_result", execution_count=1) assert output.output_type == "execute_result"
def test_empty_stream(): output = new_output("stream") assert output.output_type == "stream" assert output.name == "stdout" assert output.text == ""
def test_empty_display_data(): output = new_output("display_data") assert output.output_type == "display_data"
def test_stream(): output = new_output("stream", name="stderr", text="hello there") assert output.name == "stderr" assert output.text == "hello there"
def create_cell_output(**output): if output: output = nbbase.new_output(**output) return output else: return
source="a = 10\nb = 5", execution_count=4, ) ) cells.append( new_code_cell( source="json_outputs()", execution_count=12, outputs=[ new_output( output_type="display_data", data={ "text/plain": "<json outputs>", "application/json": {"key": "value", "x": 5, "lis": [1, 2, "x"]}, "application/vnd.listofstr+json": ["a", "b", "c"], "application/vnd.numbers+json": [1, 2, 3], "application/vnd.number+json": 42, "application/vnd.object+json": {"number": 5, "array": [1, 2], "str": "x"}, "application/vnd.string+json": "ok", }, ) ], ) ) cells.append( new_code_cell( source='print "ünîcødé"', execution_count=3, outputs=[ new_output(