##// END OF EJS Templates
Merge pull request #7435 from takluyver/test-latextools-unicode...
Merge pull request #7435 from takluyver/test-latextools-unicode Fix test for latextools under Python 2

File last commit:

r18596:2d590459
r19891:77ebedc4 merge
Show More
test_nbbase.py
101 lines | 3.2 KiB | text/x-python | PythonLexer
MinRK
first complete pass on v4...
r18573 # coding: utf-8
"""Tests for the Python API for composing notebook elements"""
MinRK
copy nbformat.v3 to v4
r18568
MinRK
first complete pass on v4...
r18573 import nose.tools as nt
MinRK
no longer need separate v4.compose...
r18575 from IPython.nbformat.validator import isvalid, validate, ValidationError
from ..nbbase import (
MinRK
first complete pass on v4...
r18573 NotebookNode, nbformat,
MinRK
remove heading cells in v4
r18596 new_code_cell, new_markdown_cell, new_notebook,
MinRK
first complete pass on v4...
r18573 new_output, new_raw_cell,
MinRK
copy nbformat.v3 to v4
r18568 )
MinRK
first complete pass on v4...
r18573 def test_empty_notebook():
nb = new_notebook()
nt.assert_equal(nb.cells, [])
nt.assert_equal(nb.metadata, NotebookNode())
nt.assert_equal(nb.nbformat, nbformat)
def test_empty_markdown_cell():
cell = new_markdown_cell()
nt.assert_equal(cell.cell_type, 'markdown')
nt.assert_equal(cell.source, '')
def test_markdown_cell():
cell = new_markdown_cell(u'* Søme markdown')
nt.assert_equal(cell.source, u'* Søme markdown')
def test_empty_raw_cell():
cell = new_raw_cell()
nt.assert_equal(cell.cell_type, u'raw')
nt.assert_equal(cell.source, '')
def test_raw_cell():
cell = new_raw_cell('hi')
nt.assert_equal(cell.source, u'hi')
def test_empty_code_cell():
cell = new_code_cell('hi')
nt.assert_equal(cell.cell_type, 'code')
nt.assert_equal(cell.source, u'hi')
def test_empty_display_data():
output = new_output('display_data')
nt.assert_equal(output.output_type, 'display_data')
def test_empty_stream():
MinRK
mv stream.stream > stream.name in nbformat.v4...
r18576 output = new_output('stream')
MinRK
first complete pass on v4...
r18573 nt.assert_equal(output.output_type, 'stream')
MinRK
mv stream.stream > stream.name in nbformat.v4...
r18576 nt.assert_equal(output.name, 'stdout')
nt.assert_equal(output.text, '')
MinRK
first complete pass on v4...
r18573
def test_empty_execute_result():
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 output = new_output('execute_result', execution_count=1)
MinRK
first complete pass on v4...
r18573 nt.assert_equal(output.output_type, 'execute_result')
mimebundle = {
'text/plain': "some text",
"application/json": {
"key": "value"
},
"image/svg+xml": 'ABCDEF',
"application/octet-stream": 'ABC-123',
"application/vnd.foo+bar": "Some other stuff",
}
def test_display_data():
output = new_output('display_data', mimebundle)
for key, expected in mimebundle.items():
MinRK
move mime-bundle data to rich output.data...
r18589 nt.assert_equal(output.data[key], expected)
MinRK
first complete pass on v4...
r18573
def test_execute_result():
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 output = new_output('execute_result', mimebundle, execution_count=10)
nt.assert_equal(output.execution_count, 10)
MinRK
first complete pass on v4...
r18573 for key, expected in mimebundle.items():
MinRK
move mime-bundle data to rich output.data...
r18589 nt.assert_equal(output.data[key], expected)
MinRK
first complete pass on v4...
r18573
def test_error():
o = new_output(output_type=u'error', ename=u'NameError',
evalue=u'Name not found', traceback=[u'frame 0', u'frame 1', u'frame 2']
)
nt.assert_equal(o.output_type, u'error')
nt.assert_equal(o.ename, u'NameError')
nt.assert_equal(o.evalue, u'Name not found')
nt.assert_equal(o.traceback, [u'frame 0', u'frame 1', u'frame 2'])
def test_code_cell_with_outputs():
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 cell = new_code_cell(execution_count=10, outputs=[
MinRK
first complete pass on v4...
r18573 new_output('display_data', mimebundle),
new_output('stream', text='hello'),
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 new_output('execute_result', mimebundle, execution_count=10),
MinRK
first complete pass on v4...
r18573 ])
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 nt.assert_equal(cell.execution_count, 10)
MinRK
first complete pass on v4...
r18573 nt.assert_equal(len(cell.outputs), 3)
er = cell.outputs[-1]
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 nt.assert_equal(er.execution_count, 10)
MinRK
first complete pass on v4...
r18573 nt.assert_equal(er['output_type'], 'execute_result')
MinRK
mv stream.stream > stream.name in nbformat.v4...
r18576
def test_stream():
output = new_output('stream', name='stderr', text='hello there')
nt.assert_equal(output.name, 'stderr')
nt.assert_equal(output.text, 'hello there')