Debian Codegraph @

test/test_parsers/test_recommonmark/test_misc.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 Various tests for the recommonmark parser.
14 """
15
16 from pathlib import Path
17 import sys
18 import unittest
19
20 if __name__ == '__main__':
21 # prepend the "docutils root" to the Python library path
22 # so we import the local `docutils` package.
23 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
24
25 from docutils.core import publish_string
26 from docutils.parsers.rst import directives as rst_directives
27 from docutils.parsers.recommonmark_wrapper import Parser
28
29
30 sample_with_html = """\
31 A paragraph:
32
33 <p>A HTML block.</p>
34
35 Next paragraph.
36
37 <script type="text/javascript">
38 // some dangerous JavaScript
39
40 Final paragraph.
41 """
42
43
44 @unittest.skipIf(Parser is None, 'Optional "recommonmark" module not found.')
45 class RecommonmarkParserTests(unittest.TestCase):
46
47 mysettings = {'output_encoding': 'unicode',
48 'warning_stream': '',
49 'raw_enabled': False,
50 }
51
52 def test_parser_name(self):
53 # cf. ../test_rst/test_directives/test__init__.py
54 # this is used in the "include" directive's :parser: option.
55 self.assertIs(rst_directives.parser_name('recommonmark'), Parser)
56
57 def test_raw_disabled(self):
58 output = publish_string(sample_with_html, parser=Parser(),
59 settings_overrides=self.mysettings)
60 self.assertNotIn('<raw>', output)
61 self.assertIn('<system_message', output)
62 self.assertIn('Raw content disabled.', output)
63
64 def test_raw_disabled_inline(self):
65 output = publish_string('foo <a href="uri">', parser=Parser(),
66 settings_overrides=self.mysettings)
67 self.assertNotIn('<raw>', output)
68 self.assertIn('<problematic', output)
69 self.assertIn('<system_message', output)
70 self.assertIn('Raw content disabled.', output)
71
72
73 if __name__ == '__main__':
74 unittest.main()