8000 Support pytest 4 · html5lib/html5lib-python@39506b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39506b4

Browse files
hroncokmcepl
authored andcommitted
Support pytest 4
Fixes #411
1 parent 59e400f commit 39506b4

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

html5lib/tests/test_sanitizer.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,32 @@ def test_sanitizer():
6363
for ns, tag_name in sanitizer.allowed_elements:
6464
if ns != constants.namespaces["html"]:
6565
continue
66-
if tag_name in ['caption', 'col', 'colgroup', 'optgroup', 'option', 'table', 'tbody', 'td',
67-
'tfoot', 'th', 'thead', 'tr', 'select']:
66+
if tag_name in ['caption', 'col', 'colgroup', 'optgroup', 'option',
67+
'table', 'tbody', 'td', 'tfoot', 'th', 'thead',
68+
'tr', 'select']:
6869
continue # TODO
6970
if tag_name == 'image':
7071
yield (runSanitizerTest, "test_should_allow_%s_tag" % tag_name,
71-
"<img title=\"1\"/>foo &lt;bad&gt;bar&lt;/bad&gt; baz",
72-
"<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name))
72+
"<img title=\"1\"/>foo &lt;bad&gt;bar&lt;/bad&gt; baz",
73+
"<%s title='1'>foo <bad>bar</bad> baz</%s>" %
74+
(tag_name, tag_name))
7375
elif tag_name == 'br':
7476
yield (runSanitizerTest, "test_should_allow_%s_tag" % tag_name,
75-
"<br title=\"1\"/>foo &lt;bad&gt;bar&lt;/bad&gt; baz<br/>",
76-
"<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name))
77+
"<br title=\"1\"/>foo &lt;bad&gt;bar&lt;/bad&gt; baz<br/>",
78+
"<%s title='1'>foo <bad>bar</bad> baz</%s>" %
79+
(tag_name, tag_name))
7780
elif tag_name in constants.voidElements:
7881
yield (runSanitizerTest, "test_should_allow_%s_tag" % tag_name,
79-
"<%s title=\"1\"/>foo &lt;bad&gt;bar&lt;/bad&gt; baz" % tag_name,
80-
"<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name))
82+
"<%s title=\"1\"/>foo &lt;bad&gt;bar&lt;/bad&gt; baz" %
83+
tag_name,
84+
"<%s title='1'>foo <bad>bar</bad> baz</%s>" %
85+
(tag_name, tag_name))
8186
else:
8287
yield (runSanitizerTest, "test_should_allow_%s_tag" % tag_name,
83-
"<%s title=\"1\">foo &lt;bad&gt;bar&lt;/bad&gt; baz</%s>" % (tag_name, tag_name),
84-
"<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name))
88+
"<%s title=\"1\">foo &lt;bad&gt;bar&lt;/bad&gt; baz</%s>" %
89+
(tag_name, tag_name),
90+
"<%s title='1'>foo <bad>bar</bad> baz</%s>" %
91+
(tag_name, tag_name))
8592

8693
for ns, attribute_name in sanitizer.allowed_attributes:
8794
if ns is not None:
@@ -92,27 +99,30 @@ def test_sanitizer():
9299
continue
93100
attribute_value = 'foo'
94101
if attribute_name in sanitizer.attr_val_is_uri:
95-
attribute_value = '%s://sub.domain.tld/path/object.ext' % sanitizer.allowed_protocols[0]
102+
attribute_value = '%s://sub.domain.tld/path/object.ext' \
103+
% sanitizer.allowed_protocols[0]
96104
yield (runSanitizerTest, "test_should_allow_%s_attribute" % attribute_name,
97-
"<p %s=\"%s\">foo &lt;bad&gt;bar&lt;/bad&gt; baz</p>" % (attribute_name, attribute_value),
98-
"<p %s='%s'>foo <bad>bar</bad> baz</p>" % (attribute_name, attribute_value))
105+
"<p %s=\"%s\">foo &lt;bad&gt;bar&lt;/bad&gt; baz</p>" %
106+
(attribute_name, attribute_value),
107+
"<p %s='%s'>foo <bad>bar</bad> baz</p>" %
108+
(attribute_name, attribute_value))
99109

100110
for protocol in sanitizer.allowed_protocols:
101111
rest_of_uri = '//sub.domain.tld/path/object.ext'
102112
if protocol == 'data':
103113
rest_of_uri = 'image/png;base64,aGVsbG8gd29ybGQ='
104114
yield (runSanitizerTest, "test_should_allow_uppercase_%s_uris" % protocol,
105-
"<img src=\"%s:%s\">foo</a>" % (protocol, rest_of_uri),
106-
"""<img src="%s:%s">foo</a>""" % (protocol, rest_of_uri))
115+
"<img src=\"%s:%s\">foo</a>" % (protocol, rest_of_uri),
116+
'<img src="%s:%s">foo</a>' % (protocol, rest_of_uri))
107117

108118
for protocol in sanitizer.allowed_protocols:
109119
rest_of_uri = '//sub.domain.tld/path/object.ext'
110120
if protocol == 'data':
111121
rest_of_uri = 'image/png;base64,aGVsbG8gd29ybGQ='
112122
protocol = protocol.upper()
113123
yield (runSanitizerTest, "test_should_allow_uppercase_%s_uris" % protocol,
114-
"<img src=\"%s:%s\">foo</a>" % (protocol, rest_of_uri),
115-
"""<img src="%s:%s">foo</a>""" % (protocol, rest_of_uri))
124+
"<img src=\"%s:%s\">foo</a>" % (protocol, rest_of_uri),
125+
'<img src="%s:%s">foo</a>' % (protocol, rest_of_uri))
116126

117127

118128
def test_lowercase_color_codes_in_style():

html5lib/tests/test_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ def test_serializer():
222222
with open(filename) as fp:
223223
tests = json.load(fp)
224224
for test in tests['tests']:
225-
yield runSerializerTest, test["input"], test["expected"], test.get("options", {})
225+
yield (runSerializerTest, test["input"], test["expected"], test.get("options", {}))

html5lib/tests/test_treewalkers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_treewalker_six_mix():
9999

100100
for tree in sorted(treeTypes.items()):
101101
for intext, attrs, expected in sm_tests:
102-
yield runTreewalkerEditTest, intext, expected, attrs, tree
102+
yield (runTreewalkerEditTest, intext, expected, attrs, tree)
103103

104104

105105
@pytest.mark.parametrize("tree,char", itertools.product(sorted(treeTypes.items()), ["x", "\u1234"]))

0 commit comments

Comments
 (0)
0