File: test_targets.py

package info (click to toggle)
python-docutils 0.3.7-2sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,872 kB
  • ctags: 2,908
  • sloc: python: 27,538; lisp: 641; makefile: 102
file content (459 lines) | stat: -rwxr-xr-x 12,540 bytes parent folder | download
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#!/usr/bin/python

# Author: David Goodger
# Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.12 $
# Date: $Date: 2004/01/04 17:44:46 $
# Copyright: This module has been placed in the public domain.

"""
Tests for states.py.
"""

from __init__ import DocutilsTestSupport

def suite():
    s = DocutilsTestSupport.ParserTestSuite()
    s.generateTests(totest)
    return s

totest = {}

totest['targets'] = [
["""\
.. _target:

(Internal hyperlink target.)
""",
"""\
<document source="test data">
    <target id="target" name="target">
    <paragraph>
        (Internal hyperlink target.)
"""],
["""\
.. _optional space before colon :
""",
"""\
<document source="test data">
    <target id="optional-space-before-colon" name="optional space before colon">
"""],
["""\
External hyperlink targets:

.. _one-liner: http://structuredtext.sourceforge.net

.. _starts-on-this-line: http://
                         structuredtext.
                         sourceforge.net

.. _entirely-below:
   http://structuredtext.
   sourceforge.net

.. _not-indirect: uri\\_
""",
"""\
<document source="test data">
    <paragraph>
        External hyperlink targets:
    <target id="one-liner" name="one-liner" refuri="http://structuredtext.sourceforge.net">
    <target id="starts-on-this-line" name="starts-on-this-line" refuri="http://structuredtext.sourceforge.net">
    <target id="entirely-below" name="entirely-below" refuri="http://structuredtext.sourceforge.net">
    <target id="not-indirect" name="not-indirect" refuri="uri_">
"""],
["""\
Indirect hyperlink targets:

.. _target1: reference_

.. _target2: `phrase-link reference`_
""",
"""\
<document source="test data">
    <paragraph>
        Indirect hyperlink targets:
    <target id="target1" name="target1" refname="reference">
    <target id="target2" name="target2" refname="phrase-link reference">
"""],
["""\
.. _target1: Not a proper hyperlink target

.. _target2: Although it ends with an underscore, this is not a phrase-link_

.. _target3: A multi-line verson of something
   ending with an underscore, but not a phrase-link_
""",
"""\
<document source="test data">
    <system_message level="2" line="1" source="test data" type="WARNING">
        <paragraph>
            Hyperlink target contains whitespace. Perhaps a footnote was intended?
        <literal_block xml:space="preserve">
            .. _target1: Not a proper hyperlink target
    <system_message level="2" line="3" source="test data" type="WARNING">
        <paragraph>
            Hyperlink target contains whitespace. Perhaps a footnote was intended?
        <literal_block xml:space="preserve">
            .. _target2: Although it ends with an underscore, this is not a phrase-link_
    <system_message level="2" line="5" source="test data" type="WARNING">
        <paragraph>
            Hyperlink target contains whitespace. Perhaps a footnote was intended?
        <literal_block xml:space="preserve">
            .. _target3: A multi-line verson of something
               ending with an underscore, but not a phrase-link_
"""],
["""\
.. __: Not a proper hyperlink target

__ Although it ends with an underscore, this is not a phrase-link_

__ A multi-line verson of something
   ending with an underscore, but not a phrase-link_
""",
"""\
<document source="test data">
    <system_message level="2" line="1" source="test data" type="WARNING">
        <paragraph>
            Hyperlink target contains whitespace. Perhaps a footnote was intended?
        <literal_block xml:space="preserve">
            .. __: Not a proper hyperlink target
    <system_message level="2" line="3" source="test data" type="WARNING">
        <paragraph>
            Hyperlink target contains whitespace. Perhaps a footnote was intended?
        <literal_block xml:space="preserve">
            __ Although it ends with an underscore, this is not a phrase-link_
    <system_message level="2" line="5" source="test data" type="WARNING">
        <paragraph>
            Hyperlink target contains whitespace. Perhaps a footnote was intended?
        <literal_block xml:space="preserve">
            __ A multi-line verson of something
            ending with an underscore, but not a phrase-link_
"""],
["""\
.. _a long target name:

.. _`a target name: including a colon (quoted)`:

.. _a target name\: including a colon (escaped):
""",
"""\
<document source="test data">
    <target id="a-long-target-name" name="a long target name">
    <target id="a-target-name-including-a-colon-quoted" name="a target name: including a colon (quoted)">
    <target id="a-target-name-including-a-colon-escaped" name="a target name: including a colon (escaped)">
"""],
["""\
.. _a very long target name,
   split across lines:
.. _`and another,
   with backquotes`:
""",
"""\
<document source="test data">
    <target id="a-very-long-target-name-split-across-lines" name="a very long target name, split across lines">
    <target id="and-another-with-backquotes" name="and another, with backquotes">
"""],
["""\
External hyperlink:

.. _target: http://www.python.org/
""",
"""\
<document source="test data">
    <paragraph>
        External hyperlink:
    <target id="target" name="target" refuri="http://www.python.org/">
"""],
["""\
.. _email: jdoe@example.com

.. _multi-line email: jdoe
   @example.com
""",
"""\
<document source="test data">
    <target id="email" name="email" refuri="mailto:jdoe@example.com">
    <target id="multi-line-email" name="multi-line email" refuri="mailto:jdoe@example.com">
"""],
["""\
Duplicate external targets (different URIs):

.. _target: first

.. _target: second
""",
"""\
<document source="test data">
    <paragraph>
        Duplicate external targets (different URIs):
    <target dupname="target" id="target" refuri="first">
    <system_message backrefs="id1" level="2" line="5" source="test data" type="WARNING">
        <paragraph>
            Duplicate explicit target name: "target".
    <target dupname="target" id="id1" refuri="second">
"""],
["""\
Duplicate external targets (same URIs):

.. _target: first

.. _target: first
""",
"""\
<document source="test data">
    <paragraph>
        Duplicate external targets (same URIs):
    <target id="target" name="target" refuri="first">
    <system_message backrefs="id1" level="1" line="5" source="test data" type="INFO">
        <paragraph>
            Duplicate explicit target name: "target".
    <target dupname="target" id="id1" refuri="first">
"""],
["""\
Duplicate implicit targets.

Title
=====

Paragraph.

Title
=====

Paragraph.
""",
"""\
<document source="test data">
    <paragraph>
        Duplicate implicit targets.
    <section dupname="title" id="title">
        <title>
            Title
        <paragraph>
            Paragraph.
    <section dupname="title" id="id1">
        <title>
            Title
        <system_message backrefs="id1" level="1" line="9" source="test data" type="INFO">
            <paragraph>
                Duplicate implicit target name: "title".
        <paragraph>
            Paragraph.
"""],
["""\
Duplicate implicit/explicit targets.

Title
=====

.. _title:

Paragraph.
""",
"""\
<document source="test data">
    <paragraph>
        Duplicate implicit/explicit targets.
    <section dupname="title" id="title">
        <title>
            Title
        <system_message backrefs="id1" level="1" line="6" source="test data" type="INFO">
            <paragraph>
                Duplicate implicit target name: "title".
        <target id="id1" name="title">
        <paragraph>
            Paragraph.
"""],
["""\
Duplicate explicit targets.

.. _title:

First.

.. _title:

Second.

.. _title:

Third.
""",
"""\
<document source="test data">
    <paragraph>
        Duplicate explicit targets.
    <target dupname="title" id="title">
    <paragraph>
        First.
    <system_message backrefs="id1" level="2" line="7" source="test data" type="WARNING">
        <paragraph>
            Duplicate explicit target name: "title".
    <target dupname="title" id="id1">
    <paragraph>
        Second.
    <system_message backrefs="id2" level="2" line="11" source="test data" type="WARNING">
        <paragraph>
            Duplicate explicit target name: "title".
    <target dupname="title" id="id2">
    <paragraph>
        Third.
"""],
["""\
Duplicate targets:

Target
======

Implicit section header target.

.. [target] Citation target.

.. [#target] Autonumber-labeled footnote target.

.. _target:

Explicit internal target.

.. _target: Explicit_external_target
""",
"""\
<document source="test data">
    <paragraph>
        Duplicate targets:
    <section dupname="target" id="target">
        <title>
            Target
        <paragraph>
            Implicit section header target.
        <citation dupname="target" id="id1">
            <label>
                target
            <system_message backrefs="id1" level="1" line="8" source="test data" type="INFO">
                <paragraph>
                    Duplicate implicit target name: "target".
            <paragraph>
                Citation target.
        <footnote auto="1" dupname="target" id="id2">
            <system_message backrefs="id2" level="2" line="10" source="test data" type="WARNING">
                <paragraph>
                    Duplicate explicit target name: "target".
            <paragraph>
                Autonumber-labeled footnote target.
        <system_message backrefs="id3" level="2" line="12" source="test data" type="WARNING">
            <paragraph>
                Duplicate explicit target name: "target".
        <target dupname="target" id="id3">
        <paragraph>
            Explicit internal target.
        <system_message backrefs="id4" level="2" line="16" source="test data" type="WARNING">
            <paragraph>
                Duplicate explicit target name: "target".
        <target dupname="target" id="id4" refuri="Explicit_external_target">
"""],
]

