Debian Codegraph @

test/test_parsers/test_recommonmark/test_line_length_limit_default.py

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