Debian Codegraph @

test/test_parsers/test_recommonmark/test_line_length_limit.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.recommonmark_wrapper import Parser
28 from docutils.utils import new_document
29
30
31 class RecommonmarkParserTestCase(unittest.TestCase):
32 def test_parser(self):
33 parser = Parser()
34 settings = get_default_settings(Parser)
35 settings.warning_stream = ''
36 settings.line_length_limit = 80
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"*80),
53 """\
54 <document source="test data">
55 <paragraph>
56 within the limit
57 %s
58 """ % ("x"*80)],
59 ["""\
60 above the limit
61 %s
62 """ % ("x"*81),
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()