Debian Codegraph @

test/test_readers/test_pep/test_inline_markup.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_inline_markup.py 9906 2024-08-15 08:43:38Z grubert $
4 # Author: David Goodger <[email protected]>
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Tests for inline markup in PEPs (readers/pep.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[3]))
19
20 from docutils.frontend import get_default_settings
21 from docutils.parsers.rst import Parser
22 from docutils.parsers.rst.states import Inliner
23 from docutils.readers.pep import Reader
24 from docutils.utils import new_document
25
26
27 class PEPParserTestCase(unittest.TestCase):
28 maxDiff = None
29
30 def test_parser(self):
31 parser = Parser(rfc2822=True, inliner=Inliner())
32 settings = get_default_settings(Parser, Reader)
33 for name, cases in totest.items():
34 for casenum, (case_input, case_expected) in enumerate(cases):
35 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
36 document = new_document('test data', settings.copy())
37 parser.parse(case_input, document)
38 output = document.pformat()
39 self.assertEqual(case_expected, output)
40
41
42 totest = {}
43
44 totest['standalone_references'] = [
45 ["""\
46 See PEP 287 (pep-0287.txt),
47 and RFC 2822 (which obsoletes RFC822 and RFC-733).
48 """,
49 """\
50 <document source="test data">
51 <paragraph>
52 See \n\
53 <reference refuri="https://peps.python.org/pep-0287">
54 PEP 287
55 (
56 <reference refuri="https://peps.python.org/pep-0287">
57 pep-0287.txt
58 ),
59 and \n\
60 <reference refuri="https://tools.ietf.org/html/rfc2822.html">
61 RFC 2822
62 (which obsoletes \n\
63 <reference refuri="https://tools.ietf.org/html/rfc822.html">
64 RFC822
65 and \n\
66 <reference refuri="https://tools.ietf.org/html/rfc733.html">
67 RFC-733
68 ).
69 """],
70 ["""\
71 References split across lines:
72
73 PEP
74 287
75
76 RFC
77 2822
78 """,
79 """\
80 <document source="test data">
81 <paragraph>
82 References split across lines:
83 <paragraph>
84 <reference refuri="https://peps.python.org/pep-0287">
85 PEP
86 287
87 <paragraph>
88 <reference refuri="https://tools.ietf.org/html/rfc2822.html">
89 RFC
90 2822
91 """],
92 ["""\
93 Test PEP-specific implicit references before a URL:
94
95 PEP 287 (https://peps.python.org/pep-0287), RFC 2822.
96 """,
97 """\
98 <document source="test data">
99 <paragraph>
100 Test PEP-specific implicit references before a URL:
101 <paragraph>
102 <reference refuri="https://peps.python.org/pep-0287">
103 PEP 287
104 (
105 <reference refuri="https://peps.python.org/pep-0287">
106 https://peps.python.org/pep-0287
107 ), \n\
108 <reference refuri="https://tools.ietf.org/html/rfc2822.html">
109 RFC 2822
110 .
111 """],
112 ]
113
114 totest['miscellaneous'] = [
115 ["""\
116 For *completeness*, _`let's` ``test`` **other** forms_
117 |of| `inline markup` [*]_.
118
119 .. [*] See https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html.
120 """,
121 """\
122 <document source="test data">
123 <paragraph>
124 For \n\
125 <emphasis>
126 completeness
127 , \n\
128 <target ids="let-s" names="let's">
129 let's
130 \n\
131 <literal>
132 test
133 \n\
134 <strong>
135 other
136 \n\
137 <reference name="forms" refname="forms">
138 forms
139 \n\
140 <substitution_reference refname="of">
141 of
142 \n\
143 <title_reference>
144 inline markup
145 \n\
146 <footnote_reference auto="*" ids="footnote-reference-1">
147 .
148 <footnote auto="*" ids="footnote-1">
149 <paragraph>
150 See \n\
151 <reference refuri="https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html">
152 https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html
153 .
154 """],
155 ]
156
157
158 if __name__ == '__main__':
159 unittest.main()