##// END OF EJS Templates
Merge pull request #1490 from minrk/raw...
Merge pull request #1490 from minrk/raw rename plaintext cell -> raw cell Raw cells should be *untransformed* when writing various output formats, as the point of them is to let users pass through IPython to their rendered document format (rst, latex, etc.). This is different from what is the logical meaning of 'plaintext', which would suggest that the contents should be preserved as unformatted plaintext (e.g. in a `<pre>` tag, or literal block). In the UI, these cells will be displayed as 'Raw Text'. WARNING: any existing v3 notebooks which use plaintext cells, when read in by versions after this merge, will silently rename those cells to 'raw'. But if such a notebook is uploaded into a pre-merge IPython, cells labeled as 'raw' will simply *not be displayed*.

File last commit:

r6480:a0e0f391 merge
r6480:a0e0f391 merge
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()
Brian E. Granger
Implemented metadata for notebook format.
r4637 self.assertEquals(cc.cell_type,u'code')
self.assertEquals(u'input' not in cc, True)
self.assertEquals(u'prompt_number' not in cc, True)
Brian E. Granger
Updates to basic notebook format....
r4402 self.assertEquals(cc.outputs, [])
Brian E. Granger
Added collapsed field to the code cell.
r4533 self.assertEquals(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)]
Brian E. Granger
Initial draft of more formal notebook format....
r4401 self.assertEquals(cc.input, u'a=10')
self.assertEquals(cc.prompt_number, 0)
Brian E. Granger
Updates to basic notebook format....
r4402 self.assertEquals(cc.language, u'python')
self.assertEquals(cc.outputs[0].svg, u'foo')
self.assertEquals(cc.outputs[0].text, u'10')
Brian E. Granger
Starting to rename text cell to html cell.
r4498 self.assertEquals(cc.outputs[0].prompt_number, 0)
Brian E. Granger
Added collapsed field to the code cell.
r4533 self.assertEquals(cc.collapsed, True)
Brian E. Granger
Adding tracebacks, evalue and etype to the nbformat and notebook.
r4540 def test_pyerr(self):
o = new_output(output_type=u'pyerr', etype=u'NameError',
evalue=u'Name not found', traceback=[u'frame 0', u'frame 1', u'frame 2']
)
self.assertEquals(o.output_type, u'pyerr')
self.assertEquals(o.etype, u'NameError')
self.assertEquals(o.evalue, u'Name not found')
self.assertEquals(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')
self.assertEquals(tc.cell_type, u'html')
Brian E. Granger
Implemented metadata for notebook format.
r4637 self.assertEquals(u'source' not in tc, True)
self.assertEquals(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')
Brian E. Granger
Starting to rename text cell to html cell.
r4498 self.assertEquals(tc.source, u'hi')
Brian E. Granger
Markdown cells are now saved and restored in notebooks.
r4511 self.assertEquals(tc.rendered, u'hi')
def test_empty_markdown_cell(self):
tc = new_text_cell(u'markdown')
self.assertEquals(tc.cell_type, u'markdown')
Brian E. Granger
Implemented metadata for notebook format.
r4637 self.assertEquals(u'source' not in tc, True)
self.assertEquals(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')
self.assertEquals(tc.source, u'hi')
self.assertEquals(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')
self.assertEquals(tc.cell_type, u'raw')
Brian Granger
Adding rst and heading cells to the notebook format.
r6016 self.assertEquals(u'source' not in tc, True)
self.assertEquals(u'rendered' not in tc, True)
MinRK
rename plaintext cell -> raw cell
r6248 def test_raw_cell(self):
tc = new_text_cell(u'raw', 'hi', 'hi')
Brian Granger
Adding rst and heading cells to the notebook format.
r6016 self.assertEquals(tc.source, u'hi')
self.assertEquals(tc.rendered, u'hi')
def test_empty_heading_cell(self):
tc = new_heading_cell()
self.assertEquals(tc.cell_type, u'heading')
self.assertEquals(u'source' not in tc, True)
Brian Granger
Minor changes to heading cell in nbformat.
r6020 self.assertEquals(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)
self.assertEquals(tc.source, u'hi')
self.assertEquals(tc.rendered, u'hi')
Brian Granger
Adding rst and heading cells to the notebook format.
r6016 self.assertEquals(tc.level, 2)
Brian E. Granger
Initial draft of more formal notebook format....
r4401
class TestWorksheet(TestCase):
def test_empty_worksheet(self):
ws = new_worksheet()
self.assertEquals(ws.cells,[])
Brian E. Granger
Implemented metadata for notebook format.
r4637 self.assertEquals(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')
Brian E. Granger
Initial draft of more formal notebook format....
r4401 self.assertEquals(ws.cells,cells)
self.assertEquals(ws.name,u'foo')
class TestNotebook(TestCase):
def test_empty_notebook(self):
nb = new_notebook()
self.assertEquals(nb.worksheets, [])
Brian E. Granger
Implemented metadata for notebook format.
r4637 self.assertEquals(nb.metadata, NotebookNode())
Brian Granger
Fixing minor issues with nbformat....
r6048 self.assertEquals(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)
self.assertEquals(nb.metadata.name,u'foo')
Brian E. Granger
Initial draft of more formal notebook format....
r4401 self.assertEquals(nb.worksheets,worksheets)
MinRK
allow name as kwarg to new_notebook...
r6207 self.assertEquals(nb.nbformat,nbformat)
def test_notebook_name(self):
worksheets = [new_worksheet(),new_worksheet()]
nb = new_notebook(name='foo',worksheets=worksheets)
self.assertEquals(nb.metadata.name,u'foo')
self.assertEquals(nb.worksheets,worksheets)
Brian Granger
Fixing minor issues with nbformat....
r6048 self.assertEquals(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()
self.assertEquals(u'name' not in md, True)
self.assertEquals(u'authors' not in md, True)
self.assertEquals(u'license' not in md, True)
self.assertEquals(u'saved' not in md, True)
self.assertEquals(u'modified' not in md, True)
self.assertEquals(u'gistid' not in md, True)
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)
self.assertEquals(md.name, u'foo')
self.assertEquals(md.license, u'BSD')
self.assertEquals(md.created, u'today')
self.assertEquals(md.modified, u'now')
self.assertEquals(md.gistid, u'21341231')
self.assertEquals(md.authors, authors)