/
test_rst.py
executable file
·82 lines (57 loc) · 1.8 KB
/
test_rst.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import io
from pathlib import Path
import pytest
from readme_renderer.rst import render
@pytest.mark.parametrize(
("rst_filename", "html_filename"),
[
(pytest.param(fn, fn.with_suffix(".html"), id=fn.name))
for fn in Path(__file__).parent.glob("fixtures/test_*.rst")
],
)
def test_rst_fixtures(rst_filename, html_filename):
# Get our Markup
with open(rst_filename, encoding='utf-8') as f:
rst_markup = f.read()
# Get our expected
with open(html_filename, encoding="utf-8") as f:
expected = f.read()
out = render(rst_markup)
if "<" in expected:
assert out == expected
else:
assert out is None
def test_rst_001():
assert render('Hello') == '<p>Hello</p>\n'
def test_rst_002():
assert render('http://mymalicioussite.com/') == (
'<p><a href="http://mymalicioussite.com/" rel="nofollow">'
'http://mymalicioussite.com/</a></p>\n'
)
def test_rst_raw():
warnings = io.StringIO()
assert render("""
.. raw:: html
<script>I am evil</script>
""", stream=warnings) is None
assert '"raw" directive disabled' in warnings.getvalue()
def test_rst_empty_file():
warnings = io.StringIO()
assert render("", stream=warnings) is None
assert "No content rendered from RST source." in warnings.getvalue()
def test_rst_header_only():
warnings = io.StringIO()
assert render("""
Header
======
""", stream=warnings) is None
assert "No content rendered from RST source." in warnings.getvalue()
def test_header_and_malformed_emits_docutils_warning_only():
warnings = io.StringIO()
assert render("""
Header
======
======
""", stream=warnings) is None
assert len(warnings.getvalue().splitlines()) == 1
assert "No content rendered from RST source." not in warnings.getvalue()