totest['anonymous_targets'] = [
["""\
Anonymous external hyperlink target:

.. __: http://w3c.org/
""",
"""\
<document source="test data">
    <paragraph>
        Anonymous external hyperlink target:
    <target anonymous="1" id="id1" refuri="http://w3c.org/">
"""],
["""\
Anonymous external hyperlink target:

__ http://w3c.org/
""",
"""\
<document source="test data">
    <paragraph>
        Anonymous external hyperlink target:
    <target anonymous="1" id="id1" refuri="http://w3c.org/">
"""],
["""\
Anonymous indirect hyperlink target:

.. __: reference_
""",
"""\
<document source="test data">
    <paragraph>
        Anonymous indirect hyperlink target:
    <target anonymous="1" id="id1" refname="reference">
"""],
["""\
Anonymous external hyperlink target, not indirect:

__ uri\\_
""",
"""\
<document source="test data">
    <paragraph>
        Anonymous external hyperlink target, not indirect:
    <target anonymous="1" id="id1" refuri="uri_">
"""],
["""\
Anonymous indirect hyperlink targets:

__ reference_
__ `a very long
   reference`_
""",
"""\
<document source="test data">
    <paragraph>
        Anonymous indirect hyperlink targets:
    <target anonymous="1" id="id1" refname="reference">
    <target anonymous="1" id="id2" refname="a very long reference">
"""],
["""\
Mixed anonymous & named indirect hyperlink targets:

__ reference_
.. __: reference_
__ reference_
.. _target1: reference_
no blank line

.. _target2: reference_
__ reference_
.. __: reference_
__ reference_
no blank line
""",
"""\
<document source="test data">
    <paragraph>
        Mixed anonymous & named indirect hyperlink targets:
    <target anonymous="1" id="id1" refname="reference">
    <target anonymous="1" id="id2" refname="reference">
    <target anonymous="1" id="id3" refname="reference">
    <target id="target1" name="target1" refname="reference">
    <system_message level="2" line="7" source="test data" type="WARNING">
        <paragraph>
            Explicit markup ends without a blank line; unexpected unindent.
    <paragraph>
        no blank line
    <target id="target2" name="target2" refname="reference">
    <target anonymous="1" id="id4" refname="reference">
    <target anonymous="1" id="id5" refname="reference">
    <target anonymous="1" id="id6" refname="reference">
    <system_message level="2" line="13" source="test data" type="WARNING">
        <paragraph>
            Explicit markup ends without a blank line; unexpected unindent.
    <paragraph>
        no blank line
"""],
]


if __name__ == '__main__':
    import unittest
    unittest.main(defaultTest='suite')