chrisjsewell / ipypublish
1 3
from ipypublish.filters_pandoc.main import jinja_filter
2 3
from ipypublish.filters_pandoc.utils import create_ipub_meta
3

4

5 3
def test_basic():
6

7 3
    out_str = jinja_filter("a", "rst", {}, {})
8 3
    assert out_str == "a"
9

10

11 3
def test_reference():
12

13 3
    out_str = jinja_filter("@label", "rst", {}, {})
14 3
    assert out_str == ":cite:`label`"
15

16

17 3
def test_reference_prefix():
18

19 3
    out_str = jinja_filter("+@label", "rst", {}, {})
20 3
    assert out_str == ":numref:`label`"
21

22

23 3
def test_option_in_nb_meta():
24

25 3
    out_str = jinja_filter(
26
        "+@label", "rst", create_ipub_meta({"use_numref": False}), {}
27
    )
28 3
    assert out_str == ":ref:`label`"
29

30

31 3
def test_option_in_cell_meta():
32

33 3
    out_str = jinja_filter(
34
        "+@label",
35
        "rst",
36
        create_ipub_meta({"use_numref": False}),
37
        create_ipub_meta({"use_numref": True}),
38
    )
39 3
    assert out_str == ":numref:`label`"
40

41

42 3
def test_option_in_top_matter():
43
    # TODO create ipub yaml from IPUB_META_ROUTE
44

45 3
    in_str = "\n".join(
46
        ["---", "ipub:", "  pandoc:", "    use_numref: true", "", "...", "", "+@label"]
47
    )
48

49 3
    out_str = jinja_filter(in_str, "rst", create_ipub_meta({"use_numref": False}), {})
50 3
    assert out_str == ":numref:`label`"
51

52

53 3
def test_at_notation_false():
54

55 3
    out_str = jinja_filter(
56
        "+@label", "rst", create_ipub_meta({"at_notation": False}), {}
57
    )
58 3
    assert out_str == "+ :cite:`label`"
59

60

61 3
def test_remove_filter():
62

63 3
    out_str = jinja_filter(
64
        "+@label", "rst", create_ipub_meta({"apply_filters": False}), {}
65
    )
66 3
    assert out_str == "+@label"
67

68

69 3
def test_complex_equation():
70

71 3
    in_source = [
72
        "$$\\begin{equation*}\n",
73
        "f(x) = \\left\\{\n",
74
        "\\begin{array}{ll}\n",
75
        "\\; x \\qquad x \\geq 0 \\\\\n",
76
        "\\; 0 \\qquad else\n",
77
        "\\end{array}\n",
78
        "\\right.\n",
79
        "\\end{equation*}$$",
80
    ]
81

82 3
    out_string = jinja_filter("".join(in_source), "rst", create_ipub_meta({}), {})
83 3
    expected = [
84
        ".. math::",
85
        "   :nowrap:",
86
        "",
87
        "   \\begin{equation*}",
88
        "   f(x) = \\left\\{",
89
        "   \\begin{array}{ll}",
90
        "   \\; x \\qquad x \\geq 0 \\\\",
91
        "   \\; 0 \\qquad else",
92
        "   \\end{array}",
93
        "   \\right.",
94
        "   \\end{equation*}",
95
    ]
96 3
    assert out_string.strip() == "\n".join(expected)

Read our documentation on viewing source code .

Loading