Debian Codegraph @

test/test_parsers/test_rst/test_line_length_limit_default.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # :Copyright: © 2020 Günter Milde.
3 # :License: Released under the terms of the `2-Clause BSD license`_, in short:
4 #
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved.
8 # This file is offered as-is, without any warranty.
9 #
10 # .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
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 from pathlib import Path
18 import sys
19 import unittest
20
21 if __name__ == '__main__':
22 # prepend the "docutils root" to the Python library path
23 # so we import the local `docutils` package.
24 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
25
26 from docutils.frontend import get_default_settings
27 from docutils.parsers.rst import Parser
28 from docutils.utils import new_document
29
30
31 class ParserTestCase(unittest.TestCase):
32 def test_parser(self):
33 parser = Parser()
34 settings = get_default_settings(Parser)
35 settings.warning_stream = ''
36 for name, cases in totest.items():
37 for casenum, (case_input, case_expected) in enumerate(cases):
38 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
39 document = new_document('test data', settings.copy())
40 parser.parse(case_input, document)
41 output = document.pformat()
42 self.assertEqual(case_expected, output)
43
44
45 totest = {}
46
47 totest['default'] = [
48 ["""\
49 within the limit
50 %s
51 """ % ("x"*10000),
52 """\
53 <document source="test data">
54 <paragraph>
55 within the limit
56 %s
57 """ % ("x"*10000)],
58 ["""\
59 above the limit
60 %s
61 """ % ("x"*10001),
62 """\
63 <document source="test data">
64 <system_message level="3" source="test data" type="ERROR">
65 <paragraph>
66 Line 2 exceeds the line-length-limit.
67 """],
68 ]
69
70
71 if __name__ == '__main__':
72 unittest.main()