test_nbbase.py
82 lines
| 2.8 KiB
| text/x-python
|
PythonLexer
Brian E. Granger
|
r4401 | from unittest import TestCase | ||
Brian E. Granger
|
r4406 | from ..nbbase import ( | ||
Brian E. Granger
|
r4401 | NotebookNode, | ||
Brian E. Granger
|
r4511 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output | ||
Brian E. Granger
|
r4401 | ) | ||
class TestCell(TestCase): | ||||
def test_empty_code_cell(self): | ||||
cc = new_code_cell() | ||||
self.assertEquals(cc.cell_type,'code') | ||||
self.assertEquals('input' not in cc, True) | ||||
self.assertEquals('prompt_number' not in cc, True) | ||||
Brian E. Granger
|
r4402 | self.assertEquals(cc.outputs, []) | ||
Brian E. Granger
|
r4533 | self.assertEquals(cc.collapsed, False) | ||
Brian E. Granger
|
r4401 | |||
def test_code_cell(self): | ||||
Brian E. Granger
|
r4533 | cc = new_code_cell(input='a=10', prompt_number=0, collapsed=True) | ||
Brian E. Granger
|
r4498 | cc.outputs = [new_output(output_type='pyout', | ||
output_svg='foo',output_text='10',prompt_number=0)] | ||||
Brian E. Granger
|
r4401 | self.assertEquals(cc.input, u'a=10') | ||
self.assertEquals(cc.prompt_number, 0) | ||||
Brian E. Granger
|
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
|
r4498 | self.assertEquals(cc.outputs[0].prompt_number, 0) | ||
Brian E. Granger
|
r4533 | self.assertEquals(cc.collapsed, True) | ||
Brian E. Granger
|
r4401 | |||
Brian E. Granger
|
r4498 | def test_empty_html_cell(self): | ||
Brian E. Granger
|
r4511 | tc = new_text_cell(u'html') | ||
self.assertEquals(tc.cell_type, u'html') | ||||
Brian E. Granger
|
r4498 | self.assertEquals('source' not in tc, True) | ||
Brian E. Granger
|
r4511 | self.assertEquals('rendered' not in tc, True) | ||
Brian E. Granger
|
r4401 | |||
Brian E. Granger
|
r4498 | def test_html_cell(self): | ||
Brian E. Granger
|
r4511 | tc = new_text_cell(u'html', 'hi', 'hi') | ||
Brian E. Granger
|
r4498 | self.assertEquals(tc.source, u'hi') | ||
Brian E. Granger
|
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') | ||||
self.assertEquals('source' not in tc, True) | ||||
self.assertEquals('rendered' not in tc, True) | ||||
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
|
r4401 | |||
class TestWorksheet(TestCase): | ||||
def test_empty_worksheet(self): | ||||
ws = new_worksheet() | ||||
self.assertEquals(ws.cells,[]) | ||||
self.assertEquals('name' not in ws, True) | ||||
def test_worksheet(self): | ||||
Brian E. Granger
|
r4511 | cells = [new_code_cell(), new_text_cell(u'html')] | ||
Brian E. Granger
|
r4401 | ws = new_worksheet(cells=cells,name='foo') | ||
self.assertEquals(ws.cells,cells) | ||||
self.assertEquals(ws.name,u'foo') | ||||
class TestNotebook(TestCase): | ||||
def test_empty_notebook(self): | ||||
nb = new_notebook() | ||||
self.assertEquals('id' in nb, True) | ||||
self.assertEquals(nb.worksheets, []) | ||||
self.assertEquals('name' not in nb, True) | ||||
Brian E. Granger
|
r4406 | self.assertEquals(nb.nbformat,2) | ||
Brian E. Granger
|
r4401 | |||
Brian E. Granger
|
r4406 | def test_notebook(self): | ||
Brian E. Granger
|
r4401 | worksheets = [new_worksheet(),new_worksheet()] | ||
nb = new_notebook(name='foo',worksheets=worksheets) | ||||
self.assertEquals(nb.name,u'foo') | ||||
self.assertEquals(nb.worksheets,worksheets) | ||||
Brian E. Granger
|
r4406 | self.assertEquals(nb.nbformat,2) | ||
Brian E. Granger
|
r4401 | |||