From 1f16844305d285a2df1d0afef42f93292a4d3230 2013-02-13 19:30:01 From: Matthias BUSSONNIER Date: 2013-02-13 19:30:01 Subject: [PATCH] fix tests --- diff --git a/converters/base.py b/converters/base.py index b8dc0bb..83d5702 100755 --- a/converters/base.py +++ b/converters/base.py @@ -157,6 +157,7 @@ class Converter(Configurable): self.exclude_cells = exclude self.infile = infile if infile: + self.infile = infile self.infile_dir, infile_root = os.path.split(infile) self.infile_root = os.path.splitext(infile_root)[0] self.clean_name = clean_filename(self.infile_root) @@ -327,7 +328,6 @@ class Converter(Configurable): # Is it an image? if fmt in ['png', 'svg', 'jpg', 'pdf'] and self.extract_figures: - print('I will extract this', fmt) img_file = self._new_figure(output[fmt], fmt) # Subclasses can have format-specific render functions (e.g., # latex has to auto-convert all SVG to PDF first). @@ -336,7 +336,6 @@ class Converter(Configurable): lines_fun = self._img_lines lines = lines_fun(img_file) else: - print('I will NOT extract this', fmt) lines_fun = self.dispatch_display_format(fmt) lines = lines_fun(output) diff --git a/converters/notebook.py b/converters/notebook.py index c4e970a..32cab8c 100755 --- a/converters/notebook.py +++ b/converters/notebook.py @@ -44,8 +44,8 @@ class ConverterNotebook(Converter): """ extension = 'ipynb' - def __init__(self, infile, outbase, **kw): - Converter.__init__(self, infile, **kw) + def __init__(self, infile=None, outbase=None, **kw): + Converter.__init__(self, infile=infile, **kw) self.outbase = outbase rmtree(self.files_dir) diff --git a/nbconvert.py b/nbconvert.py index 36f8015..5769bc0 100755 --- a/nbconvert.py +++ b/nbconvert.py @@ -108,7 +108,8 @@ class NbconvertApp(Application): def run(self): """Convert a notebook to html in one step""" ConverterClass = converters[self.fmt] - converter = ConverterClass(infile=self.extra_args[0], config=self.config) + infile = (self.extra_args or [None])[0] + converter = ConverterClass(infile=infile, config=self.config) converter.render() def main(): diff --git a/tests/test_nbconverter.py b/tests/test_nbconverter.py index 1718f47..a82d243 100644 --- a/tests/test_nbconverter.py +++ b/tests/test_nbconverter.py @@ -17,9 +17,9 @@ def test_roundtrip(): out2 = os.path.join(directory, outbase2) fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.ipynb') - converter = ConverterNotebook(fname, out1) + converter = ConverterNotebook(infile=fname, outbase=out1) converter.render() - converter2 = ConverterNotebook(out1 + '.ipynb', out2) + converter2 = ConverterNotebook(infile=out1 + '.ipynb', outbase=out2) converter2.render() with open(out1 + '.ipynb', 'rb') as f: diff --git a/tests/test_references.py b/tests/test_references.py index 713151d..36414c3 100644 --- a/tests/test_references.py +++ b/tests/test_references.py @@ -50,7 +50,7 @@ def compfiles(stra, strb): @nottest def test_conversion(ConverterClass, ipynb, ref_file): - converter = ConverterClass(ipynb) + converter = ConverterClass(infile=ipynb) converter.read() cv = converter.convert() with io.open(ref_file) as ref: diff --git a/tests/test_simple.py b/tests/test_simple.py index 1ba1c5d..6bc5c87 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -1,4 +1,4 @@ -from nbconvert import main, converters +from nbconvert import main, converters , NbconvertApp from converters.rst import ConverterRST import nose.tools as nt @@ -26,11 +26,13 @@ class TestSimple(object): def outfile_exists(self, fmt): extension = converters[fmt].extension + print("==out to ==>>",os.path.join(self.wrkdir, + self.basename + '.' + extension)) return os.path.exists(os.path.join(self.wrkdir, self.basename + '.' + extension)) def test_simple(self): - c = ConverterRST(self.infile) + c = ConverterRST(infile=self.infile) f = c.render() nt.assert_true(f.endswith('.rst'), 'changed file extension to rst') @@ -39,7 +41,13 @@ class TestSimple(object): Run the 'main' method to convert the input file to the given format and check that the expected output file exists. """ - main(self.infile, format=fmt) + app = NbconvertApp.instance() + app.initialize() + app.extra_args = [self.infile] + app.fmt = fmt + app.start() + + app.run() nt.assert_true(self.outfile_exists(fmt)) def test_main(self): @@ -77,7 +85,7 @@ class TestSimple(object): cell_nb.source = '\n'.join(cell_nb.source) # Render to rst - c = ConverterRST('') + c = ConverterRST() rst_list = c.render_heading(cell_nb) # render should return a list