Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_class.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_class.py 10169 2025-06-16 10:05:35Z milde $
4 # Author: Lea Wiemann <[email protected]>
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Tests for the 'class' 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
27 maxDiff = None
28
29 def test_parser(self):
30 parser = Parser()
31 settings = get_default_settings(Parser)
32 settings.warning_stream = ''
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['class'] = [
45 ["""\
46 .. class:: class1 class2
47 """,
48 """\
49 <document source="test data">
50 <pending>
51 .. internal attributes:
52 .transform: docutils.transforms.misc.ClassAttribute
53 .details:
54 class: ['class1', 'class2']
55 directive: 'class'
56 """],
57 ["""\
58 .. class:: class1 class2
59
60 The classes are applied to this paragraph.
61
62 And this one.
63 """,
64 """\
65 <document source="test data">
66 <paragraph classes="class1 class2">
67 The classes are applied to this paragraph.
68 <paragraph classes="class1 class2">
69 And this one.
70 """],
71 ["""\
72 .. rst-class:: class1 class2
73 ..
74
75 The classes will be applied to this block quote.
76 """,
77 """\
78 <document source="test data">
79 <pending>
80 .. internal attributes:
81 .transform: docutils.transforms.misc.ClassAttribute
82 .details:
83 class: ['class1', 'class2']
84 directive: 'rst-class'
85 <comment xml:space="preserve">
86 <block_quote>
87 <paragraph>
88 The classes will be applied to this block quote.
89 """],
90 ]
91
92
93 if __name__ == '__main__':
94 unittest.main()