Show More
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -1,46 +1,48 b'' | |||||
1 | import os |
|
1 | import os | |
2 | import io |
|
2 | import io | |
3 | import nose.tools as nt |
|
3 | import nose.tools as nt | |
4 |
from nbconvert import |
|
4 | from nbconvert import ( | |
|
5 | ConverterLaTeX, ConverterMarkdown, ConverterPy, ConverterHTML | |||
|
6 | ) | |||
5 | from nose.tools import nottest |
|
7 | from nose.tools import nottest | |
6 |
|
8 | |||
7 |
|
9 | |||
8 | def test_evens(): |
|
10 | def test_evens(): | |
9 |
###### |
|
11 | ###### | |
10 |
# for now, we don't need to really run inkscape to extract svg |
|
12 | # for now, we don't need to really run inkscape to extract svg | |
11 | # from file, on unix, for test, we monkeypathc it to 'true' |
|
13 | # from file, on unix, for test, we monkeypathc it to 'true' | |
12 | # which does not fail as doing anything. |
|
14 | # which does not fail as doing anything. | |
13 | #### |
|
15 | #### | |
14 | ConverterLaTeX.inkscape = 'true' |
|
16 | ConverterLaTeX.inkscape = 'true' | |
15 |
|
17 | |||
16 |
# commenting rst for now as travis build |
|
18 | # commenting rst for now as travis build | |
17 | # fail because of pandoc version. |
|
19 | # fail because of pandoc version. | |
18 | converters = [ |
|
20 | converters = [ | |
19 | #(ConverterRST,'rst'), |
|
21 | #(ConverterRST,'rst'), | |
20 | (ConverterMarkdown,'md'), |
|
22 | (ConverterMarkdown, 'md'), | |
21 | (ConverterLaTeX,'tex'), |
|
23 | (ConverterLaTeX, 'tex'), | |
22 | (ConverterPy,'py'), |
|
24 | (ConverterPy, 'py'), | |
23 | (ConverterHTML,'html') |
|
25 | (ConverterHTML, 'html') | |
24 | ] |
|
26 | ] | |
25 | reflist = [ |
|
27 | reflist = [ | |
26 | 'tests/ipynbref/IntroNumPy.orig' |
|
28 | 'tests/ipynbref/IntroNumPy.orig' | |
27 | ] |
|
29 | ] | |
28 |
for root in reflist |
|
30 | for root in reflist: | |
29 | for conv,ext in converters: |
|
31 | for conv, ext in converters: | |
30 | yield test_conversion, conv,root+'.ipynb',root+'.'+ext |
|
32 | yield test_conversion, conv, root + '.ipynb', root + '.' + ext | |
31 |
|
33 | |||
|
34 | ||||
32 | @nottest |
|
35 | @nottest | |
33 | def compfiles(stra, strb): |
|
36 | def compfiles(stra, strb): | |
34 |
nt.assert_equal(map(unicode.strip,stra.split('\n')), |
|
37 | nt.assert_equal(map(unicode.strip, stra.split('\n')), | |
|
38 | map(unicode.strip, strb.split('\n'))) | |||
|
39 | ||||
35 |
|
40 | |||
36 | @nottest |
|
41 | @nottest | |
37 | def test_conversion(ConverterClass, ipynb, ref_file): |
|
42 | def test_conversion(ConverterClass, ipynb, ref_file): | |
38 |
|
||||
39 | converter = ConverterClass(ipynb) |
|
43 | converter = ConverterClass(ipynb) | |
40 | converter.read() |
|
44 | converter.read() | |
41 | cv =converter.convert() |
|
45 | cv = converter.convert() | |
42 | with io.open(ref_file) as ref: |
|
46 | with io.open(ref_file) as ref: | |
43 | value = ref.read() |
|
47 | value = ref.read() | |
44 | compfiles(cv,value) |
|
48 | compfiles(cv, value) | |
45 |
|
||||
46 |
|
@@ -1,70 +1,71 b'' | |||||
1 | from nbconvert import ConverterRST, main |
|
1 | from nbconvert import ConverterRST, main | |
2 | import nose.tools as nt |
|
2 | 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 | from IPython.nbformat import current as nbformat | |
7 |
|
7 | |||
8 | fname = 'tests/test.ipynb' |
|
8 | fname = 'tests/test.ipynb' | |
9 | out_fname = 'tests/test.rst' |
|
9 | out_fname = 'tests/test.rst' | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | def clean_dir(): |
|
12 | def clean_dir(): | |
13 | "Remove .rst files created during conversion" |
|
13 | "Remove .rst files created during conversion" | |
14 | map(os.remove, glob.glob("./tests/*.rst")) |
|
14 | map(os.remove, glob.glob("./tests/*.rst")) | |
15 | map(os.remove, glob.glob("./tests/*.png")) |
|
15 | map(os.remove, glob.glob("./tests/*.png")) | |
16 | map(os.remove, glob.glob("./tests/*.html")) |
|
16 | map(os.remove, glob.glob("./tests/*.html")) | |
17 | map(os.remove, glob.glob("./tests/test_files/*")) |
|
17 | map(os.remove, glob.glob("./tests/test_files/*")) | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | @nt.with_setup(clean_dir, clean_dir) |
|
20 | @nt.with_setup(clean_dir, clean_dir) | |
21 | def test_simple(): |
|
21 | def test_simple(): | |
22 | c = ConverterRST(fname) |
|
22 | c = ConverterRST(fname) | |
23 | f = c.render() |
|
23 | f = c.render() | |
24 | nt.assert_true('rst' in f, 'changed file extension to rst') |
|
24 | nt.assert_true('rst' in f, 'changed file extension to rst') | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | @nt.with_setup(clean_dir, clean_dir) |
|
27 | @nt.with_setup(clean_dir, clean_dir) | |
28 | def test_main(): |
|
28 | def test_main(): | |
29 | """ |
|
29 | """ | |
30 | Test main entry point |
|
30 | Test main entry point | |
31 | """ |
|
31 | """ | |
32 | main(fname) |
|
32 | main(fname) | |
33 | nt.assert_true(os.path.exists(out_fname)) |
|
33 | nt.assert_true(os.path.exists(out_fname)) | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | def test_render_heading(): |
|
36 | def test_render_heading(): | |
37 | """ Unit test for cell type "heading" """ |
|
37 | """ Unit test for cell type "heading" """ | |
38 | # Generate and test heading cells level 1-6 |
|
38 | # Generate and test heading cells level 1-6 | |
39 | for level in xrange(1, 7): |
|
39 | for level in xrange(1, 7): | |
40 | cell = { |
|
40 | cell = { | |
41 | 'cell_type': 'heading', |
|
41 | 'cell_type': 'heading', | |
42 |
'level' |
|
42 | 'level': level, | |
43 |
'source' |
|
43 | 'source': ['Test for heading type H{0}'.format(level)] | |
44 | } |
|
44 | } | |
45 | # Convert cell dictionaries to NotebookNode |
|
45 | # Convert cell dictionaries to NotebookNode | |
46 | cell_nb = nbformat.NotebookNode(cell) |
|
46 | cell_nb = nbformat.NotebookNode(cell) | |
47 | # Make sure "source" attribute is uniconde not list. |
|
47 | # Make sure "source" attribute is uniconde not list. | |
48 | # For some reason, creating a NotebookNode manually like |
|
48 | # For some reason, creating a NotebookNode manually like | |
49 | # this isn't converting source to a string like using |
|
49 | # this isn't converting source to a string like using | |
50 | # the create-from-file routine. |
|
50 | # the create-from-file routine. | |
51 | if type(cell_nb.source) is list: |
|
51 | if type(cell_nb.source) is list: | |
52 | cell_nb.source = '\n'.join(cell_nb.source) |
|
52 | cell_nb.source = '\n'.join(cell_nb.source) | |
53 | # Render to rst |
|
53 | # Render to rst | |
54 | c = ConverterRST('') |
|
54 | c = ConverterRST('') | |
55 | rst_list = c.render_heading(cell_nb) |
|
55 | rst_list = c.render_heading(cell_nb) | |
56 |
|
|
56 | # render should return a list | |
|
57 | nt.assert_true(isinstance(rst_list, list)) | |||
57 | rst_str = "".join(rst_list) |
|
58 | rst_str = "".join(rst_list) | |
58 | # Confirm rst content |
|
59 | # Confirm rst content | |
59 | chk_str = "Test for heading type H{0}\n{1}\n".format( |
|
60 | chk_str = "Test for heading type H{0}\n{1}\n".format( | |
60 | level, c.heading_level[level] * 24) |
|
61 | level, c.heading_level[level] * 24) | |
61 | nt.assert_equal(rst_str, chk_str) |
|
62 | nt.assert_equal(rst_str, chk_str) | |
62 |
|
63 | |||
63 |
|
64 | |||
64 | @nt.with_setup(clean_dir, clean_dir) |
|
65 | @nt.with_setup(clean_dir, clean_dir) | |
65 | def test_main_html(): |
|
66 | def test_main_html(): | |
66 | """ |
|
67 | """ | |
67 | Test main entry point |
|
68 | Test main entry point | |
68 | """ |
|
69 | """ | |
69 | main(fname, format='html') |
|
70 | main(fname, format='html') | |
70 | nt.assert_true(os.path.exists('tests/test.html')) |
|
71 | nt.assert_true(os.path.exists('tests/test.html')) |
General Comments 0
You need to be logged in to leave comments.
Login now