Skip to content

Commit 79e65cd

Browse files
Improve code coverage
1 parent 76c30c1 commit 79e65cd

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

tests/basic_rendering_test.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
br,
1818
input,
1919
a,
20-
DangerousRawHtml,
2120
)
2221

2322

@@ -249,21 +248,3 @@ def test_boolean_tag_attributes_false():
249248
Attributes with value `False` are skipped
250249
"""
251250
assert str(input(readonly=False)) == "<input/>"
252-
253-
254-
def test_dangerous_raw_html():
255-
"""
256-
Is raw HTML rendered correctly?
257-
"""
258-
assert str(DangerousRawHtml("<script>alert(1)</script>")) \
259-
== "<script>alert(1)</script>"
260-
261-
assert str(
262-
html(
263-
DangerousRawHtml("<script>alert(1)</script>")
264-
)
265-
) == "\n".join([
266-
"<html>",
267-
" <script>alert(1)</script>",
268-
"</html>",
269-
])

tests/end_to_end/flask_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ def test_failed_to_stringify(client: FlaskClient):
7676
assert "**HINT:** if you're using Flask" in str(exception_info.value)
7777

7878

79-
if __name__ == '__main__':
79+
# Ignore coverage since this won't be used when running tests automatically
80+
if __name__ == '__main__': # pragma: no cover
8081
app.run(debug=True)

tests/raw_html_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
# Tests / Raw HTML Test
3+
4+
Test cases for `DangerousRawHtml` tag
5+
"""
6+
import pytest
7+
from pyhtml import DangerousRawHtml, html
8+
9+
10+
def test_dangerous_raw_html():
11+
"""
12+
Is raw HTML rendered correctly?
13+
"""
14+
assert str(DangerousRawHtml("<script>alert(1)</script>")) \
15+
== "<script>alert(1)</script>"
16+
17+
assert str(
18+
html(
19+
DangerousRawHtml("<script>alert(1)</script>")
20+
)
21+
) == "\n".join([
22+
"<html>",
23+
" <script>alert(1)</script>",
24+
"</html>",
25+
])
26+
27+
28+
def test_raw_html_not_callable():
29+
"""
30+
`DangerousRawHtml` elements should not be callable.
31+
"""
32+
with pytest.raises(TypeError):
33+
DangerousRawHtml("")()

0 commit comments

Comments
 (0)