-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.py
125 lines (113 loc) · 3.46 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import re
import unittest
import textwrap
import markdown
from md_condition.extension import ConditionExtension
class TestCondition(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.md = markdown.Markdown(
extensions=[ConditionExtension(symbol='DEBUG')])
def assertExpectedMarkdown(self, md_input, expected_output):
output = self.md.convert(textwrap.dedent(md_input))
expected = textwrap.dedent(expected_output)
try:
self.assertEqual(output, expected)
except AssertionError as e:
raise AssertionError('\n' + re.sub("' != '", '\n!=\n', e.message))
def test_single(self):
md_input = """\
# 1
<!--- #if DEBUG -->
DEBUG
<!--- #endif -->
# 2
<!--- #if RELEASE -->
RELEASE
<!--- #endif -->
# 3"""
expected_result = """\
<h1>1</h1>
<p>DEBUG</p>
<h1>2</h1>
<h1>3</h1>"""
self.assertExpectedMarkdown(md_input, expected_result)
def test_single_else(self):
md_input = """\
# 1
<!--- #if DEBUG -->
DEBUG
<!--- #else -->
not DEBUG
<!--- #endif -->
# 2
<!--- #if RELEASE -->
RELEASE
<!--- #else -->
not RELEASE
<!--- #endif -->
# 3"""
expected_result = """\
<h1>1</h1>
<p>DEBUG</p>
<h1>2</h1>
<p>not RELEASE</p>
<h1>3</h1>"""
self.assertExpectedMarkdown(md_input, expected_result)
def test_double(self):
md_input = """\
# 1
<!--- #if DEBUG RELEASE -->
DEBUG RELEASE
<!--- #endif -->
# 2
<!--- #if RELEASE -->
RELEASE
<!--- #endif -->
# 3"""
expected_result = """\
<h1>1</h1>
<p>DEBUG RELEASE</p>
<h1>2</h1>
<h1>3</h1>"""
self.assertExpectedMarkdown(md_input, expected_result)
def test_double_else(self):
md_input = """\
# 1
<!--- #if DEBUG RELEASE -->
DEBUG RELEASE
<!--- #else -->
else DEBUG RELEASE
<!--- #endif -->
# 2
<!--- #if RELEASE -->
RELEASE
<!--- #else -->
not RELEASE
<!--- #endif -->
# 3"""
expected_result = """\
<h1>1</h1>
<p>DEBUG RELEASE</p>
<h1>2</h1>
<p>not RELEASE</p>
<h1>3</h1>"""
self.assertExpectedMarkdown(md_input, expected_result)
def test_unbalance(self):
md_input = """\
<!--- #if DEBUG RELEASE -->
# 1"""
with self.assertRaises(AssertionError) as ae:
self.md.convert(textwrap.dedent(md_input))
print(ae.exception)
def test_unbalance_end(self):
md_input = """\
<!--- #if DEBUG RELEASE -->
# 1
<!--- #endif -->
<!--- #endif -->"""
with self.assertRaises(AssertionError) as ae:
self.md.convert(textwrap.dedent(md_input))
print(ae.exception)
if __name__ == "__main__":
unittest.main()