-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
125 lines (112 loc) · 4.01 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
from random import choice
from unittest import TestCase, main
from xml.etree.ElementTree import canonicalize
from markdown import Markdown
from markdown_gfm_admonition import GfmAdmonitionExtension
class GfmAdmonitionTestCase(TestCase):
def setUp(self) -> None:
ext = choice([
GfmAdmonitionExtension(),
"markdown_gfm_admonition:GfmAdmonitionExtension",
"gfm_admonition",
])
self.md = Markdown(extensions=[ext])
def assertHtmlEqual(self, expected: str, actual: str):
self.assertEqual(
canonicalize(
f"<body>{expected}</body>",
with_comments=False,
strip_text=True,
),
canonicalize(
f"<body>{actual}</body>",
with_comments=False,
strip_text=True,
),
)
def testNote(self):
result = self.md.convert(
"> This is not an admonition block.\n"
"\n"
"---\n"
"\n"
"> [!NOTE] \n"
"> Highlights information that users should take into account,\n"
"> even when skimming.\n"
)
self.assertHtmlEqual(
"<blockquote><p>This is not an admonition block.</p></blockquote>"
'<hr></hr><div class="admonition note"><p class="admonition-title">'
"Note</p><p>Highlights information that users should take into "
"account,\neven when skimming.</p></div>",
result
)
def testTip(self):
result = self.md.convert(
"> [!TIP]\n"
"> Optional information to help a user be more successful.\n"
"\n"
"---\n"
"> This is not an admonition block.\n"
)
self.assertHtmlEqual(
'<div class="admonition tip"><p class="admonition-title">Tip</p>'
"<p>Optional information to help a user be more successful.</p>"
"</div><hr></hr><blockquote><p>This is not an admonition block.</p>"
"</blockquote>",
result
)
def testImportant(self):
result = self.md.convert(
"> [!IMPORTANT]\n"
">\n"
"> Crucial information necessary for users to succeed."
)
self.assertHtmlEqual(
'<div class="admonition important"><p class="admonition-title">'
"Important</p><p>Crucial information necessary for users to "
"succeed.</p></div>",
result
)
def testWarning(self):
result = self.md.convert(
"> [!WARNING]\n"
"> \n"
"> Critical content demanding immediate user attention due to "
"potential risks.\n"
)
self.assertHtmlEqual(
'<div class="admonition warning"><p class="admonition-title">'
"Warning</p><p>Critical content demanding immediate user attention "
"due to potential risks.</p></div>",
result
)
def testCuation(self):
result = self.md.convert(
"> [!CAUTION]\n"
"> \n"
"> Negative potential consequences of an action."
)
self.assertHtmlEqual(
'<div class="admonition caution"><p class="admonition-title">'
"Caution</p><p>Negative potential consequences of an action.</p>"
"</div>",
result
)
def testEscapedBrackets(self):
result = self.md.convert(
"> \\[!TIP\\]\n"
"> Optional information to help a user be more successful.\n"
"\n"
"---\n"
"> This is not an admonition block.\n"
)
self.assertHtmlEqual(
'<div class="admonition tip"><p class="admonition-title">Tip</p>'
"<p>Optional information to help a user be more successful.</p>"
"</div><hr></hr><blockquote><p>This is not an admonition block.</p>"
"</blockquote>",
result
)
if __name__ == "__main__":
main()