Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_decorations.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_decorations.py 9425 2023-06-30 14:56:47Z milde $
4 # Author: David Goodger <[email protected]>
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Tests for the "header" & "footer" directives.
9 """
10
11 from pathlib import Path
12 import sys
13 import unittest
14
15 if __name__ == '__main__':
16 # prepend the "docutils root" to the Python library path
17 # so we import the local `docutils` package.
18 sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
19
20 from docutils.frontend import get_default_settings
21 from docutils.parsers.rst import Parser
22 from docutils.utils import new_document
23
24
25 class ParserTestCase(unittest.TestCase):
26 def test_parser(self):
27 parser = Parser()
28 settings = get_default_settings(Parser)
29 settings.warning_stream = ''
30 for name, cases in totest.items():
31 for casenum, (case_input, case_expected) in enumerate(cases):
32 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
33 document = new_document('test data', settings.copy())
34 parser.parse(case_input, document)
35 output = document.pformat()
36 self.assertEqual(case_expected, output)
37
38
39 totest = {}
40
41 totest['headers'] = [
42 ["""\
43 .. header:: a paragraph for the header
44 """,
45 """\
46 <document source="test data">
47 <decoration>
48 <header>
49 <paragraph>
50 a paragraph for the header
51 """],
52 ["""\
53 .. header::
54 """,
55 """\
56 <document source="test data">
57 <system_message level="3" line="1" source="test data" type="ERROR">
58 <paragraph>
59 Content block expected for the "header" directive; none found.
60 <literal_block xml:space="preserve">
61 .. header::
62 """],
63 ["""\
64 .. header:: first part of the header
65 .. header:: second part of the header
66 """,
67 """\
68 <document source="test data">
69 <decoration>
70 <header>
71 <paragraph>
72 first part of the header
73 <paragraph>
74 second part of the header
75 """],
76 ]
77
78 totest['footers'] = [
79 ["""\
80 .. footer:: a paragraph for the footer
81 """,
82 """\
83 <document source="test data">
84 <decoration>
85 <footer>
86 <paragraph>
87 a paragraph for the footer
88 """],
89 ["""\
90 .. footer:: even if a footer is declared first
91 .. header:: the header appears first
92 """,
93 """\
94 <document source="test data">
95 <decoration>
96 <header>
97 <paragraph>
98 the header appears first
99 <footer>
100 <paragraph>
101 even if a footer is declared first
102 """],
103 ]
104
105
106 if __name__ == '__main__':
107 unittest.main()