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

File last commit:

r8738:fa0e3fea merge
r8761:2f9d43b4
Show More
test_simple.py
71 lines | 2.1 KiB | text/x-python | PythonLexer
Anton I. Sipos
Fix main() function to use new object based converters, and add a test
r6252 from nbconvert import ConverterRST, main
Paul Ivanov
refactored nbconvert, nosetest pass...
r6239 import nose.tools as nt
import os
import glob
smithj1
Add unit test for ConvertRST.render_heading method...
r6259 from IPython.nbformat import current as nbformat
Paul Ivanov
refactored nbconvert, nosetest pass...
r6239
Anton I. Sipos
Fix main() function to use new object based converters, and add a test
r6252 fname = 'tests/test.ipynb'
out_fname = 'tests/test.rst'
Paul Ivanov
refactored nbconvert, nosetest pass...
r6239 def clean_dir():
"Remove .rst files created during conversion"
Paul Ivanov
only delete .rst and .png in the tests directory
r6246 map(os.remove, glob.glob("./tests/*.rst"))
map(os.remove, glob.glob("./tests/*.png"))
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 map(os.remove, glob.glob("./tests/*.html"))
Matthias BUSSONNIER
cleanup more files after test_simple
r8647 map(os.remove, glob.glob("./tests/test_files/*"))
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261
Paul Ivanov
refactored nbconvert, nosetest pass...
r6239
@nt.with_setup(clean_dir, clean_dir)
def test_simple():
c = ConverterRST(fname)
f = c.render()
Maximilian Albert
Really check the file extension, not an arbitrary occurrence of 'rst'.
r8729 nt.assert_true(f.endswith('.rst'), 'changed file extension to rst')
Paul Ivanov
refactored nbconvert, nosetest pass...
r6239
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261
Anton I. Sipos
Fix main() function to use new object based converters, and add a test
r6252 @nt.with_setup(clean_dir, clean_dir)
def test_main():
"""
Test main entry point
"""
main(fname)
nt.assert_true(os.path.exists(out_fname))
smithj1
Add unit test for ConvertRST.render_heading method...
r6259
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261
smithj1
Add unit test for ConvertRST.render_heading method...
r6259 def test_render_heading():
""" Unit test for cell type "heading" """
# Generate and test heading cells level 1-6
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 for level in xrange(1, 7):
smithj1
Add unit test for ConvertRST.render_heading method...
r6259 cell = {
'cell_type': 'heading',
David Warde-Farley
PEP8
r8718 'level': level,
'source': ['Test for heading type H{0}'.format(level)]
smithj1
Add unit test for ConvertRST.render_heading method...
r6259 }
# Convert cell dictionaries to NotebookNode
cell_nb = nbformat.NotebookNode(cell)
# Make sure "source" attribute is uniconde not list.
# For some reason, creating a NotebookNode manually like
# this isn't converting source to a string like using
# the create-from-file routine.
if type(cell_nb.source) is list:
cell_nb.source = '\n'.join(cell_nb.source)
# Render to rst
c = ConverterRST('')
rst_list = c.render_heading(cell_nb)
David Warde-Farley
PEP8
r8718 # render should return a list
nt.assert_true(isinstance(rst_list, list))
smithj1
Add unit test for ConvertRST.render_heading method...
r6259 rst_str = "".join(rst_list)
# Confirm rst content
chk_str = "Test for heading type H{0}\n{1}\n".format(
Paul Ivanov
make render_heading reusable
r6264 level, c.heading_level[level] * 24)
Anton I. Sipos
Add argument parsing, and ability to convert an HTML file from command line
r6261 nt.assert_equal(rst_str, chk_str)
@nt.with_setup(clean_dir, clean_dir)
def test_main_html():
"""
Test main entry point
"""
main(fname, format='html')
nt.assert_true(os.path.exists('tests/test.html'))