##// END OF EJS Templates
update ref texfile
update ref texfile

File last commit:

r8719:d65920be
r8759:a82ef14f
Show More
test_nbconverter.py
35 lines | 995 B | text/x-python | PythonLexer
/ tests / test_nbconverter.py
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366 from nbconvert import ConverterNotebook
import nose.tools as nt
David Warde-Farley
Make tests more filesystem-friendly
r8719 import os
import json
import shutil
import tempfile
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366
David Warde-Farley
Make tests more filesystem-friendly
r8719
# name = os.path.join(os.path.dirname(os.path.abspath(__file__), test.ipynb')
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366 outbase1 = 'newtest1'
David Warde-Farley
Make tests more filesystem-friendly
r8719 outbase2 = 'test' # will output to ./test.ipynb
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366
def test_roundtrip():
David Warde-Farley
Make tests more filesystem-friendly
r8719 directory = tempfile.mkdtemp()
out1 = os.path.join(directory, outbase1)
out2 = os.path.join(directory, outbase2)
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'test.ipynb')
converter = ConverterNotebook(fname, out1)
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366 converter.render()
David Warde-Farley
Make tests more filesystem-friendly
r8719 converter2 = ConverterNotebook(out1 + '.ipynb', out2)
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366 converter2.render()
David Warde-Farley
Make tests more filesystem-friendly
r8719 with open(out1 + '.ipynb', 'rb') as f:
s1 = f.read()
with open(out2 + '.ipynb', 'rb') as f:
s2 = f.read()
Jonathan Taylor
overriding DocInherit due to recursion depth errors
r7366 nt.assert_true(s1.replace(outbase1, outbase2) == s2)
David Warde-Farley
Make tests more filesystem-friendly
r8719 shutil.rmtree(directory)
Jonathan Taylor
testing roundtrip of test.ipynb file after passing through json.dump/json.load
r7369
s0 = json.dumps(json.load(file(fname)), indent=1, sort_keys=True)
nt.assert_true(s0 == s2)