Skip to content

Commit b45b186

Browse files
committed
serializer
1 parent 38bb175 commit b45b186

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

html5lib/tests/test_serializer.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@ def serialize_html(input, options):
8989
return serializer.render(stream, encoding)
9090

9191

92-
def runSerializerTest(input, expected, options):
93-
encoding = options.get("encoding", None)
94-
95-
if encoding:
96-
expected = list(map(lambda x: x.encode(encoding), expected))
97-
98-
result = serialize_html(input, options)
99-
if len(expected) == 1:
100-
assert expected[0] == result, "Expected:\n%s\nActual:\n%s\nOptions:\n%s" % (expected[0], result, str(options))
101-
elif result not in expected:
102-
assert False, "Expected: %s, Received: %s" % (expected, result)
103-
104-
10592
def throwsWithLatin1(input):
10693
with pytest.raises(UnicodeEncodeError):
10794
serialize_html(input, {"encoding": "iso-8859-1"})
@@ -120,13 +107,13 @@ def testDoctypeSystemId():
120107

121108

122109
def testCdataCharacters():
123-
runSerializerTest([["StartTag", "http://www.w3.org/1999/xhtml", "style", {}], ["Characters", "\u0101"]],
124-
["<style>&amacr;"], {"encoding": "iso-8859-1"})
110+
test_serializer([["StartTag", "http://www.w3.org/1999/xhtml", "style", {}], ["Characters", "\u0101"]],
111+
["<style>&amacr;"], {"encoding": "iso-8859-1"})
125112

126113

127114
def testCharacters():
128-
runSerializerTest([["Characters", "\u0101"]],
129-
["&amacr;"], {"encoding": "iso-8859-1"})
115+
test_serializer([["Characters", "\u0101"]],
116+
["&amacr;"], {"encoding": "iso-8859-1"})
130117

131118

132119
def testStartTagName():
@@ -138,9 +125,9 @@ def testAttributeName():
138125

139126

140127
def testAttributeValue():
141-
runSerializerTest([["StartTag", "http://www.w3.org/1999/xhtml", "span",
142-
[{"namespace": None, "name": "potato", "value": "\u0101"}]]],
143-
["<span potato=&amacr;>"], {"encoding": "iso-8859-1"})
128+
test_serializer([["StartTag", "http://www.w3.org/1999/xhtml", "span",
129+
[{"namespace": None, "name": "potato", "value": "\u0101"}]]],
130+
["<span potato=&amacr;>"], {"encoding": "iso-8859-1"})
144131

145132

146133
def testEndTagName():
@@ -165,7 +152,7 @@ def testSpecQuoteAttribute(c):
165152
else:
166153
output_ = ['<span foo="%s">' % c]
167154
options_ = {"quote_attr_values": "spec"}
168-
runSerializerTest(input_, output_, options_)
155+
test_serializer(input_, output_, options_)
169156

170157

171158
@pytest.mark.parametrize("c", list("\t\n\u000C\x20\r\"'=<>`"
@@ -184,7 +171,7 @@ def testLegacyQuoteAttribute(c):
184171
else:
185172
output_ = ['<span foo="%s">' % c]
186173
options_ = {"quote_attr_values": "legacy"}
187-
runSerializerTest(input_, output_, options_)
174+
test_serializer(input_, output_, options_)
188175

189176

190177
@pytest.fixture
@@ -217,9 +204,23 @@ def testEntityNoResolve(lxml_parser):
217204
assert result == '<!DOCTYPE html SYSTEM "about:legacy-compat"><html>&beta;</html>'
218205

219206

220-
def test_serializer():
207+
def param_serializer():
221208
for filename in get_data_files('serializer-testdata', '*.test', os.path.dirname(__file__)):
222209
with open(filename) as fp:
223210
tests = json.load(fp)
224211
for test in tests['tests']:
225-
yield runSerializerTest, test["input"], test["expected"], test.get("options", {})
212+
yield test["input"], test["expected"], test.get("options", {})
213+
214+
215+
@pytest.mark.parametrize("input, expected, options", param_serializer())
216+
def test_serializer(input, expected, options):
217+
encoding = options.get("encoding", None)
218+
219+
if encoding:
220+
expected = list(map(lambda x: x.encode(encoding), expected))
221+
222+
result = serialize_html(input, options)
223+
if len(expected) == 1:
224+
assert expected[0] == result, "Expected:\n%s\nActual:\n%s\nOptions:\n%s" % (expected[0], result, str(options))
225+
elif result not in expected:
226+
assert False, "Expected: %s, Received: %s" % (expected, result)

0 commit comments

Comments
 (0)