Show More
@@ -63,7 +63,7 b' class Converter(object):' | |||||
63 | user_preamble = None |
|
63 | user_preamble = None | |
64 | output = unicode() |
|
64 | output = unicode() | |
65 | raw_as_verbatim = False |
|
65 | raw_as_verbatim = False | |
66 |
|
66 | |||
67 | def __init__(self, infile): |
|
67 | def __init__(self, infile): | |
68 | self.infile = infile |
|
68 | self.infile = infile | |
69 | self.infile_dir, infile_root = os.path.split(infile) |
|
69 | self.infile_dir, infile_root = os.path.split(infile) | |
@@ -168,7 +168,7 b' class Converter(object):' | |||||
168 |
|
168 | |||
169 | Returns a path relative to the input file. |
|
169 | Returns a path relative to the input file. | |
170 | """ |
|
170 | """ | |
171 |
figname = '%s_fig_%02i.%s' % (self.infile_root, |
|
171 | figname = '%s_fig_%02i.%s' % (self.infile_root, | |
172 | self.figures_counter, fmt) |
|
172 | self.figures_counter, fmt) | |
173 | self.figures_counter += 1 |
|
173 | self.figures_counter += 1 | |
174 | fullname = os.path.join(self.files_dir, figname) |
|
174 | fullname = os.path.join(self.files_dir, figname) | |
@@ -179,10 +179,10 b' class Converter(object):' | |||||
179 | fopen = lambda fname: open(fname, 'wb') |
|
179 | fopen = lambda fname: open(fname, 'wb') | |
180 | else: |
|
180 | else: | |
181 | fopen = lambda fname: codecs.open(fname, 'wb', self.default_encoding) |
|
181 | fopen = lambda fname: codecs.open(fname, 'wb', self.default_encoding) | |
182 |
|
182 | |||
183 | with fopen(fullname) as f: |
|
183 | with fopen(fullname) as f: | |
184 | f.write(data) |
|
184 | f.write(data) | |
185 |
|
185 | |||
186 | return fullname |
|
186 | return fullname | |
187 |
|
187 | |||
188 | def render_heading(self, cell): |
|
188 | def render_heading(self, cell): |
@@ -7,7 +7,7 b' class ConverterNotebook(Converter):' | |||||
7 | """ |
|
7 | """ | |
8 | A converter that is essentially a null-op. |
|
8 | A converter that is essentially a null-op. | |
9 | This exists so it can be subclassed |
|
9 | This exists so it can be subclassed | |
10 |
for custom handlers of .ipynb files |
|
10 | for custom handlers of .ipynb files | |
11 | that create new .ipynb files. |
|
11 | that create new .ipynb files. | |
12 |
|
12 | |||
13 | What distinguishes this from JSONWriter is that |
|
13 | What distinguishes this from JSONWriter is that |
@@ -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 | |
|
33 | ||||
31 |
|
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 |
|
@@ -39,8 +39,8 b' def test_render_heading():' | |||||
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) | |
@@ -53,7 +53,8 b' def test_render_heading():' | |||||
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( |
General Comments 0
You need to be logged in to leave comments.
Login now