Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_parsed_literals.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_parsed_literals.py 9425 2023-06-30 14:56:47Z milde $
4 # Author: Lea Wiemann <[email protected]>
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Tests for the body.py 'parsed-literal' 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['parsed_literals'] = [
42 ["""\
43 .. parsed-literal::
44
45 This is a parsed literal block.
46 It may contain *inline markup
47 spanning lines.*
48 """,
49 """\
50 <document source="test data">
51 <literal_block xml:space="preserve">
52 This is a parsed literal block.
53 It may contain \n\
54 <emphasis>
55 inline markup
56 spanning lines.
57 """],
58 ["""\
59 .. parsed-literal::
60 :class: myliteral
61 :name: example: parsed
62
63 This is a parsed literal block with options.
64 """,
65 """\
66 <document source="test data">
67 <literal_block classes="myliteral" ids="example-parsed" names="example:\\ parsed" xml:space="preserve">
68 This is a parsed literal block with options.
69 """],
70 ["""\
71 .. parsed-literal:: content may start on same line
72 """,
73 """\
74 <document source="test data">
75 <literal_block xml:space="preserve">
76 content may start on same line
77 """],
78 ["""\
79 .. parsed-literal::
80 """,
81 """\
82 <document source="test data">
83 <system_message level="3" line="1" source="test data" type="ERROR">
84 <paragraph>
85 Content block expected for the "parsed-literal" directive; none found.
86 <literal_block xml:space="preserve">
87 .. parsed-literal::
88 """],
89 ]
90
91
92 if __name__ == '__main__':
93 unittest.main()