| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Tests for misc.py "replace" directive. |
| 9 |
Test in french (not default/fallback language). |
| 10 |
""" |
| 11 |
|
| 12 |
from pathlib import Path |
| 13 |
import sys |
| 14 |
import unittest |
| 15 |
|
| 16 |
if __name__ == '__main__': |
| 17 |
|
| 18 |
|
| 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 |
settings.language_code = 'fr' |
| 32 |
for name, 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 |
output = document.pformat() |
| 38 |
self.assertEqual(case_expected, output) |
| 39 |
|
| 40 |
|
| 41 |
totest = {} |
| 42 |
|
| 43 |
totest['replace'] = [ |
| 44 |
["""\ |
| 45 |
Test directive containing french role exposant (superscript). |
| 46 |
|
| 47 |
.. |Na+| remplace:: Na\\ :exp:`+` |
| 48 |
|
| 49 |
Le |Na+| est l'ion sodium. |
| 50 |
""", |
| 51 |
"""\ |
| 52 |
<document source="test data"> |
| 53 |
<paragraph> |
| 54 |
Test directive containing french role exposant (superscript). |
| 55 |
<substitution_definition names="Na+"> |
| 56 |
Na |
| 57 |
<superscript> |
| 58 |
+ |
| 59 |
<paragraph> |
| 60 |
Le \n\ |
| 61 |
<substitution_reference refname="Na+"> |
| 62 |
Na+ |
| 63 |
est l\'ion sodium. |
| 64 |
"""], |
| 65 |
["""\ |
| 66 |
Test directive containing english role superscript. |
| 67 |
|
| 68 |
.. |Na+| remplace:: Na\\ :sup:`+` |
| 69 |
|
| 70 |
Le |Na+| est l'ion sodium. |
| 71 |
""", |
| 72 |
"""\ |
| 73 |
<document source="test data"> |
| 74 |
<paragraph> |
| 75 |
Test directive containing english role superscript. |
| 76 |
<system_message level="1" line="3" source="test data" type="INFO"> |
| 77 |
<paragraph> |
| 78 |
No role entry for "sup" in module "docutils.parsers.rst.languages.fr". |
| 79 |
Using English fallback for role "sup". |
| 80 |
<substitution_definition names="Na+"> |
| 81 |
Na |
| 82 |
<superscript> |
| 83 |
+ |
| 84 |
<paragraph> |
| 85 |
Le \n\ |
| 86 |
<substitution_reference refname="Na+"> |
| 87 |
Na+ |
| 88 |
est l\'ion sodium. |
| 89 |
"""], |
| 90 |
] |
| 91 |
|
| 92 |
|
| 93 |
if __name__ == '__main__': |
| 94 |
unittest.main() |