##// END OF EJS Templates
fix tests
Matthias BUSSONNIER -
Show More
@@ -157,6 +157,7 b' class Converter(Configurable):'
157 self.exclude_cells = exclude
157 self.exclude_cells = exclude
158 self.infile = infile
158 self.infile = infile
159 if infile:
159 if infile:
160 self.infile = infile
160 self.infile_dir, infile_root = os.path.split(infile)
161 self.infile_dir, infile_root = os.path.split(infile)
161 self.infile_root = os.path.splitext(infile_root)[0]
162 self.infile_root = os.path.splitext(infile_root)[0]
162 self.clean_name = clean_filename(self.infile_root)
163 self.clean_name = clean_filename(self.infile_root)
@@ -327,7 +328,6 b' class Converter(Configurable):'
327
328
328 # Is it an image?
329 # Is it an image?
329 if fmt in ['png', 'svg', 'jpg', 'pdf'] and self.extract_figures:
330 if fmt in ['png', 'svg', 'jpg', 'pdf'] and self.extract_figures:
330 print('I will extract this', fmt)
331 img_file = self._new_figure(output[fmt], fmt)
331 img_file = self._new_figure(output[fmt], fmt)
332 # Subclasses can have format-specific render functions (e.g.,
332 # Subclasses can have format-specific render functions (e.g.,
333 # latex has to auto-convert all SVG to PDF first).
333 # latex has to auto-convert all SVG to PDF first).
@@ -336,7 +336,6 b' class Converter(Configurable):'
336 lines_fun = self._img_lines
336 lines_fun = self._img_lines
337 lines = lines_fun(img_file)
337 lines = lines_fun(img_file)
338 else:
338 else:
339 print('I will NOT extract this', fmt)
340 lines_fun = self.dispatch_display_format(fmt)
339 lines_fun = self.dispatch_display_format(fmt)
341 lines = lines_fun(output)
340 lines = lines_fun(output)
342
341
@@ -44,8 +44,8 b' class ConverterNotebook(Converter):'
44 """
44 """
45 extension = 'ipynb'
45 extension = 'ipynb'
46
46
47 def __init__(self, infile, outbase, **kw):
47 def __init__(self, infile=None, outbase=None, **kw):
48 Converter.__init__(self, infile, **kw)
48 Converter.__init__(self, infile=infile, **kw)
49 self.outbase = outbase
49 self.outbase = outbase
50 rmtree(self.files_dir)
50 rmtree(self.files_dir)
51
51
@@ -108,7 +108,8 b' class NbconvertApp(Application):'
108 def run(self):
108 def run(self):
109 """Convert a notebook to html in one step"""
109 """Convert a notebook to html in one step"""
110 ConverterClass = converters[self.fmt]
110 ConverterClass = converters[self.fmt]
111 converter = ConverterClass(infile=self.extra_args[0], config=self.config)
111 infile = (self.extra_args or [None])[0]
112 converter = ConverterClass(infile=infile, config=self.config)
112 converter.render()
113 converter.render()
113
114
114 def main():
115 def main():
@@ -17,9 +17,9 b' def test_roundtrip():'
17 out2 = os.path.join(directory, outbase2)
17 out2 = os.path.join(directory, outbase2)
18 fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),
18 fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),
19 'test.ipynb')
19 'test.ipynb')
20 converter = ConverterNotebook(fname, out1)
20 converter = ConverterNotebook(infile=fname, outbase=out1)
21 converter.render()
21 converter.render()
22 converter2 = ConverterNotebook(out1 + '.ipynb', out2)
22 converter2 = ConverterNotebook(infile=out1 + '.ipynb', outbase=out2)
23 converter2.render()
23 converter2.render()
24
24
25 with open(out1 + '.ipynb', 'rb') as f:
25 with open(out1 + '.ipynb', 'rb') as f:
@@ -50,7 +50,7 b' def compfiles(stra, strb):'
50
50
51 @nottest
51 @nottest
52 def test_conversion(ConverterClass, ipynb, ref_file):
52 def test_conversion(ConverterClass, ipynb, ref_file):
53 converter = ConverterClass(ipynb)
53 converter = ConverterClass(infile=ipynb)
54 converter.read()
54 converter.read()
55 cv = converter.convert()
55 cv = converter.convert()
56 with io.open(ref_file) as ref:
56 with io.open(ref_file) as ref:
@@ -1,4 +1,4 b''
1 from nbconvert import main, converters
1 from nbconvert import main, converters , NbconvertApp
2 from converters.rst import ConverterRST
2 from converters.rst import ConverterRST
3 import nose.tools as nt
3 import nose.tools as nt
4
4
@@ -26,11 +26,13 b' class TestSimple(object):'
26
26
27 def outfile_exists(self, fmt):
27 def outfile_exists(self, fmt):
28 extension = converters[fmt].extension
28 extension = converters[fmt].extension
29 print("==out to ==>>",os.path.join(self.wrkdir,
30 self.basename + '.' + extension))
29 return os.path.exists(os.path.join(self.wrkdir,
31 return os.path.exists(os.path.join(self.wrkdir,
30 self.basename + '.' + extension))
32 self.basename + '.' + extension))
31
33
32 def test_simple(self):
34 def test_simple(self):
33 c = ConverterRST(self.infile)
35 c = ConverterRST(infile=self.infile)
34 f = c.render()
36 f = c.render()
35 nt.assert_true(f.endswith('.rst'), 'changed file extension to rst')
37 nt.assert_true(f.endswith('.rst'), 'changed file extension to rst')
36
38
@@ -39,7 +41,13 b' class TestSimple(object):'
39 Run the 'main' method to convert the input file to the given
41 Run the 'main' method to convert the input file to the given
40 format and check that the expected output file exists.
42 format and check that the expected output file exists.
41 """
43 """
42 main(self.infile, format=fmt)
44 app = NbconvertApp.instance()
45 app.initialize()
46 app.extra_args = [self.infile]
47 app.fmt = fmt
48 app.start()
49
50 app.run()
43 nt.assert_true(self.outfile_exists(fmt))
51 nt.assert_true(self.outfile_exists(fmt))
44
52
45 def test_main(self):
53 def test_main(self):
@@ -77,7 +85,7 b' class TestSimple(object):'
77 cell_nb.source = '\n'.join(cell_nb.source)
85 cell_nb.source = '\n'.join(cell_nb.source)
78
86
79 # Render to rst
87 # Render to rst
80 c = ConverterRST('')
88 c = ConverterRST()
81 rst_list = c.render_heading(cell_nb)
89 rst_list = c.render_heading(cell_nb)
82
90
83 # render should return a list
91 # render should return a list
General Comments 0
You need to be logged in to leave comments. Login now