test_nbconverter.py
33 lines
| 1.0 KiB
| text/x-python
|
PythonLexer
Matthias BUSSONNIER
|
r8766 | from converters import ConverterNotebook | ||
Jonathan Taylor
|
r7366 | 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') | ||||
Matthias BUSSONNIER
|
r9572 | converter = ConverterNotebook(infile=fname, outbase=out1) | ||
Jonathan Taylor
|
r7366 | converter.render() | ||
Matthias BUSSONNIER
|
r9572 | converter2 = ConverterNotebook(infile=out1 + '.ipynb', outbase=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) | ||||