Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_block_quotes.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_block_quotes.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 block quote directives "epigraph", "highlights", and
9 "pull-quote".
10 """
11
12 from pathlib import Path
13 import sys
14 import unittest
15
16 if __name__ == '__main__':
17 # prepend the "docutils root" to the Python library path
18 # so we import the local `docutils` package.
19 sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
20
21 from docutils.frontend import get_default_settings
22 from docutils.parsers.rst import Parser
23 from docutils.utils import new_document
24
25
26 class ParserTestCase(unittest.TestCase):
27 def test_parser(self):
28 parser = Parser()
29 settings = get_default_settings(Parser)
30 settings.warning_stream = ''
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 generic_tests = [
41 ["""\
42 .. %(type)s::
43
44 This is a block quote.
45
46 -- Attribution
47
48 This is another block quote.
49
50 -- Another Attribution,
51 Second Line
52 """,
53 """\
54 <document source="test data">
55 <block_quote classes="%(type)s">
56 <paragraph>
57 This is a block quote.
58 <attribution>
59 Attribution
60 <block_quote classes="%(type)s">
61 <paragraph>
62 This is another block quote.
63 <attribution>
64 Another Attribution,
65 Second Line
66 """],
67 # TODO: Add class option.
68 ["""\
69 .. %(type)s::
70 """,
71 """\
72 <document source="test data">
73 <system_message level="3" line="1" source="test data" type="ERROR">
74 <paragraph>
75 Content block expected for the "%(type)s" directive; none found.
76 <literal_block xml:space="preserve">
77 .. %(type)s::
78 """],
79 ]
80
81 totest = {}
82 for block_quote_type in ('epigraph', 'highlights', 'pull-quote'):
83 totest[block_quote_type] = [
84 [text % {'type': block_quote_type} for text in pair]
85 for pair in generic_tests]
86
87
88 if __name__ == '__main__':
89 unittest.main()