| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Test for pseudo-XML writer. |
| 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[2])) |
| 19 |
|
| 20 |
from docutils.core import publish_string |
| 21 |
from docutils.writers import pseudoxml |
| 22 |
|
| 23 |
|
| 24 |
class WriterPublishTestCase(unittest.TestCase): |
| 25 |
maxDiff = None |
| 26 |
|
| 27 |
def test_publish(self): |
| 28 |
for name, cases in totest.items(): |
| 29 |
for casenum, (case_input, case_expected) in enumerate(cases): |
| 30 |
with self.subTest(id=f'totest[{name!r}][{casenum}]'): |
| 31 |
output = publish_string( |
| 32 |
source=case_input, |
| 33 |
writer=pseudoxml.Writer(), |
| 34 |
settings_overrides={ |
| 35 |
'_disable_config': True, |
| 36 |
'strict_visitor': True, |
| 37 |
}).decode() |
| 38 |
self.assertEqual(case_expected, output) |
| 39 |
|
| 40 |
for name, cases in totest_detailed.items(): |
| 41 |
for casenum, (case_input, case_expected) in enumerate(cases): |
| 42 |
with self.subTest(id=f'totest_detailed[{name!r}][{casenum}]'): |
| 43 |
output = publish_string( |
| 44 |
source=case_input, |
| 45 |
writer=pseudoxml.Writer(), |
| 46 |
settings_overrides={ |
| 47 |
'_disable_config': True, |
| 48 |
'strict_visitor': True, |
| 49 |
'detailed': True, |
| 50 |
}).decode() |
| 51 |
self.assertEqual(case_expected, output) |
| 52 |
|
| 53 |
|
| 54 |
totest = {} |
| 55 |
totest_detailed = {} |
| 56 |
|
| 57 |
totest['basic'] = [ |
| 58 |
|
| 59 |
[r""" |
| 60 |
This is a paragraph. |
| 61 |
|
| 62 |
---------- |
| 63 |
|
| 64 |
This is a paragraph |
| 65 |
with \escaped \characters. |
| 66 |
|
| 67 |
A Section |
| 68 |
--------- |
| 69 |
|
| 70 |
Foo. |
| 71 |
""", |
| 72 |
|
| 73 |
"""\ |
| 74 |
<document source="<string>"> |
| 75 |
<paragraph> |
| 76 |
This is a paragraph. |
| 77 |
<transition> |
| 78 |
<paragraph> |
| 79 |
This is a paragraph |
| 80 |
with escaped characters. |
| 81 |
<section ids="a-section" names="a\\ section"> |
| 82 |
<title> |
| 83 |
A Section |
| 84 |
<paragraph> |
| 85 |
Foo. |
| 86 |
"""] |
| 87 |
] |
| 88 |
|
| 89 |
totest_detailed['basic'] = [ |
| 90 |
|
| 91 |
[totest['basic'][0][0], |
| 92 |
|
| 93 |
"""\ |
| 94 |
<document source="<string>"> |
| 95 |
<paragraph> |
| 96 |
<#text> |
| 97 |
'This is a paragraph.' |
| 98 |
<transition> |
| 99 |
<paragraph> |
| 100 |
<#text> |
| 101 |
'This is a paragraph\\n' |
| 102 |
'with \\x00escaped \\x00characters.' |
| 103 |
<section ids="a-section" names="a\\ section"> |
| 104 |
<title> |
| 105 |
<#text> |
| 106 |
'A Section' |
| 107 |
<paragraph> |
| 108 |
<#text> |
| 109 |
'Foo.' |
| 110 |
"""] |
| 111 |
] |
| 112 |
|
| 113 |
if __name__ == '__main__': |
| 114 |
unittest.main() |