test_nbconverter.py
35 lines
| 995 B
| text/x-python
|
PythonLexer
/ tests / test_nbconverter.py
Jonathan Taylor
|
r7366 | from nbconvert import ConverterNotebook | ||
import nose.tools as nt | ||||
David Warde-Farley
|
r8719 | import os | ||
import json | ||||
import shutil | ||||
import tempfile | ||||
Jonathan Taylor
|
r7366 | |||
David Warde-Farley
|
r8719 | |||
# name = os.path.join(os.path.dirname(os.path.abspath(__file__), test.ipynb') | ||||
Jonathan Taylor
|
r7366 | outbase1 = 'newtest1' | ||
David Warde-Farley
|
r8719 | outbase2 = 'test' # will output to ./test.ipynb | ||
Jonathan Taylor
|
r7366 | |||
def test_roundtrip(): | ||||
David Warde-Farley
|
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
|
r7366 | converter.render() | ||
David Warde-Farley
|
r8719 | converter2 = ConverterNotebook(out1 + '.ipynb', out2) | ||
Jonathan Taylor
|
r7366 | converter2.render() | ||
David Warde-Farley
|
r8719 | with open(out1 + '.ipynb', 'rb') as f: | ||
s1 = f.read() | ||||
with open(out2 + '.ipynb', 'rb') as f: | ||||
s2 = f.read() | ||||
Jonathan Taylor
|
r7366 | nt.assert_true(s1.replace(outbase1, outbase2) == s2) | ||
David Warde-Farley
|
r8719 | shutil.rmtree(directory) | ||
Jonathan Taylor
|
r7369 | |||
s0 = json.dumps(json.load(file(fname)), indent=1, sort_keys=True) | ||||
nt.assert_true(s0 == s2) | ||||