##// END OF EJS Templates
testing roundtrip of test.ipynb file after passing through json.dump/json.load
Jonathan Taylor -
Show More
@@ -1,20 +1,24 b''
1 from nbconvert import ConverterNotebook
1 from nbconvert import ConverterNotebook
2 import nose.tools as nt
2 import nose.tools as nt
3 import os
3 import os, json
4
4
5 fname = 'tests/test.ipynb'
5 fname = 'tests/test.ipynb'
6 outbase1 = 'newtest1'
6 outbase1 = 'newtest1'
7 outbase2 = 'newtest2'
7 outbase2 = 'test' # will output to ./test.ipynb
8
8
9 def test_roundtrip():
9 def test_roundtrip():
10 converter = ConverterNotebook(fname, outbase1)
10 converter = ConverterNotebook(fname, outbase1)
11 converter.render()
11 converter.render()
12
12
13 converter2 = ConverterNotebook(outbase1+'.ipynb', outbase2)
13 converter2 = ConverterNotebook(outbase1+'.ipynb', outbase2)
14 converter2.render()
14 converter2.render()
15
15
16 s1 = open(outbase1+'.ipynb', 'rb').read()
16 s1 = open(outbase1+'.ipynb', 'rb').read()
17 s2 = open(outbase2+'.ipynb', 'rb').read()
17 s2 = open(outbase2+'.ipynb', 'rb').read()
18 nt.assert_true(s1.replace(outbase1, outbase2) == s2)
18 nt.assert_true(s1.replace(outbase1, outbase2) == s2)
19 os.remove(outbase1+'.ipynb')
19 os.remove(outbase1+'.ipynb')
20 os.remove(outbase2+'.ipynb')
20 os.remove(outbase2+'.ipynb')
21
22 s0 = json.dumps(json.load(file(fname)), indent=1, sort_keys=True)
23 nt.assert_true(s0 == s2)
24
General Comments 0
You need to be logged in to leave comments. Login now