Skip to content

Commit 6d29b33

Browse files
author
James Graham
committed
Handle utf8 better
1 parent 0437f25 commit 6d29b33

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

html5lib/tests/support.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
import codecs
34
import glob
45

56
base_path = os.path.split(__file__)[0]
@@ -74,7 +75,7 @@ def __getitem__(self, key):
7475

7576
class TestData(object):
7677
def __init__(self, filename, newTestHeading="data"):
77-
self.f = open(filename)
78+
self.f = codecs.open(filename, encoding="utf8")
7879
self.newTestHeading = newTestHeading
7980

8081
def __iter__(self):

html5lib/tests/test_parser.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,20 @@ def runParserTest(self, innerHTML, input, expected, errors, treeClass,
8484
p = html5parser.HTMLParser(tree = treeClass,
8585
namespaceHTMLElements=namespaceHTMLElements)
8686
except constants.DataLossWarning:
87-
return
87+
return
8888

89-
errors = [item.decode("utf-8") for item in errors]
90-
9189
try:
9290
if innerHTML:
93-
document = p.parseFragment(StringIO.StringIO(input), innerHTML)
91+
document = p.parseFragment(input, innerHTML)
9492
else:
9593
try:
96-
document = p.parse(StringIO.StringIO(input))
94+
document = p.parse(input)
9795
except constants.DataLossWarning:
9896
return
9997
except:
100-
errorMsg = "\n".join(["\n\nInput:", input, "\nExpected:", expected,
101-
"\nTraceback:", traceback.format_exc()])
102-
self.assertTrue(False, errorMsg)
98+
errorMsg = u"\n".join([u"\n\nInput:", input, u"\nExpected:", expected,
99+
u"\nTraceback:", traceback.format_exc()])
100+
self.assertTrue(False, errorMsg.encode("utf8"))
103101

104102
output = convertTreeDump(p.tree.testSerializer(document))
105103
output = attrlist.sub(sortattrs, output)
@@ -109,9 +107,9 @@ def runParserTest(self, innerHTML, input, expected, errors, treeClass,
109107
if namespaceHTMLElements:
110108
expected = namespaceExpected(r"\1<html \2>", expected)
111109

112-
errorMsg = "\n".join(["\n\nInput:", input, "\nExpected:", expected,
113-
"\nReceived:", output])
114-
self.assertEquals(expected, output, errorMsg.encode("utf-8"))
110+
errorMsg = u"\n".join([u"\n\nInput:", input, u"\nExpected:", expected,
111+
u"\nReceived:", output])
112+
self.assertEquals(expected, output, errorMsg.encode("utf8"))
115113
errStr = [u"Line: %i Col: %i %s"%(line, col,
116114
constants.E[errorcode] % datavars if isinstance(datavars, dict) else (datavars,)) for
117115
((line,col), errorcode, datavars) in p.errors]
@@ -152,6 +150,8 @@ def testFunc(self, innerHTML=innerHTML, input=input,
152150
testFunc.__name__ = "test_%s_%d_%s_%s" % (testName,index+1,treeName, namespaceHTMLElements and "namespaced" or "no_html_namespace")
153151
setattr(TestCase, testFunc.__name__,
154152
testFunc)
153+
break
154+
break
155155

156156
return unittest.TestLoader().loadTestsFromTestCase(TestCase)
157157

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy