| 1 |
|
| 2 |
e. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
""" |
| 13 |
Tests for inline markup in docutils/parsers/rst/states.py. |
| 14 |
Interpreted text tests are in a separate module, test_interpreted.py. |
| 15 |
""" |
| 16 |
|
| 17 |
import os.path |
| 18 |
from pathlib import Path |
| 19 |
import sys |
| 20 |
import unittest |
| 21 |
|
| 22 |
if __name__ == '__main__': |
| 23 |
|
| 24 |
|
| 25 |
sys.path.insert(0, str(Path(__file__).resolve().parents[3])) |
| 26 |
|
| 27 |
from docutils.frontend import get_default_settings |
| 28 |
from docutils.parsers.rst import Parser |
| 29 |
from docutils.utils import new_document |
| 30 |
|
| 31 |
|
| 32 |
TEST_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..')) |
| 33 |
docutils_conf = os.path.relpath( |
| 34 |
os.path.join(TEST_ROOT, 'docutils.conf'), os.getcwd()).replace('\\', '/') |
| 35 |
|
| 36 |
|
| 37 |
class ParserTestCase(unittest.TestCase): |
| 38 |
maxDiff = None |
| 39 |
|
| 40 |
def test_parser(self): |
| 41 |
parser = Parser() |
| 42 |
settings = get_default_settings(Parser) |
| 43 |
settings.warning_stream = '' |
| 44 |
settings.line_length_limit = 80 |
| 45 |
for name, cases in totest.items(): |
| 46 |
for casenum, (case_input, case_expected) in enumerate(cases): |
| 47 |
with self.subTest(id=f'totest[{name!r}][{casenum}]'): |
| 48 |
document = new_document('test data', settings.copy()) |
| 49 |
parser.parse(case_input, document) |
| 50 |
output = document.pformat() |
| 51 |
self.assertEqual(case_expected, output) |
| 52 |
|
| 53 |
|
| 54 |
totest = {} |
| 55 |
|
| 56 |
totest['default'] = [ |
| 57 |
["""\ |
| 58 |
within the limit |
| 59 |
%s |
| 60 |
""" % ("x"*80), |
| 61 |
"""\ |
| 62 |
<document source="test data"> |
| 63 |
<paragraph> |
| 64 |
within the limit |
| 65 |
%s |
| 66 |
""" % ("x"*80)], |
| 67 |
["""\ |
| 68 |
above the limit |
| 69 |
%s |
| 70 |
""" % ("x"*81), |
| 71 |
"""\ |
| 72 |
<document source="test data"> |
| 73 |
<system_message level="3" source="test data" type="ERROR"> |
| 74 |
<paragraph> |
| 75 |
Line 2 exceeds the line-length-limit. |
| 76 |
"""], |
| 77 |
[f"""\ |
| 78 |
Include Test |
| 79 |
============ |
| 80 |
|
| 81 |
.. include:: {docutils_conf} |
| 82 |
|
| 83 |
A paragraph. |
| 84 |
""", |
| 85 |
f"""\ |
| 86 |
<document source="test data"> |
| 87 |
<section ids="include-test" names="include\\ test"> |
| 88 |
<title> |
| 89 |
Include Test |
| 90 |
<system_message level="2" line="4" source="test data" type="WARNING"> |
| 91 |
<paragraph> |
| 92 |
"{docutils_conf}": line 5 exceeds the line-length-limit. |
| 93 |
<literal_block xml:space="preserve"> |
| 94 |
.. include:: {docutils_conf} |
| 95 |
<paragraph> |
| 96 |
A paragraph. |
| 97 |
"""], |
| 98 |
[f"""\ |
| 99 |
Include Test 2 |
| 100 |
|
| 101 |
.. include:: {docutils_conf} |
| 102 |
:start-line: 3 |
| 103 |
|
| 104 |
A paragraph. |
| 105 |
""", |
| 106 |
f"""\ |
| 107 |
<document source="test data"> |
| 108 |
<paragraph> |
| 109 |
Include Test 2 |
| 110 |
<system_message level="2" line="3" source="test data" type="WARNING"> |
| 111 |
<paragraph> |
| 112 |
"{docutils_conf}": line 5 exceeds the line-length-limit. |
| 113 |
<literal_block xml:space="preserve"> |
| 114 |
.. include:: {docutils_conf} |
| 115 |
:start-line: 3 |
| 116 |
<paragraph> |
| 117 |
A paragraph. |
| 118 |
"""], |
| 119 |
] |
| 120 |
|
| 121 |
|
| 122 |
if __name__ == '__main__': |
| 123 |
unittest.main() |