Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_container.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_container.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 'container' directive from body.py.
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['container'] = [
42 ["""\
43 .. container::
44
45 "container" is a generic element, an extension mechanism for
46 users & applications.
47
48 Containers may contain arbitrary body elements.
49 """,
50 """\
51 <document source="test data">
52 <container>
53 <paragraph>
54 "container" is a generic element, an extension mechanism for
55 users & applications.
56 <paragraph>
57 Containers may contain arbitrary body elements.
58 """],
59 ["""\
60 .. container:: custom
61
62 Some text.
63 """,
64 """\
65 <document source="test data">
66 <container classes="custom">
67 <paragraph>
68 Some text.
69 """],
70 ["""\
71 .. container:: one two three
72 four
73
74 Multiple classes.
75
76 Multi-line argument.
77
78 Multiple paragraphs in the container.
79 """,
80 """\
81 <document source="test data">
82 <container classes="one two three four">
83 <paragraph>
84 Multiple classes.
85 <paragraph>
86 Multi-line argument.
87 <paragraph>
88 Multiple paragraphs in the container.
89 """],
90 ["""\
91 .. container::
92 :name: my name
93
94 The name argument allows hyperlinks to `my name`_.
95 """,
96 """\
97 <document source="test data">
98 <container ids="my-name" names="my\\ name">
99 <paragraph>
100 The name argument allows hyperlinks to \n\
101 <reference name="my name" refname="my name">
102 my name
103 .
104 """],
105 ]
106
107
108 if __name__ == '__main__':
109 unittest.main()