Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_code_none.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_code_none.py 9425 2023-06-30 14:56:47Z milde $
4 # Author: Guenter Milde
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Test the 'code' directive in body.py with syntax_highlight = 'none'.
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 settings.syntax_highlight = 'none'
31 for name, cases in totest.items():
32 for casenum, (case_input, case_expected) in enumerate(cases):
33 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
34 document = new_document('test data', settings.copy())
35 parser.parse(case_input, document)
36 output = document.pformat()
37 self.assertEqual(case_expected, output)
38
39
40 totest = {}
41
42 totest['code_parsing_none'] = [
43 ["""\
44 .. code::
45
46 This is a code block.
47 """,
48 """\
49 <document source="test data">
50 <literal_block classes="code" xml:space="preserve">
51 This is a code block.
52 """],
53 ["""\
54 .. code:: python
55 :number-lines: 7
56
57 def my_function():
58 '''Test the lexer.
59 '''
60
61 # and now for something completely different
62 print(8/2)
63 """,
64 """\
65 <document source="test data">
66 <literal_block classes="code python" xml:space="preserve">
67 <inline classes="ln">
68 7 \n\
69 def my_function():
70 <inline classes="ln">
71 8 \n\
72 \'\'\'Test the lexer.
73 <inline classes="ln">
74 9 \n\
75 \'\'\'
76 <inline classes="ln">
77 10 \n\
78 \n\
79 <inline classes="ln">
80 11 \n\
81 # and now for something completely different
82 <inline classes="ln">
83 12 \n\
84 print(8/2)
85 """],
86 ["""\
87 .. code:: latex
88
89 hello \\emph{world} % emphasize
90 """,
91 """\
92 <document source="test data">
93 <literal_block classes="code latex" xml:space="preserve">
94 hello \\emph{world} % emphasize
95 """],
96 ]
97
98
99 if __name__ == '__main__':
100 unittest.main()