Debian Codegraph @

tests/test_extensions/test_blocks/test_details.py

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