| 1 |
|
| 2 |
e. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 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 |
|
| 22 |
|
| 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 |
|
| 54 |
|
| 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() |