Exemple #1
0
def test_template_load():
    """MarkdownWriter should be able to load a template from an
    absolute path. IPython requires a relative path.
    """
    template_abspath = os.path.abspath('notedown/templates/markdown.tpl')
    writer = notedown.MarkdownWriter(template_file=template_abspath)
    import jinja2
    assert (isinstance(writer.exporter.template, jinja2.Template))
Exemple #2
0
def test_template_load_absolute():
    """Load a template from an absolute path.

    IPython 3 requires a relative path in a child directory.
    """
    template_abspath = os.path.abspath('notedown/templates/markdown.tpl')
    writer = notedown.MarkdownWriter(template_file=template_abspath)
    import jinja2
    assert(isinstance(writer.exporter.template, jinja2.Template))
Exemple #3
0
def test_template_load_nonchild():
    """Load a template from a non-child directory.

    IPython 3 requires a relative path in a child directory.
    """
    temp = tempfile.NamedTemporaryFile(delete=False, mode='w+t')

    template_path = 'notedown/templates/markdown.tpl'

    with open(template_path, 'rt') as source:
        temp.write(source.read())

    temp.close()

    writer = notedown.MarkdownWriter(template_file=temp.name)
    import jinja2
    assert(isinstance(writer.exporter.template, jinja2.Template))

    os.remove(temp.name)
Exemple #4
0
def test_roundtrip():
    """Run nbconvert using our custom markdown template to recover
    original markdown from a notebook.
    """
    # create a notebook from the markdown
    mr = notedown.MarkdownReader()
    roundtrip_notebook = mr.to_notebook(roundtrip_markdown)

    # write the notebook into json
    notebook_json = nbformat.writes(roundtrip_notebook)

    # write the json back into notebook
    notebook = nbformat.reads(notebook_json, as_version=4)

    # convert notebook to markdown
    mw = notedown.MarkdownWriter(template_file='notedown/templates/markdown.tpl', strip_outputs=True)
    markdown = mw.writes(notebook)

    nt.assert_multi_line_equal(roundtrip_markdown, markdown)
Exemple #5
0
def test_markdown_markdown():
    mr = notedown.MarkdownReader()
    mw = notedown.MarkdownWriter(notedown.markdown_template)
    nb = mr.reads(roundtrip_markdown)
    markdown = mw.writes(nb)
    nt.assert_multi_line_equal(markdown, roundtrip_markdown)