1
|
|
|
""" |
2
|
|
|
Test pandoc-codeblock-include filter. |
3
|
|
|
""" |
4
|
|
|
|
5
|
|
|
from os import path |
6
|
|
|
from pathlib import Path |
7
|
|
|
from unittest import TestCase |
8
|
|
|
|
9
|
|
|
from panflute import convert_text |
10
|
|
|
|
11
|
|
|
from pandoc_codeblock_include import main |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class IncludeTest(TestCase): |
15
|
|
|
""" |
16
|
|
|
Test pandoc-codeblock-include filter. |
17
|
|
|
""" |
18
|
|
|
|
19
|
|
|
@staticmethod |
20
|
|
|
def scenario(): |
21
|
|
|
""" |
22
|
|
|
Get all tests |
23
|
|
|
|
24
|
|
|
Returns |
25
|
|
|
------- |
26
|
|
|
A list of all tests. |
27
|
|
|
""" |
28
|
|
|
return [ |
29
|
|
|
("content1.md", "markdown", "expected1.md"), |
30
|
|
|
("content2.md", "markdown", "expected2.md"), |
31
|
|
|
("content3.md", "markdown", "expected3.md"), |
32
|
|
|
("content4.md", "latex", "expected4.md"), |
33
|
|
|
("content5.md", "markdown", "expected5.md"), |
34
|
|
|
("content6.md", "markdown", "expected6.md"), |
35
|
|
|
] |
36
|
|
|
|
37
|
|
|
def test_include(self): |
38
|
|
|
""" |
39
|
|
|
Test include function (via main). |
40
|
|
|
""" |
41
|
|
|
for content, output, expected in IncludeTest.scenario(): |
42
|
|
|
folder = path.abspath(path.dirname(__file__)) |
43
|
|
|
content_text = Path(path.join(folder, content)).read_text() |
44
|
|
|
expected_text = Path(path.join(folder, expected)).read_text() |
45
|
|
|
|
46
|
|
|
doc = convert_text(content_text, standalone=True) |
47
|
|
|
doc.format = output |
48
|
|
|
|
49
|
|
|
self.assertEqual( |
50
|
|
|
convert_text( |
51
|
|
|
main(doc), |
52
|
|
|
standalone=True, |
53
|
|
|
input_format="panflute", |
54
|
|
|
output_format="markdown", |
55
|
|
|
), |
56
|
|
|
expected_text, |
57
|
|
|
"Error in converting " |
58
|
|
|
+ content |
59
|
|
|
+ " to " |
60
|
|
|
+ expected |
61
|
|
|
+ " with format " |
62
|
|
|
+ output, |
63
|
|
|
) |
64
|
|
|
|