Show More
@@ -3,6 +3,7 b' import nose.tools as nt' | |||||
3 |
|
3 | |||
4 | import os |
|
4 | import os | |
5 | import glob |
|
5 | import glob | |
|
6 | from IPython.nbformat import current as nbformat | |||
6 |
|
7 | |||
7 | fname = 'tests/test.ipynb' |
|
8 | fname = 'tests/test.ipynb' | |
8 | out_fname = 'tests/test.rst' |
|
9 | out_fname = 'tests/test.rst' | |
@@ -13,14 +14,12 b' def clean_dir():' | |||||
13 | map(os.remove, glob.glob("./tests/*.rst")) |
|
14 | map(os.remove, glob.glob("./tests/*.rst")) | |
14 | map(os.remove, glob.glob("./tests/*.png")) |
|
15 | map(os.remove, glob.glob("./tests/*.png")) | |
15 |
|
16 | |||
16 |
|
||||
17 | @nt.with_setup(clean_dir, clean_dir) |
|
17 | @nt.with_setup(clean_dir, clean_dir) | |
18 | def test_simple(): |
|
18 | def test_simple(): | |
19 | c = ConverterRST(fname) |
|
19 | c = ConverterRST(fname) | |
20 | f = c.render() |
|
20 | f = c.render() | |
21 | nt.assert_true('rst' in f, 'changed file extension to rst') |
|
21 | nt.assert_true('rst' in f, 'changed file extension to rst') | |
22 |
|
22 | |||
23 |
|
||||
24 | @nt.with_setup(clean_dir, clean_dir) |
|
23 | @nt.with_setup(clean_dir, clean_dir) | |
25 | def test_main(): |
|
24 | def test_main(): | |
26 | """ |
|
25 | """ | |
@@ -28,3 +27,31 b' def test_main():' | |||||
28 | """ |
|
27 | """ | |
29 | main(fname) |
|
28 | main(fname) | |
30 | nt.assert_true(os.path.exists(out_fname)) |
|
29 | 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) |
General Comments 0
You need to be logged in to leave comments.
Login now