| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Tests for the target-notes directives. |
| 9 |
""" |
| 10 |
|
| 11 |
from pathlib import Path |
| 12 |
import sys |
| 13 |
import unittest |
| 14 |
|
| 15 |
if __name__ == '__main__': |
| 16 |
|
| 17 |
|
| 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 |
def test_parser(self): |
| 27 |
parser = Parser() |
| 28 |
settings = get_default_settings(Parser) |
| 29 |
settings.warning_stream = '' |
| 30 |
for name, cases in totest.items(): |
| 31 |
for casenum, (case_input, case_expected) in enumerate(cases): |
| 32 |
with self.subTest(id=f'totest[{name!r}][{casenum}]'): |
| 33 |
document = new_document('test data', settings.copy()) |
| 34 |
parser.parse(case_input, document) |
| 35 |
output = document.pformat() |
| 36 |
self.assertEqual(case_expected, output) |
| 37 |
|
| 38 |
|
| 39 |
totest = {} |
| 40 |
|
| 41 |
totest['target_notes'] = [ |
| 42 |
["""\ |
| 43 |
.. target-notes:: |
| 44 |
""", |
| 45 |
"""\ |
| 46 |
<document source="test data"> |
| 47 |
<pending> |
| 48 |
.. internal attributes: |
| 49 |
.transform: docutils.transforms.references.TargetNotes |
| 50 |
.details: |
| 51 |
"""], |
| 52 |
["""\ |
| 53 |
.. target-notes:: :class: custom |
| 54 |
""", |
| 55 |
"""\ |
| 56 |
<document source="test data"> |
| 57 |
<pending> |
| 58 |
.. internal attributes: |
| 59 |
.transform: docutils.transforms.references.TargetNotes |
| 60 |
.details: |
| 61 |
class: ['custom'] |
| 62 |
"""], |
| 63 |
["""\ |
| 64 |
.. target-notes:: |
| 65 |
:class: custom |
| 66 |
:name: targets |
| 67 |
""", |
| 68 |
"""\ |
| 69 |
<document source="test data"> |
| 70 |
<system_message level="3" line="1" source="test data" type="ERROR"> |
| 71 |
<paragraph> |
| 72 |
Error in "target-notes" directive: |
| 73 |
unknown option: "name". |
| 74 |
<literal_block xml:space="preserve"> |
| 75 |
.. target-notes:: |
| 76 |
:class: custom |
| 77 |
:name: targets |
| 78 |
"""], |
| 79 |
["""\ |
| 80 |
.. target-notes:: |
| 81 |
:class: |
| 82 |
""", |
| 83 |
"""\ |
| 84 |
<document source="test data"> |
| 85 |
<system_message level="3" line="1" source="test data" type="ERROR"> |
| 86 |
<paragraph> |
| 87 |
Error in "target-notes" directive: |
| 88 |
invalid option value: (option: "class"; value: None) |
| 89 |
argument required but none supplied. |
| 90 |
<literal_block xml:space="preserve"> |
| 91 |
.. target-notes:: |
| 92 |
:class: |
| 93 |
"""], |
| 94 |
] |
| 95 |
|
| 96 |
|
| 97 |
if __name__ == '__main__': |
| 98 |
unittest.main() |