-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
92 lines (69 loc) · 2.46 KB
/
test.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
83
84
85
86
87
88
89
90
91
92
import doctest
import unittest
from time import time as timeobj
from fast_html import *
class PerformanceTesting(unittest.TestCase):
def test_large_structure_generation_performance(self):
num_divs = 100000
start_time = timeobj()
for _ in range(num_divs):
''.join(div('Content'))
end_time = timeobj()
execution_time = end_time - start_time
max_execution_time = 0.3
self.assertLessEqual(execution_time, max_execution_time)
class HtmlToStringTesting(unittest.TestCase):
def test_html_converter(self):
self.assertEqual(
"""[div([p(['Some text'], )], class_="example")]""",
str(html_to_code('<div class="example"><p>Some text</p></div>')),
)
class EscapedHtmlTesting(unittest.TestCase):
def setUp(self):
escape_it(True)
indent_it(False)
def tearDown(self):
escape_it(False)
indent_it(True)
def test_bad_script_tag(self):
actual = render(div([div("<script>alert(1)</script>"), div()]))
expected = "<div><div><script>alert(1)</script></div><div></div></div>"
self.assertEqual(
expected,
actual
)
def test_bad_script_tag_with_sibling(self):
actual = render(div([div(["<script>alert(1)</script>", div()]), div()]))
expected = "<div><div><script>alert(1)</script><div></div></div><div></div></div>"
self.assertEqual(
expected,
actual
)
def test_bad_script_tag_with_nested_lists(self):
actual = render(div([div([["<script>alert(1)</script>"], div()]), div()]))
expected = "<div><div><script>alert(1)</script><div></div></div><div></div></div>"
self.assertEqual(
expected,
actual
)
def test_deeper_nesting(self):
actual = render(
table([
thead(
tr([
td("Student ID"),
td("Name"),
td("<bold>Birthday</bold>"),
])
),
tbody()
])
)
expected = "<table><thead><tr><td>Student ID</td><td>Name</td><td><bold>Birthday</bold></td></tr></thead><tbody></tbody></table>"
self.assertEqual(
expected,
actual
)
if __name__ == '__main__':
doctest.testfile('README.md')
unittest.main()