Website: add template and basic stylesheet with menu. Update buildhtml.py (and theref...
[docutils.git] / sandbox / gitpull / web_stylesheet_and_menu / test / test_parsers / test_rst / test_directives / test_role.py
blob78fb8fdc7b6854083abccb4dbe5e497b2d609e82
1 #! /usr/bin/env python
3 # $Id$
4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Tests for misc.py "role" directive.
9 """
11 from __init__ import DocutilsTestSupport
14 def suite():
15 s = DocutilsTestSupport.ParserTestSuite()
16 s.generateTests(totest)
17 return s
19 totest = {}
21 totest['role'] = [
22 ["""\
23 .. role:: custom
24 .. role:: special
26 :custom:`interpreted` and :special:`interpreted`
27 """,
28 """\
29 <document source="test data">
30 <paragraph>
31 <inline classes="custom">
32 interpreted
33 and \n\
34 <inline classes="special">
35 interpreted
36 """],
37 ["""\
38 .. role:: custom
39 :class: custom-class
40 .. role:: special
41 :class: special-class
43 :custom:`interpreted` and :special:`interpreted`
44 """,
45 """\
46 <document source="test data">
47 <paragraph>
48 <inline classes="custom-class">
49 interpreted
50 and \n\
51 <inline classes="special-class">
52 interpreted
53 """],
54 ["""\
55 Must define :custom:`interpreted` before using it.
57 .. role:: custom
59 Now that it's defined, :custom:`interpreted` works.
60 """,
61 """\
62 <document source="test data">
63 <paragraph>
64 Must define
65 <problematic ids="id2" refid="id1">
66 :custom:`interpreted`
67 before using it.
68 <system_message level="1" line="1" source="test data" type="INFO">
69 <paragraph>
70 No role entry for "custom" in module "docutils.parsers.rst.languages.en".
71 Trying "custom" as canonical role name.
72 <system_message backrefs="id2" ids="id1" level="3" line="1" source="test data" type="ERROR">
73 <paragraph>
74 Unknown interpreted text role "custom".
75 <paragraph>
76 Now that it's defined, \n\
77 <inline classes="custom">
78 interpreted
79 works.
80 """],
81 ["""\
82 .. role:: custom(emphasis)
84 :custom:`text`
85 """,
86 """\
87 <document source="test data">
88 <paragraph>
89 <emphasis classes="custom">
90 text
91 """],
92 ["""\
93 .. role:: custom ( emphasis )
95 :custom:`text`
96 """,
97 """\
98 <document source="test data">
99 <paragraph>
100 <emphasis classes="custom">
101 text
102 """],
103 ["""\
104 .. role:: custom(emphasis)
105 :class: special
107 :custom:`text`
108 """,
109 """\
110 <document source="test data">
111 <paragraph>
112 <emphasis classes="special">
113 text
114 """],
115 ["""\
116 .. role:: custom(unknown-role)
117 """,
118 """\
119 <document source="test data">
120 <system_message level="1" line="1" source="test data" type="INFO">
121 <paragraph>
122 No role entry for "unknown-role" in module "docutils.parsers.rst.languages.en".
123 Trying "unknown-role" as canonical role name.
124 <system_message level="3" line="1" source="test data" type="ERROR">
125 <paragraph>
126 Unknown interpreted text role "unknown-role".
127 <literal_block xml:space="preserve">
128 .. role:: custom(unknown-role)
129 """],
130 ["""\
131 .. role:: custom
132 :class: 1
133 """,
134 """\
135 <document source="test data">
136 <system_message level="3" line="1" source="test data" type="ERROR">
137 <paragraph>
138 Error in "role" directive:
139 invalid option value: (option: "class"; value: '1')
140 cannot make "1" into a class name.
141 <literal_block xml:space="preserve">
142 .. role:: custom
143 :class: 1
144 """],
145 ["""\
146 .. role:: 1
147 """,
148 """\
149 <document source="test data">
150 <system_message level="3" line="1" source="test data" type="ERROR">
151 <paragraph>
152 Invalid argument for "role" directive:
153 cannot make "1" into a class name.
154 <literal_block xml:space="preserve">
155 .. role:: 1
156 """],
157 ["""\
158 .. role:: (error)
159 """,
160 """\
161 <document source="test data">
162 <system_message level="3" line="1" source="test data" type="ERROR">
163 <paragraph>
164 "role" directive arguments not valid role names: "(error)".
165 <literal_block xml:space="preserve">
166 .. role:: (error)
167 """],
168 ["""\
169 .. role::
170 """,
171 """\
172 <document source="test data">
173 <system_message level="3" line="1" source="test data" type="ERROR">
174 <paragraph>
175 "role" directive requires arguments on the first line.
176 <literal_block xml:space="preserve">
177 .. role::
178 """],
179 ["""\
180 Test
181 ----
183 .. role:: fileref(emphasis)
185 Testing a :fileref:`role` in a nested parse.
186 """,
187 """\
188 <document source="test data">
189 <section ids="test" names="test">
190 <title>
191 Test
192 <paragraph>
193 Testing a \n\
194 <emphasis classes="fileref">
195 role
196 in a nested parse.
197 """],
198 ["""\
199 .. role:: custom
200 .. role:: special
202 Empty :custom:`\ ` and empty `\ `:special:
203 """,
204 """\
205 <document source="test data">
206 <paragraph>
207 Empty
208 <inline classes="custom">
209 and empty
210 <inline classes="special">
211 """],
214 totest['raw_role'] = [
215 ["""\
216 .. role:: html(raw)
217 :format: html
219 Here's some :html:`<i>raw HTML data</i>`.
220 """,
221 """\
222 <document source="test data">
223 <paragraph>
224 Here's some \n\
225 <raw classes="html" format="html" xml:space="preserve">
226 <i>raw HTML data</i>
228 """],
229 ["""\
230 .. role:: itex(raw)
231 :format: latex html
233 Here's some itex markup: :itex:`$x^\\infty$`.
234 """,
235 """\
236 <document source="test data">
237 <paragraph>
238 Here's some itex markup: \n\
239 <raw classes="itex" format="latex html" xml:space="preserve">
240 $x^\\infty$
242 """],
243 ["""\
244 Can't use the :raw:`role` directly.
245 """,
246 """\
247 <document source="test data">
248 <paragraph>
249 Can't use the \n\
250 <problematic ids="id2" refid="id1">
251 :raw:`role`
252 directly.
253 <system_message backrefs="id2" ids="id1" level="3" line="1" source="test data" type="ERROR">
254 <paragraph>
255 No format (Writer name) is associated with this role: "raw".
256 The "raw" role cannot be used directly.
257 Instead, use the "role" directive to create a new role with an associated format.
258 """],
262 if __name__ == '__main__':
263 import unittest
264 unittest.main(defaultTest='suite')