chrisjsewell / ipypublish
1 3
import os
2 3
import pytest
3 3
from ipypublish.utils import pathlib  # noqa: F401
4 3
from ipypublish.frontend import nbpresent
5 3
from ipypublish.frontend import nbpublish
6

7

8 3
@pytest.mark.ipynb("basic_nb")
9 3
def test_nbpresent_bad_exporter(ipynb_app):
10
    # type: (str, pathlib.Path) -> None
11 3
    assert 1 == nbpresent.run(
12
        [
13
            str(ipynb_app.input_file),
14
            "-f",
15
            "non-existent",
16
            "--outpath",
17
            str(ipynb_app.converted_path),
18
            "--dry-run",
19
            "--log-level",
20
            "debug",
21
        ]
22
    )
23

24

25 3
@pytest.mark.ipynb("basic_nb")
26 3
def test_nbpublish_bad_exporter(ipynb_app):
27
    # type: (str, pathlib.Path) -> None
28 3
    assert 1 == nbpublish.run(
29
        [
30
            str(ipynb_app.input_file),
31
            "-f",
32
            "non-existent",
33
            "--outpath",
34
            str(ipynb_app.converted_path),
35
            "--dry-run",
36
            "--log-level",
37
            "debug",
38
        ]
39
    )
40

41

42 3
@pytest.mark.ipynb("basic_nb")
43 3
def test_nbpresent_dry_run(ipynb_app):
44
    # type: (str, pathlib.Path) -> None
45 3
    assert 0 == nbpresent.run(
46
        [
47
            str(ipynb_app.input_file),
48
            "--outpath",
49
            str(ipynb_app.converted_path),
50
            "--dry-run",
51
            "--log-level",
52
            "debug",
53
            "-pt",
54
        ]
55
    )
56

57

58 3
@pytest.mark.ipynb("basic_nb")
59 3
def test_nbpublish_dry_run(ipynb_app):
60
    # type: (str, pathlib.Path) -> None
61 3
    assert 0 == nbpublish.run(
62
        [
63
            str(ipynb_app.input_file),
64
            "--outpath",
65
            str(ipynb_app.converted_path),
66
            "--dry-run",
67
            "--log-level",
68
            "debug",
69
            "-pt",
70
        ]
71
    )
72

73

74 3
@pytest.mark.ipynb("basic_nb")
75 3
def test_nbpublish_dry_run_with_external_plugin(ipynb_app, external_export_plugin):
76
    # type: (str, pathlib.Path) -> None
77 3
    assert 0 == nbpublish.run(
78
        [
79
            str(ipynb_app.input_file),
80
            "--outformat",
81
            str(external_export_plugin),
82
            "--outpath",
83
            str(ipynb_app.converted_path),
84
            "--dry-run",
85
            "--log-level",
86
            "debug",
87
            "-pt",
88
        ]
89
    )
90

91

92 3
@pytest.mark.ipynb("basic_nb")
93 3
def test_nbpublish_dry_run_with_external_plugin_key(ipynb_app, external_export_plugin):
94
    # type: (str, pathlib.Path, pathlib.Path) -> None
95 3
    assert 0 == nbpublish.run(
96
        [
97
            str(ipynb_app.input_file),
98
            "--export-paths",
99
            str(external_export_plugin.parent),
100
            "--outformat",
101
            os.path.splitext(str(external_export_plugin.name))[0],
102
            "--outpath",
103
            str(ipynb_app.converted_path),
104
            "--dry-run",
105
            "--log-level",
106
            "debug",
107
            "-pt",
108
        ]
109
    )
110

111

112 3
def test_nbpresent_list_exports():
113 3
    with pytest.raises(SystemExit) as out:
114 3
        nbpresent.run(["--list-exporters"])
115 0
        assert out.type == SystemExit
116 0
        assert out.value.code == 0
117

118

119 3
def test_nbpublish_list_exports():
120 3
    with pytest.raises(SystemExit) as out:
121 3
        nbpublish.run(["--list-exporters"])
122 0
        assert out.type == SystemExit
123 0
        assert out.value.code == 0
124

125

126 3
@pytest.mark.ipynb("basic_nb")
127 3
def test_nbpublish_write(ipynb_app):
128
    # type: (str, pathlib.Path) -> None
129 3
    assert 0 == nbpublish.run(
130
        [
131
            str(ipynb_app.input_file),
132
            "--outformat",
133
            "latex_ipypublish_main",
134
            "--outpath",
135
            str(ipynb_app.converted_path),
136
            "-pt",
137
        ]
138
    )
139 3
    assert ipynb_app.converted_path.joinpath(
140
        ipynb_app.input_file.name.replace(".ipynb", ".tex")
141
    ).exists()
142

143

144 3
@pytest.mark.requires_latexmk
145 3
@pytest.mark.ipynb("basic_nb")
146 3
def test_nbpublish_to_pdf(ipynb_app):
147
    # type: (str, pathlib.Path) -> None
148 3
    assert 0 == nbpublish.run(
149
        [
150
            str(ipynb_app.input_file),
151
            "--outformat",
152
            "latex_ipypublish_main",
153
            "--outpath",
154
            str(ipynb_app.converted_path),
155
            "--create-pdf",
156
            "-pt",
157
        ]
158
    )
159 3
    assert ipynb_app.converted_path.joinpath(
160
        ipynb_app.input_file.name.replace(".ipynb", ".pdf")
161
    ).exists()

Read our documentation on viewing source code .

Loading