Debian Codegraph @

test/test_parsers/test_rst/test_interpreted_fr.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # $Id: test_interpreted.py 6424 2010-09-18 10:43:52Z smerten $
4 # Author: David Goodger <[email protected]>
5 # Copyright: This module has been placed in the public domain.
6
7 """
8 Tests for interpreted text in docutils/parsers/rst/states.py.
9 Test not default/fallback language french.
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[3]))
20
21 from docutils.frontend import get_default_settings
22 from docutils.parsers.rst import Parser, roles
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 settings.language_code = 'fr'
32 for name, cases in totest.items():
33 for casenum, (case_input, case_expected) in enumerate(cases):
34 # Language-specific roles and roles added by the
35 # "default-role" and "role" directives are currently stored
36 # globally in the roles._roles dictionary. This workaround
37 # empties that dictionary.
38 roles._roles = {}
39 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
40 document = new_document('test data', settings.copy())
41 parser.parse(case_input, document)
42 output = document.pformat()
43 self.assertEqual(case_expected, output)
44
45
46 totest = {}
47
48 totest['basics'] = [
49 ["""\
50 Simple explicit roles and english fallbacks:
51 :acronym:`acronym`,
52 :exp:`superscript`,
53 :ind:`subscript`,
54 :titre:`title reference`.
55 """,
56 """\
57 <document source="test data">
58 <paragraph>
59 Simple explicit roles and english fallbacks:
60 <acronym>
61 acronym
62 ,
63 <superscript>
64 superscript
65 ,
66 <subscript>
67 subscript
68 ,
69 <title_reference>
70 title reference
71 .
72 <system_message level="1" line="1" source="test data" type="INFO">
73 <paragraph>
74 No role entry for "acronym" in module "docutils.parsers.rst.languages.fr".
75 Using English fallback for role "acronym".
76 """],
77 ]
78
79 if __name__ == '__main__':
80 unittest.main()