33
44import os
55import glob
6+ from IPython .nbformat import current as nbformat
67
78fname = 'tests/test.ipynb'
89out_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 )
1818def 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 )
2524def 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