test_margin.MarginTestCase.verify_conversion()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 39
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 39
rs 9.45
c 0
b 0
f 0
cc 1
nop 7
1
from unittest import TestCase
2
from panflute import convert_text, debug
3
4
import pandoc_latex_margin
5
6
7
class MarginTestCase(TestCase):
8
    def verify_conversion(
9
        self,
10
        text,
11
        expected,
12
        transform,
13
        input_format="markdown",
14
        output_format="latex",
15
        standalone=False,
16
    ) -> None:
17
        """
18
        Verify the conversion.
19
20
        Parameters
21
        ----------
22
        text
23
            input text
24
        expected
25
            expected text
26
        transform
27
            filter function
28
        input_format
29
            input format
30
        output_format
31
            output format
32
        standalone
33
            is the output format standalone ?
34
        """
35
        doc = convert_text(text, input_format=input_format, standalone=True)
36
        doc.format = output_format
37
        doc = transform(doc)
38
        converted = convert_text(
39
            doc.content,
40
            input_format="panflute",
41
            output_format=output_format,
42
            extra_args=["--wrap=none"],
43
            standalone=standalone,
44
        )
45
        print(converted)
46
        self.assertEqual(converted.strip(), expected.strip())
47
48
    def test_margin(self):
49
        self.verify_conversion(
50
            """
51
---
52
pandoc-latex-margin:
53
  - classes: [left]
54
    left: 1cm
55
  - classes: [right]
56
    right: 1cm
57
---
58
59
::: {.left latex-right-margin="2cm"} :::
60
Content1
61
:::::::::::::::
62
63
::: {.right latex-left-margin="2cm"} :::
64
Content2
65
:::::::::::::::
66
67
::: {latex-right-margin="2cm"} :::
68
Content3
69
:::::::::::::::
70
71
::: {latex-left-margin="2cm"} :::
72
Content4
73
:::::::::::::::
74
    
75
            """,
76
            r"""
77
\begin{pandocchangemargin}{1cm}{2cm}
78
79
Content1
80
81
\end{pandocchangemargin}
82
83
\begin{pandocchangemargin}{2cm}{1cm}
84
85
Content2
86
87
\end{pandocchangemargin}
88
89
\begin{pandocchangemargin}{0pt}{2cm}
90
91
Content3
92
93
\end{pandocchangemargin}
94
95
\begin{pandocchangemargin}{2cm}{0pt}
96
97
Content4
98
99
\end{pandocchangemargin}
100
            """,
101
            pandoc_latex_margin.main,
102
        )
103