Debian Codegraph @

test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_admonitions_dummy_lang.py 9425 2023-06-30 14:56:47Z milde $
4 # Author: David Goodger <[email protected]>
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Tests for admonition directives with local language module.
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 settings.language_code = 'test.local-dummy-lang'
34 for name, cases in totest.items():
35 for casenum, (case_input, case_expected) in enumerate(cases):
36 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
37 document = new_document('test data', settings.copy())
38 parser.parse(case_input, document)
39 output = document.pformat()
40 self.assertEqual(case_expected, output)
41
42
43 totest = {}
44
45 totest['admonitions'] = [
46 ["""\
47 .. Dummy-Attention:: directive with silly localised name.
48
49 .. Attention:: English fallback (an INFO is written).
50 """,
51 """\
52 <document source="test data">
53 <attention>
54 <paragraph>
55 directive with silly localised name.
56 <system_message level="1" line="3" source="test data" type="INFO">
57 <paragraph>
58 No directive entry for "Attention" in module "test.local_dummy_lang".
59 Using English fallback for directive "Attention".
60 <attention>
61 <paragraph>
62 English fallback (an INFO is written).
63 """],
64 ]
65
66
67 if __name__ == '__main__':
68 unittest.main()