Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_rubrics.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_rubrics.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 "rubric" directive.
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['rubrics'] = [
42 ["""\
43 .. rubric:: This is a rubric
44 """,
45 """\
46 <document source="test data">
47 <rubric>
48 This is a rubric
49 """],
50 ["""\
51 .. rubric::
52 .. rubric:: A rubric has no content
53
54 Invalid content
55 """,
56 """\
57 <document source="test data">
58 <system_message level="3" line="1" source="test data" type="ERROR">
59 <paragraph>
60 Error in "rubric" directive:
61 1 argument(s) required, 0 supplied.
62 <literal_block xml:space="preserve">
63 .. rubric::
64 <system_message level="3" line="2" source="test data" type="ERROR">
65 <paragraph>
66 Error in "rubric" directive:
67 no content permitted.
68 <literal_block xml:space="preserve">
69 .. rubric:: A rubric has no content
70 \n\
71 Invalid content
72 """],
73 ["""\
74 .. rubric:: A rubric followed by a block quote
75 ..
76
77 Block quote
78 """,
79 """\
80 <document source="test data">
81 <rubric>
82 A rubric followed by a block quote
83 <comment xml:space="preserve">
84 <block_quote>
85 <paragraph>
86 Block quote
87 """],
88 ["""\
89 .. rubric:: A Rubric
90 :class: foo bar
91 :name: Foo Rubric
92 """,
93 """\
94 <document source="test data">
95 <rubric classes="foo bar" ids="foo-rubric" names="foo\\ rubric">
96 A Rubric
97 """],
98 ]
99
100
101 if __name__ == '__main__':
102 unittest.main()