Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eea7980

Browse files
smithj1smithj1
authored andcommitted
Add unit test for ConvertRST.render_heading method
Conflicts: tests/test_simple.py
1 parent 5a47132 commit eea7980

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

tests/test_simple.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import glob
6+
from IPython.nbformat import current as nbformat
67

78
fname = 'tests/test.ipynb'
89
out_fname = 'tests/test.rst'
@@ -13,18 +14,44 @@ def clean_dir():
1314
map(os.remove, glob.glob("./tests/*.rst"))
1415
map(os.remove, glob.glob("./tests/*.png"))
1516

16-
1717
@nt.with_setup(clean_dir, clean_dir)
1818
def test_simple():
1919
c = ConverterRST(fname)
2020
f = c.render()
2121
nt.assert_true('rst' in f, 'changed file extension to rst')
2222

23-
2423
@nt.with_setup(clean_dir, clean_dir)
2524
def test_main():
2625
"""
2726
Test main entry point
2827
"""
2928
main(fname)
3029
nt.assert_true(os.path.exists(out_fname))
30+
31+
def test_render_heading():
32+
""" Unit test for cell type "heading" """
33+
# Generate and test heading cells level 1-6
34+
for level in xrange(1,7):
35+
cell = {
36+
'cell_type': 'heading',
37+
'level' : level,
38+
'source' : ['Test for heading type H{0}'.format(level)]
39+
}
40+
# Convert cell dictionaries to NotebookNode
41+
cell_nb = nbformat.NotebookNode(cell)
42+
# Make sure "source" attribute is uniconde not list.
43+
# For some reason, creating a NotebookNode manually like
44+
# this isn't converting source to a string like using
45+
# the create-from-file routine.
46+
if type(cell_nb.source) is list:
47+
cell_nb.source = '\n'.join(cell_nb.source)
48+
# Render to rst
49+
c = ConverterRST('')
50+
rst_list = c.render_heading(cell_nb)
51+
nt.assert_is_instance(rst_list,list) # render should return a list
52+
rst_str = "".join(rst_list)
53+
# Confirm rst content
54+
heading_level = {1:'=', 2:'-', 3:'`', 4:'\'', 5:'.',6:'~'}
55+
chk_str = "Test for heading type H{0}\n{1}\n".format(
56+
level,heading_level[level]*24)
57+
nt.assert_equal(rst_str,chk_str)

0 commit comments

Comments
 (0)