def test_pretty_print_code_cell(): cell = v4.new_code_cell(source='def foo():\n return 4', execution_count=3, outputs=[ v4.new_output('stream', name='stdout', text='some\ntext'), v4.new_output('display_data', {'text/plain': 'hello display'}), ]) config = TestConfig() pp.pretty_print_value_at(cell, "/cells/0", "+", config) text = config.out.getvalue() lines = text.splitlines() assert lines == [ '+code cell:', '+ execution_count: 3', '+ source:', '+ def foo():', '+ return 4', '+ outputs:', '+ output 0:', '+ output_type: stream', '+ name: stdout', '+ text:', '+ some', '+ text', '+ output 1:', '+ output_type: display_data', '+ data:', '+ text/plain: hello display', ]
def test_pretty_print_code_cell(): cell = v4.new_code_cell(source='def foo():\n return 4', execution_count=3, outputs=[ v4.new_output('stream', name='stdout', text='some\ntext'), v4.new_output('display_data', {'text/plain': 'hello display'}), ] ) io = StringIO() pp.pretty_print_value_at(cell, "/cells/0", "+", io) text = io.getvalue() lines = text.splitlines() assert lines == [ '+code cell:', '+ execution_count: 3', '+ source:', '+ def foo():', '+ return 4', '+ outputs:', '+ output 0:', '+ output_type: stream', '+ name: stdout', '+ text:', '+ some', '+ text', '+ output 1:', '+ output_type: display_data', '+ data:', '+ text/plain: hello display', ]
def test_pretty_print_multiline_string_short(): ins = 'short string' prefix = '+' config = TestConfig() pp.pretty_print_value_at(ins, "no/addr", prefix, config) text = config.out.getvalue() lines = text.splitlines(False) assert lines == [prefix + ins]
def test_pretty_print_multiline_string_short(): ins = 'short string' prefix = '+' io = StringIO() pp.pretty_print_value_at(ins, "no/addr", prefix, io) text = io.getvalue() lines = text.splitlines(False) assert lines == [prefix + ins]
def test_pretty_print_markdown_cell(): cell = v4.new_markdown_cell(source='# Heading\n\n*some markdown*') config = TestConfig() pp.pretty_print_value_at(cell, "/cells/0", "+", config) text = config.out.getvalue() lines = text.splitlines() assert lines[0] == '+markdown cell:' assert all(line.startswith('+') for line in lines if line) assert 'source:' in text assert '+ # Heading' in text assert '+ ' in lines assert '+ *some markdown*' in text
def test_pretty_print_markdown_cell(): cell = v4.new_markdown_cell(source='# Heading\n\n*some markdown*') io = StringIO() pp.pretty_print_value_at(cell, "/cells/0", "+", io) text = io.getvalue() lines = text.splitlines() assert lines[0] == '+markdown cell:' assert all(line.startswith('+') for line in lines if line) assert 'source:' in text assert '+ # Heading' in text assert '+ ' in lines assert '+ *some markdown*' in text
def test_pretty_print_stream_output(): output = v4.new_output('stream', name='stdout', text='some\ntext') config = TestConfig() pp.pretty_print_value_at(output, "/cells/2/outputs/3", "+", config) text = config.out.getvalue() lines = text.splitlines() assert lines == [ '+output:', '+ output_type: stream', "+ name: stdout", "+ text:", "+ some", "+ text", ]
def test_pretty_print_stream_output(): output = v4.new_output('stream', name='stdout', text='some\ntext') io = StringIO() pp.pretty_print_value_at(output, "/cells/2/outputs/3", "+", io) text = io.getvalue() lines = text.splitlines() assert lines == [ '+output:', '+ output_type: stream', "+ name: stdout", "+ text:", "+ some", "+ text", ]
def test_pretty_print_display_data(): output = v4.new_output('display_data', { 'text/plain': 'text', 'image/png': b64text(1024), }) config = TestConfig() pp.pretty_print_value_at(output, "/cells/1/outputs/2", "+", config) text = config.out.getvalue() lines = text.splitlines() assert 'output_type: display_data' in text assert len(text) < 500 assert 'snip base64' in text assert 'image/png' in text assert "text/plain: text" in text assert all(line.startswith('+') for line in lines if line)
def test_pretty_print_display_data(): output = v4.new_output('display_data', { 'text/plain': 'text', 'image/png': b64text(1024), }) io = StringIO() pp.pretty_print_value_at(output, "/cells/1/outputs/2", "+", io) text = io.getvalue() lines = text.splitlines() assert 'output_type: display_data' in text assert len(text) < 500 assert 'snip base64' in text assert 'image/png' in text assert "text/plain: text" in text assert all(line.startswith('+') for line in lines if line)
def _pretty_print(value, prefix="+", path="/dummypath"): config = TestConfig() pp.pretty_print_value_at(value, path, prefix, config) text = config.out.getvalue() return text
def _pretty_print(value, prefix="+", path="/dummypath"): io = StringIO() pp.pretty_print_value_at(value, path, prefix, io) text = io.getvalue() return text