##// END OF EJS Templates
Add nbconvert dependencies to TravisCI config
Add nbconvert dependencies to TravisCI config

File last commit:

r10233:7be1cf4e
r11498:5440fd38
Show More
test_nbbase.py
143 lines | 5.3 KiB | text/x-python | PythonLexer
Brian E. Granger
Initial draft of more formal notebook format....
r4401 from unittest import TestCase
Brian E. Granger
Full versioning added to nbformat.
r4406 from ..nbbase import (
Brian E. Granger
Initial draft of more formal notebook format....
r4401 NotebookNode,
Brian E. Granger
Implemented metadata for notebook format.
r4637 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output,
Brian Granger
Fixing minor issues with nbformat....
r6048 new_author, new_metadata, new_heading_cell, nbformat
Brian E. Granger
Initial draft of more formal notebook format....
r4401 )
class TestCell(TestCase):
def test_empty_code_cell(self):
cc = new_code_cell()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(cc.cell_type,u'code')
self.assertEqual(u'input' not in cc, True)
self.assertEqual(u'prompt_number' not in cc, True)
self.assertEqual(cc.outputs, [])
self.assertEqual(cc.collapsed, False)
Brian E. Granger
Initial draft of more formal notebook format....
r4401
def test_code_cell(self):
Brian E. Granger
Added collapsed field to the code cell.
r4533 cc = new_code_cell(input='a=10', prompt_number=0, collapsed=True)
Brian E. Granger
Implemented metadata for notebook format.
r4637 cc.outputs = [new_output(output_type=u'pyout',
output_svg=u'foo',output_text=u'10',prompt_number=0)]
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(cc.input, u'a=10')
self.assertEqual(cc.prompt_number, 0)
self.assertEqual(cc.language, u'python')
self.assertEqual(cc.outputs[0].svg, u'foo')
self.assertEqual(cc.outputs[0].text, u'10')
self.assertEqual(cc.outputs[0].prompt_number, 0)
self.assertEqual(cc.collapsed, True)
Brian E. Granger
Added collapsed field to the code cell.
r4533
Brian E. Granger
Adding tracebacks, evalue and etype to the nbformat and notebook.
r4540 def test_pyerr(self):
Maxim Grechkin
Notebook actually gets and holds ename, not etype
r10233 o = new_output(output_type=u'pyerr', ename=u'NameError',
Brian E. Granger
Adding tracebacks, evalue and etype to the nbformat and notebook.
r4540 evalue=u'Name not found', traceback=[u'frame 0', u'frame 1', u'frame 2']
)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(o.output_type, u'pyerr')
Maxim Grechkin
Notebook actually gets and holds ename, not etype
r10233 self.assertEqual(o.ename, u'NameError')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(o.evalue, u'Name not found')
self.assertEqual(o.traceback, [u'frame 0', u'frame 1', u'frame 2'])
Brian E. Granger
Initial draft of more formal notebook format....
r4401
Brian E. Granger
Starting to rename text cell to html cell.
r4498 def test_empty_html_cell(self):
Brian E. Granger
Markdown cells are now saved and restored in notebooks.
r4511 tc = new_text_cell(u'html')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(tc.cell_type, u'html')
self.assertEqual(u'source' not in tc, True)
self.assertEqual(u'rendered' not in tc, True)
Brian E. Granger
Initial draft of more formal notebook format....
r4401
Brian E. Granger
Starting to rename text cell to html cell.
r4498 def test_html_cell(self):
Brian E. Granger
Markdown cells are now saved and restored in notebooks.
r4511 tc = new_text_cell(u'html', 'hi', 'hi')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(tc.source, u'hi')
self.assertEqual(tc.rendered, u'hi')
Brian E. Granger
Markdown cells are now saved and restored in notebooks.
r4511
def test_empty_markdown_cell(self):
tc = new_text_cell(u'markdown')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(tc.cell_type, u'markdown')
self.assertEqual(u'source' not in tc, True)
self.assertEqual(u'rendered' not in tc, True)
Brian E. Granger
Markdown cells are now saved and restored in notebooks.
r4511
def test_markdown_cell(self):
tc = new_text_cell(u'markdown', 'hi', 'hi')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(tc.source, u'hi')
self.assertEqual(tc.rendered, u'hi')
Brian E. Granger
Initial draft of more formal notebook format....
r4401
MinRK
rename plaintext cell -> raw cell
r6248 def test_empty_raw_cell(self):
tc = new_text_cell(u'raw')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(tc.cell_type, u'raw')
self.assertEqual(u'source' not in tc, True)
self.assertEqual(u'rendered' not in tc, True)
Brian Granger
Adding rst and heading cells to the notebook format.
r6016
MinRK
rename plaintext cell -> raw cell
r6248 def test_raw_cell(self):
tc = new_text_cell(u'raw', 'hi', 'hi')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(tc.source, u'hi')
self.assertEqual(tc.rendered, u'hi')
Brian Granger
Adding rst and heading cells to the notebook format.
r6016
def test_empty_heading_cell(self):
tc = new_heading_cell()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(tc.cell_type, u'heading')
self.assertEqual(u'source' not in tc, True)
self.assertEqual(u'rendered' not in tc, True)
Brian Granger
Adding rst and heading cells to the notebook format.
r6016
def test_heading_cell(self):
Brian Granger
Minor changes to heading cell in nbformat.
r6020 tc = new_heading_cell(u'hi', u'hi', level=2)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(tc.source, u'hi')
self.assertEqual(tc.rendered, u'hi')
self.assertEqual(tc.level, 2)
Brian Granger
Adding rst and heading cells to the notebook format.
r6016
Brian E. Granger
Initial draft of more formal notebook format....
r4401
class TestWorksheet(TestCase):
def test_empty_worksheet(self):
ws = new_worksheet()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(ws.cells,[])
self.assertEqual(u'name' not in ws, True)
Brian E. Granger
Initial draft of more formal notebook format....
r4401
def test_worksheet(self):
Brian E. Granger
Markdown cells are now saved and restored in notebooks.
r4511 cells = [new_code_cell(), new_text_cell(u'html')]
Brian E. Granger
Implemented metadata for notebook format.
r4637 ws = new_worksheet(cells=cells,name=u'foo')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(ws.cells,cells)
self.assertEqual(ws.name,u'foo')
Brian E. Granger
Initial draft of more formal notebook format....
r4401
class TestNotebook(TestCase):
def test_empty_notebook(self):
nb = new_notebook()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(nb.worksheets, [])
self.assertEqual(nb.metadata, NotebookNode())
self.assertEqual(nb.nbformat,nbformat)
Brian E. Granger
Initial draft of more formal notebook format....
r4401
Brian E. Granger
Full versioning added to nbformat.
r4406 def test_notebook(self):
Brian E. Granger
Initial draft of more formal notebook format....
r4401 worksheets = [new_worksheet(),new_worksheet()]
Brian E. Granger
Implemented metadata for notebook format.
r4637 metadata = new_metadata(name=u'foo')
nb = new_notebook(metadata=metadata,worksheets=worksheets)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(nb.metadata.name,u'foo')
self.assertEqual(nb.worksheets,worksheets)
self.assertEqual(nb.nbformat,nbformat)
MinRK
allow name as kwarg to new_notebook...
r6207
def test_notebook_name(self):
worksheets = [new_worksheet(),new_worksheet()]
nb = new_notebook(name='foo',worksheets=worksheets)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(nb.metadata.name,u'foo')
self.assertEqual(nb.worksheets,worksheets)
self.assertEqual(nb.nbformat,nbformat)
Brian E. Granger
Initial draft of more formal notebook format....
r4401
Brian E. Granger
Implemented metadata for notebook format.
r4637 class TestMetadata(TestCase):
def test_empty_metadata(self):
md = new_metadata()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(u'name' not in md, True)
self.assertEqual(u'authors' not in md, True)
self.assertEqual(u'license' not in md, True)
self.assertEqual(u'saved' not in md, True)
self.assertEqual(u'modified' not in md, True)
self.assertEqual(u'gistid' not in md, True)
Brian E. Granger
Implemented metadata for notebook format.
r4637
def test_metadata(self):
authors = [new_author(name='Bart Simpson',email='bsimpson@fox.com')]
md = new_metadata(name=u'foo',license=u'BSD',created=u'today',
modified=u'now',gistid=u'21341231',authors=authors)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(md.name, u'foo')
self.assertEqual(md.license, u'BSD')
self.assertEqual(md.created, u'today')
self.assertEqual(md.modified, u'now')
self.assertEqual(md.gistid, u'21341231')
self.assertEqual(md.authors, authors)
Brian E. Granger
Implemented metadata for notebook format.
r4637