Beispiel #1
0
    def test_render_heading(self):
        """
        Unit test for cell type "heading"
        """
        # Generate and test heading cells level 1-6
        for level in xrange(1, 7):
            cell = {
                'cell_type': 'heading',
                'level': level,
                'source': ['Test for heading type H{0}'.format(level)]
            }

            # 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)

            # render should return a list
            nt.assert_true(isinstance(rst_list, list))
            rst_str = "".join(rst_list)

            # Confirm rst content
            chk_str = "Test for heading type H{0}\n{1}\n".format(
                level, c.heading_level[level] * 24)
            nt.assert_equal(rst_str, chk_str)
    def test_render_heading(self):
        """
        Unit test for cell type "heading"
        """
        # Generate and test heading cells level 1-6
        for level in xrange(1, 7):
            cell = {
                'cell_type': 'heading',
                'level': level,
                'source':  ['Test for heading type H{0}'.format(level)]
                }

            # 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)

            # render should return a list
            nt.assert_true(isinstance(rst_list, list))
            rst_str = "".join(rst_list)

            # Confirm rst content
            chk_str = "Test for heading type H{0}\n{1}\n".format(
                 level, c.heading_level[level] * 24)
            nt.assert_equal(rst_str, chk_str)
Beispiel #3
0
def main(infile, format='rst'):
    """Convert a notebook to html in one step"""
    # XXX: this is just quick and dirty for now. When adding a new format,
    # make sure to add it to the `known_formats` string above, which gets
    # printed in in the catch-all else, as well as in the help
    if format == 'rst':
        converter = ConverterRST(infile)
        converter.render()
    elif format == 'markdown':
        converter = ConverterMarkdown(infile)
        converter.render()
    elif format == 'html':
        converter = ConverterHTML(infile)
        converter.render()
    elif format == 'blogger-html':
        converter = ConverterBloggerHTML(infile)
        converter.render()
    elif format == 'latex':
        converter = ConverterLaTeX(infile)
        converter.render()
    elif format == 'py':
        converter = ConverterPy(infile)
        converter.render()
    else:
        raise SystemExit("Unknown format '%s', " % format +
                "known formats are: " + known_formats)
Beispiel #4
0
 def test_simple(self):
     c = ConverterRST(self.infile)
     f = c.render()
     nt.assert_true(f.endswith('.rst'), 'changed file extension to rst')
 def test_simple(self):
     c = ConverterRST(self.infile)
     f = c.render()
     nt.assert_true(f.endswith('.rst'), 'changed file extension to rst')