Debian Codegraph @

tests/test_extensions/test_blocks/test_admonitions.py

raw
1 """Test cases for Blocks (admonitions)."""
2 from ... import util
3
4
5 class TestBlocksAdmonitions(util.MdCase):
6 """Test Blocks admonitions cases."""
7
8 extension = ['pymdownx.blocks.admonition']
9 extension_configs = {
10 'pymdownx.blocks.admonition': {
11 'types': [
12 'note',
13 'custom',
14 {'name': 'custom2'},
15 {'name': 'custom3', 'class': 'different'},
16 {'name': 'custom4', 'class': 'different', 'title': 'Default'},
17 {'name': 'custom5', 'title': 'Default'}
18 ]
19 }
20 }
21
22 def test_optional_title(self):
23 """Test that tab is not processed if title is omitted."""
24
25 self.check_markdown(
26 R'''
27 /// admonition
28 Some *content*
29 ///
30 ''',
31 r'''
32 <div class="admonition">
33 <p>Some <em>content</em></p>
34 </div>
35 ''',
36 True
37 )
38
39 def test_type_no_title(self):
40 """Test test type as title."""
41
42 self.check_markdown(
43 R'''
44 /// admonition
45 type: note
46 attrs: {class: other}
47
48 Some *content*
49 ///
50 ''',
51 r'''
52 <div class="admonition note other">
53 <p class="admonition-title">Note</p>
54 <p>Some <em>content</em></p>
55 </div>
56 ''',
57 True
58 )
59
60 def test_type_empty_title(self):
61 """Test test empty title."""
62
63 self.check_markdown(
64 R'''
65 /// admonition |
66 type: note
67 attrs: {class: other}
68
69 Some *content*
70 ///
71 ''',
72 r'''
73 <div class="admonition note other">
74 <p>Some <em>content</em></p>
75 </div>
76 ''',
77 True
78 )
79
80 def test_admonition(self):
81 """Test admonition with title."""
82
83 self.check_markdown(
84 R'''
85 /// admonition | A Title
86 Some *content*
87 ///
88 ''',
89 r'''
90 <div class="admonition">
91 <p class="admonition-title">A Title</p>
92 <p>Some <em>content</em></p>
93 </div>
94 ''',
95 True
96 )
97
98 def test_note_no_title(self):
99 """Test note with no title."""
100
101 self.check_markdown(
102 R'''
103 /// note
104 Some *content*
105 ///
106 ''',
107 r'''
108 <div class="admonition note">
109 <p class="admonition-title">Note</p>
110 <p>Some <em>content</em></p>
111 </div>
112 ''',
113 True
114 )
115
116 def test_note_with_title(self):
117 """Test note with no title."""
118
119 self.check_markdown(
120 R'''
121 /// note | A Title
122 Some *content*
123 ///
124 ''',
125 r'''
126 <div class="admonition note">
127 <p class="admonition-title">A Title</p>
128 <p>Some <em>content</em></p>
129 </div>
130 ''',
131 True
132 )
133
134 def test_custom(self):
135 """Test custom type (one not shipped by default)."""
136
137 self.check_markdown(
138 R'''
139 /// custom | A Title
140 Some *content*
141 ///
142 ''',
143 r'''
144 <div class="admonition custom">
145 <p class="admonition-title">A Title</p>
146 <p>Some <em>content</em></p>
147 </div>
148 ''',
149 True
150 )
151
152 def test_custom_title(self):
153 """Test custom title."""
154
155 self.check_markdown(
156 R'''
157 /// custom
158 Some *content*
159 ///
160 ''',
161 r'''
162 <div class="admonition custom">
163 <p class="admonition-title">Custom</p>
164 <p>Some <em>content</em></p>
165 </div>
166 ''',
167 True
168 )
169
170 def test_custom_dict_title(self):
171 """Test custom title with dictionary form."""
172
173 self.check_markdown(
174 R'''
175 /// custom2
176 Some *content*
177 ///
178 ''',
179 r'''
180 <div class="admonition custom2">
181 <p class="admonition-title">Custom2</p>
182 <p>Some <em>content</em></p>
183 </div>
184 ''',
185 True
186 )
187
188 def test_custom_explicit_title(self):
189 """Test custom with an explicit, default title."""
190
191 self.check_markdown(
192 R'''
193 /// custom5
194 Some *content*
195 ///
196 ''',
197 r'''
198 <div class="admonition custom5">
199 <p class="admonition-title">Default</p>
200 <p>Some <em>content</em></p>
201 </div>
202 ''',
203 True
204 )
205
206 def test_custom_with_class(self):
207 """Test custom title with configured custom class."""
208
209 self.check_markdown(
210 R'''
211 /// custom3
212 Some *content*
213 ///
214 ''',
215 r'''
216 <div class="admonition different">
217 <p class="admonition-title">Different</p>
218 <p>Some <em>content</em></p>
219 </div>
220 ''',
221 True
222 )
223
224 def test_custom_with_class_and_title(self):
225 """Test custom title with configured custom class and title."""
226
227 self.check_markdown(
228 R'''
229 /// custom4
230 Some *content*
231 ///
232 ''',
233 r'''
234 <div class="admonition different">
235 <p class="admonition-title">Default</p>
236 <p>Some <em>content</em></p>
237 </div>
238 ''',
239 True
240 )