Debian Codegraph @

test/test_transforms/test_expose_internals.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_expose_internals.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 Test module for universal.ExposeInternals transform.
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[2]))
19
20 from docutils.frontend import get_default_settings
21 from docutils.parsers.rst import Parser
22 from docutils.transforms.universal import ExposeInternals, TestMessages
23 from docutils.utils import new_document
24
25
26 class TransformTestCase(unittest.TestCase):
27 def test_transforms(self):
28 parser = Parser()
29 settings = get_default_settings(Parser)
30 settings.warning_stream = ''
31 settings.expose_internals = ['rawsource', 'source']
32 for name, (transforms, cases) in totest.items():
33 for casenum, (case_input, case_expected) in enumerate(cases):
34 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
35 document = new_document('test data', settings.copy())
36 parser.parse(case_input, document)
37 # Don't do a ``populate_from_components()`` because that
38 # would enable the Transformer's default transforms.
39 document.transformer.add_transforms(transforms)
40 document.transformer.add_transform(TestMessages)
41 document.transformer.apply_transforms()
42 output = document.pformat()
43 self.assertEqual(case_expected, output)
44
45
46 totest = {}
47
48 totest['transitions'] = ((ExposeInternals,), [
49 ["""\
50 This is a test.
51 """,
52 """\
53 <document internal:rawsource="" source="test data">
54 <paragraph internal:rawsource="This is a test." internal:source="test data">
55 This is a test.
56 """],
57 ])
58
59
60 if __name__ == '__main__':
61 unittest.main()