4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
8 Tests for docutils.transforms.frontmatter.DocTitle.
11 from __init__
import DocutilsTestSupport
12 from docutils
.transforms
.frontmatter
import DocTitle
, SectionSubTitle
13 from docutils
.parsers
.rst
import Parser
, Directive
14 from docutils
.parsers
.rst
.directives
import register_directive
16 # dummy directive to test attribute merging:
17 class AddNameToDocumentTitle(Directive
):
18 required_arguments
= 0
19 optional_arguments
= 0
20 final_argument_whitespace
= True
25 document
= self
.state_machine
.document
26 document
['names'].append('Name')
29 register_directive('add-name-to-title', AddNameToDocumentTitle
)
33 s
= DocutilsTestSupport
.TransformTestSuite(parser
)
34 s
.generateTests(totest
)
39 totest
['section_headers'] = ((DocTitle
, SectionSubTitle
), [
41 .. test title promotion
49 <document ids="title" names="title" source="test data" title="Title">
52 <comment xml:space="preserve">
60 Paragraph (no blank line).
63 <document ids="title" names="title" source="test data" title="Title">
67 Paragraph (no blank line).
78 <document source="test data">
81 <section ids="title" names="title">
94 .. title:: Another Title
96 Test title, subtitle, and title metadata.
99 <document ids="title" names="title" source="test data" title="Another Title">
102 <subtitle ids="subtitle" names="subtitle">
105 Test title, subtitle, and title metadata.
111 Test short underline.
114 <document ids="title" names="title" source="test data" title="Title">
117 <system_message level="2" line="2" source="test data" type="WARNING">
119 Title underline too short.
120 <literal_block xml:space="preserve">
124 Test short underline.
131 Test long title and space normalization.
132 The system_message should move after the document title
133 (it was before the beginning of the section).
136 <document ids="long-title" names="long\ title" source="test data" title="Long Title">
139 <system_message level="2" line="1" source="test data" type="WARNING">
141 Title overline too short.
142 <literal_block xml:space="preserve">
147 Test long title and space normalization.
148 The system_message should move after the document title
149 (it was before the beginning of the section).
152 .. Test multiple second-level titles.
167 <document ids="title-1" names="title\ 1" source="test data" title="Title 1">
170 <comment xml:space="preserve">
171 Test multiple second-level titles.
174 <section ids="title-2" names="title\ 2">
179 <section ids="title-3" names="title\ 3">
186 .. |foo| replace:: bar
188 .. _invisible target:
192 This title should be the document title despite the
193 substitution_definition.
196 <document ids="title" names="title" source="test data" title="Title">
199 <substitution_definition names="foo">
201 <target ids="invisible-target" names="invisible\ target">
203 This title should be the document title despite the
204 substitution_definition.
207 (Because of this paragraph, the following is not a doc title.)
225 <document source="test data">
227 (Because of this paragraph, the following is not a doc title.)
228 <section ids="section-title" names="section\ title">
231 <subtitle ids="subtitle" names="subtitle">
233 <section ids="another-section" names="another\ section">
236 <subtitle ids="another-subtitle" names="another\ subtitle">
244 This is a document, it flows nicely, so the attributes of it are at the
247 .. add-name-to-title::
251 <document ids="title" names="Name title" source="test data" title="Title">
255 This is a document, it flows nicely, so the attributes of it are at the
261 if __name__
== '__main__':
263 unittest
.main(defaultTest
='suite')