~ubuntu-branches/ubuntu/hardy/python-docutils/hardy

« back to all changes in this revision

Viewing changes to test/test_transforms/test_transitions.py

  • Committer: Bazaar Package Importer
  • Author(s): martin f. krafft
  • Date: 2006-07-10 11:45:05 UTC
  • mfrom: (2.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20060710114505-otkhqcslevewxmz5
Tags: 0.4-3
Added build dependency on python-central (closes: #377580).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
# Author: David Goodger
 
4
# Contact: goodger@users.sourceforge.net
 
5
# Revision: $Revision: 4132 $
 
6
# Date: $Date: 2005-12-03 03:13:12 +0100 (Sat, 03 Dec 2005) $
 
7
# Copyright: This module has been placed in the public domain.
 
8
 
 
9
"""
 
10
Test module for misc.Transitions transform.
 
11
"""
 
12
 
 
13
from __init__ import DocutilsTestSupport # must be imported before docutils
 
14
from docutils.transforms.misc import Transitions
 
15
from docutils.parsers.rst import Parser
 
16
 
 
17
def suite():
 
18
    parser = Parser()
 
19
    s = DocutilsTestSupport.TransformTestSuite(parser)
 
20
    s.generateTests(totest)
 
21
    return s
 
22
 
 
23
 
 
24
totest = {}
 
25
 
 
26
totest['transitions'] = ((Transitions,), [
 
27
["""\
 
28
Section 1
 
29
=========
 
30
 
 
31
Subsection 1
 
32
------------
 
33
 
 
34
Some text.
 
35
 
 
36
----------
 
37
 
 
38
Section 2
 
39
=========
 
40
 
 
41
Some text.
 
42
""",
 
43
"""\
 
44
<document source="test data">
 
45
    <section ids="section-1" names="section\ 1">
 
46
        <title>
 
47
            Section 1
 
48
        <section ids="subsection-1" names="subsection\ 1">
 
49
            <title>
 
50
                Subsection 1
 
51
            <paragraph>
 
52
                Some text.
 
53
    <transition>
 
54
    <section ids="section-2" names="section\ 2">
 
55
        <title>
 
56
            Section 2
 
57
        <paragraph>
 
58
            Some text.
 
59
"""],
 
60
["""\
 
61
A paragraph.
 
62
 
 
63
----------
 
64
 
 
65
Section 1
 
66
=========
 
67
 
 
68
Paragraph.
 
69
""",
 
70
"""\
 
71
<document source="test data">
 
72
    <paragraph>
 
73
        A paragraph.
 
74
    <transition>
 
75
    <section ids="section-1" names="section\ 1">
 
76
        <title>
 
77
            Section 1
 
78
        <paragraph>
 
79
            Paragraph.
 
80
"""],
 
81
["""\
 
82
--------
 
83
 
 
84
A section or document may not begin with a transition.
 
85
 
 
86
The DTD specifies that two transitions may not
 
87
be adjacent:
 
88
 
 
89
--------
 
90
 
 
91
--------
 
92
 
 
93
--------
 
94
 
 
95
The DTD also specifies that a section or document
 
96
may not end with a transition.
 
97
 
 
98
--------
 
99
""",
 
100
"""\
 
101
<document source="test data">
 
102
    <system_message level="3" line="1" source="test data" type="ERROR">
 
103
        <paragraph>
 
104
            Document or section may not begin with a transition.
 
105
    <transition>
 
106
    <paragraph>
 
107
        A section or document may not begin with a transition.
 
108
    <paragraph>
 
109
        The DTD specifies that two transitions may not
 
110
        be adjacent:
 
111
    <transition>
 
112
    <system_message level="3" line="10" source="test data" type="ERROR">
 
113
        <paragraph>
 
114
            At least one body element must separate transitions; adjacent transitions are not allowed.
 
115
    <transition>
 
116
    <system_message level="3" line="12" source="test data" type="ERROR">
 
117
        <paragraph>
 
118
            At least one body element must separate transitions; adjacent transitions are not allowed.
 
119
    <transition>
 
120
    <paragraph>
 
121
        The DTD also specifies that a section or document
 
122
        may not end with a transition.
 
123
    <transition>
 
124
    <system_message level="3" line="17" source="test data" type="ERROR">
 
125
        <paragraph>
 
126
            Document may not end with a transition.
 
127
"""],
 
128
["""\
 
129
Sections with transitions at beginning and end.
 
130
 
 
131
Section 1
 
132
=========
 
133
 
 
134
----------
 
135
 
 
136
The next transition is legal:
 
137
 
 
138
----------
 
139
 
 
140
Section 2
 
141
=========
 
142
 
 
143
----------
 
144
""",
 
145
"""\
 
146
<document source="test data">
 
147
    <paragraph>
 
148
        Sections with transitions at beginning and end.
 
149
    <section ids="section-1" names="section\ 1">
 
150
        <title>
 
151
            Section 1
 
152
        <system_message level="3" line="6" source="test data" type="ERROR">
 
153
            <paragraph>
 
154
                Document or section may not begin with a transition.
 
155
        <transition>
 
156
        <paragraph>
 
157
            The next transition is legal:
 
158
    <transition>
 
159
    <section ids="section-2" names="section\ 2">
 
160
        <title>
 
161
            Section 2
 
162
        <system_message level="3" line="15" source="test data" type="ERROR">
 
163
            <paragraph>
 
164
                Document or section may not begin with a transition.
 
165
        <transition>
 
166
        <system_message level="3" line="15" source="test data" type="ERROR">
 
167
            <paragraph>
 
168
                Document may not end with a transition.
 
169
"""],
 
170
["""\
 
171
A paragraph and two transitions.
 
172
 
 
173
----------
 
174
 
 
175
----------
 
176
""", # the same:
 
177
"""\
 
178
<document source="test data">
 
179
    <paragraph>
 
180
        A paragraph and two transitions.
 
181
    <transition>
 
182
    <system_message level="3" line="5" source="test data" type="ERROR">
 
183
        <paragraph>
 
184
            At least one body element must separate transitions; adjacent transitions are not allowed.
 
185
    <transition>
 
186
    <system_message level="3" line="5" source="test data" type="ERROR">
 
187
        <paragraph>
 
188
            Document may not end with a transition.
 
189
"""],
 
190
["""\
 
191
A paragraph, two transitions, and a blank line.
 
192
 
 
193
----------
 
194
 
 
195
----------
 
196
 
 
197
""",
 
198
"""\
 
199
<document source="test data">
 
200
    <paragraph>
 
201
        A paragraph, two transitions, and a blank line.
 
202
    <transition>
 
203
    <system_message level="3" line="5" source="test data" type="ERROR">
 
204
        <paragraph>
 
205
            At least one body element must separate transitions; adjacent transitions are not allowed.
 
206
    <transition>
 
207
    <system_message level="3" line="5" source="test data" type="ERROR">
 
208
        <paragraph>
 
209
            Document may not end with a transition.
 
210
"""],
 
211
["""\
 
212
----------
 
213
 
 
214
Document beginning with a transition.
 
215
""",
 
216
"""\
 
217
<document source="test data">
 
218
    <system_message level="3" line="1" source="test data" type="ERROR">
 
219
        <paragraph>
 
220
            Document or section may not begin with a transition.
 
221
    <transition>
 
222
    <paragraph>
 
223
        Document beginning with a transition.
 
224
"""],
 
225
["""\
 
226
Section 1
 
227
=========
 
228
 
 
229
----------
 
230
 
 
231
----------
 
232
 
 
233
----------
 
234
 
 
235
Section 2
 
236
=========
 
237
 
 
238
Some text.
 
239
""",
 
240
"""\
 
241
<document source="test data">
 
242
    <section ids="section-1" names="section\ 1">
 
243
        <title>
 
244
            Section 1
 
245
        <system_message level="3" line="4" source="test data" type="ERROR">
 
246
            <paragraph>
 
247
                Document or section may not begin with a transition.
 
248
        <transition>
 
249
        <system_message level="3" line="6" source="test data" type="ERROR">
 
250
            <paragraph>
 
251
                At least one body element must separate transitions; adjacent transitions are not allowed.
 
252
        <transition>
 
253
        <system_message level="3" line="8" source="test data" type="ERROR">
 
254
            <paragraph>
 
255
                At least one body element must separate transitions; adjacent transitions are not allowed.
 
256
    <transition>
 
257
    <section ids="section-2" names="section\ 2">
 
258
        <title>
 
259
            Section 2
 
260
        <paragraph>
 
261
            Some text.
 
262
"""],
 
263
["""\
 
264
----------
 
265
 
 
266
----------
 
267
 
 
268
----------
 
269
""",
 
270
"""\
 
271
<document source="test data">
 
272
    <system_message level="3" line="1" source="test data" type="ERROR">
 
273
        <paragraph>
 
274
            Document or section may not begin with a transition.
 
275
    <transition>
 
276
    <system_message level="3" line="3" source="test data" type="ERROR">
 
277
        <paragraph>
 
278
            At least one body element must separate transitions; adjacent transitions are not allowed.
 
279
    <transition>
 
280
    <system_message level="3" line="5" source="test data" type="ERROR">
 
281
        <paragraph>
 
282
            At least one body element must separate transitions; adjacent transitions are not allowed.
 
283
    <transition>
 
284
    <system_message level="3" line="5" source="test data" type="ERROR">
 
285
        <paragraph>
 
286
            Document may not end with a transition.
 
287
"""],
 
288
["""\
 
289
A paragraph.
 
290
 
 
291
----------
 
292
 
 
293
""",
 
294
"""\
 
295
<document source="test data">
 
296
    <paragraph>
 
297
        A paragraph.
 
298
    <transition>
 
299
    <system_message level="3" line="3" source="test data" type="ERROR">
 
300
        <paragraph>
 
301
            Document may not end with a transition.
 
302
"""],
 
303
])
 
304
 
 
305
 
 
306
if __name__ == '__main__':
 
307
    import unittest
 
308
    unittest.main(defaultTest='suite')