chrisjsewell / ipypublish
1 3
import pytest
2

3 3
from ipypublish.convert import nbmerge
4 3
from ipypublish.convert.config_manager import create_exporter_cls, str_to_jinja
5 3
from ipypublish.convert.main import dict_to_config, IpyPubMain
6

7

8 3
@pytest.mark.ipynb("basic_nb")
9 3
def test_nbexport_latex_empty(ipynb_app):
10 3
    template = str_to_jinja("", "template_name")
11 3
    config = dict_to_config({"LatexExporter.template_file": "template_name"})
12 3
    exporter_cls = create_exporter_cls("nbconvert.exporters.LatexExporter")
13 3
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
14 3
    exporter, body, resources = IpyPubMain().export_notebook(
15
        nb, exporter_cls, config, template
16
    )
17 3
    assert exporter.output_mimetype == "text/latex"
18 3
    assert body == ""
19

20

21 3
@pytest.mark.ipynb("basic_nb")
22 3
def test_nbexport_latex_mkdown1(ipynb_app):
23 3
    template = str_to_jinja(
24
        """
25
((* block markdowncell scoped *))
26
test123
27
((* endblock markdowncell *))
28
    """,
29
        "template_name",
30
    )
31 3
    config = dict_to_config({"LatexExporter.template_file": "template_name"})
32 3
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
33 3
    exporter_cls = create_exporter_cls("nbconvert.exporters.LatexExporter")
34 3
    exporter, body, resources = IpyPubMain().export_notebook(
35
        nb, exporter_cls, config, template
36
    )
37 3
    assert exporter.output_mimetype == "text/latex"
38 3
    assert body.strip() == "test123"
39

40

41 3
@pytest.mark.ipynb("basic_nb")
42 3
def test_nbexport_latex_mkdown2(ipynb_app):
43 3
    template = str_to_jinja(
44
        """
45
((*- extends 'display_priority.tplx' -*))
46
((* block markdowncell scoped *))
47
(((cell.source)))
48
((* endblock markdowncell *))
49
    """,
50
        "template_name",
51
    )
52 3
    config = dict_to_config({"LatexExporter.template_file": "template_name"})
53 3
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
54 3
    exporter_cls = create_exporter_cls("nbconvert.exporters.LatexExporter")
55 3
    exporter, body, resources = IpyPubMain().export_notebook(
56
        nb, exporter_cls, config, template
57
    )
58 3
    assert exporter.output_mimetype == "text/latex"
59

60 3
    assert body.strip() == "# a title\n\nsome text"
61

62

63 3
@pytest.mark.ipynb("basic_nb")
64 3
def test_nbexport_html_empty(ipynb_app):
65 3
    template = str_to_jinja("", "template_name")
66 3
    config = dict_to_config({"HTMLExporter.template_file": "template_name"})
67 3
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
68 3
    exporter_cls = create_exporter_cls("nbconvert.exporters.HTMLExporter")
69 3
    exporter, body, resources = IpyPubMain().export_notebook(
70
        nb, exporter_cls, config, template
71
    )
72 3
    assert exporter.output_mimetype == "text/html"
73

74 3
    assert body == ""
75

76

77 3
@pytest.mark.ipynb("basic_nb")
78 3
def test_nbexport_html_mkdown1(ipynb_app):
79 3
    template = str_to_jinja(
80
        """
81
{% block markdowncell scoped %}
82
test123
83
{% endblock markdowncell %}
84
    """,
85
        "template_name",
86
    )
87 3
    config = dict_to_config({"HTMLExporter.template_file": "template_name"})
88 3
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
89 3
    exporter_cls = create_exporter_cls("nbconvert.exporters.HTMLExporter")
90 3
    exporter, body, resources = IpyPubMain().export_notebook(
91
        nb, exporter_cls, config, template
92
    )
93 3
    assert exporter.output_mimetype == "text/html"
94

95 3
    assert body.strip() == "test123"
96

97

98 3
@pytest.mark.ipynb("basic_nb")
99 3
def test_nbexport_html_mkdown2(ipynb_app):
100 3
    template = str_to_jinja(
101
        """
102
{%- extends 'display_priority.tpl' -%}
103
{% block markdowncell scoped %}
104
{{cell.source}}
105
{% endblock markdowncell %}
106
    """,
107
        "template_name",
108
    )
109 3
    config = dict_to_config({"HTMLExporter.template_file": "template_name"})
110 3
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
111 3
    exporter_cls = create_exporter_cls("nbconvert.exporters.HTMLExporter")
112 3
    exporter, body, resources = IpyPubMain().export_notebook(
113
        nb, exporter_cls, config, template
114
    )
115 3
    assert exporter.output_mimetype == "text/html"
116

117 3
    assert body.strip() == "# a title\n\nsome text"

Read our documentation on viewing source code .

Loading