10000 Attribute order doesn't matter · awesome-python/html5lib-python@53b3f68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 53b3f68

Browse files
committed
Attribute order doesn't matter
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40563
1 parent 212760d commit 53b3f68

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

tests/runtests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def main():
2121

2222
if __name__ == "__main__":
2323
#Allow us to import the parent module
24+
#RELEASE remove
25+
sys.path.insert(0,os.path.abspath(os.path.join(__file__,'../../src')))
26+
#END RELEASE
2427
os.chdir(os.path.split(os.path.abspath(__file__))[0])
2528
sys.path.insert(0, os.path.abspath(os.pardir))
2629

tests/test_parser.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def parseTestcase(testString):
6969
raise
7070
innerHTML = False
7171
input = []
72-
output = []
72+
expected = []
7373
errors = []
7474
currentList = input
7575
for line in testString:
7676
if line and not (line.startswith("#errors") or
7777
line.startswith("#document") or line.startswith("#data") or
7878
line.startswith("#document-fragment")):
79-
if currentList is output:
79+
if currentList is expected:
8080
if line.startswith("|"):
8181
currentList.append(line[2:])
8282
else:
@@ -91,8 +91,8 @@ def parseTestcase(testString):
9191
if not innerHTML:
9292
sys.stderr.write(testString)
9393
assert innerHTML
94-
currentList = output
95-
return innerHTML, "\n".join(input), "\n".join(output), errors
94+
currentList = expected
95+
return innerHTML, "\n".join(input), "\n".join(expected), errors
9696

9797
def convertTreeDump(treedump):
9898
"""convert the output of str(document) to the format used in the testcases"""
@@ -105,20 +105,28 @@ def convertTreeDump(treedump):
105105
rv.append(line)
106106
return "\n".join(rv)
107107

108+
import re
109+
attrlist = re.compile(r"^(\s+)\w+=.*(\n\1\w+=.*)+",re.M)
110+
def sortattrs(x):
111+
lines = x.group(0).split("\n")
112+
lines.sort()
113+
return "\n".join(lines)
114+
108115
class TestCase(unittest.TestCase):
109-
def runParserTest(self, innerHTML, input, output, errors, treeClass):
116+
def runParserTest(self, innerHTML, input, expected, errors, treeClass):
110117
#XXX - move this out into the setup function
111118
#concatenate all consecutive character tokens into a single token
112119
p = html5parser.HTMLParser(tree = treeClass)
113120
if innerHTML:
114121
document = p.parseFragment(StringIO.StringIO(input), innerHTML)
115122
else:
116123
document = p.parse(StringIO.StringIO(input))
117-
errorMsg = "\n".join(["\n\nExpected:", output, "\nRecieved:",
118-
convertTreeDump(p.tree.testSerializer(document))])
119-
self.assertEquals(output,
120-
convertTreeDump(p.tree.testSerializer(document)),
121-
errorMsg)
124+
output = convertTreeDump(p.tree.testSerializer(document))
125+
output = attrlist.sub(sortattrs, output)
126+
expected = attrlist.sub(sortattrs, expected)
127+
errorMsg = "\n".join(["\n\nExpected:", expected,
128+
"\nRecieved:", output])
129+
self.assertEquals(expected, output, errorMsg)
122130
errStr = ["Line: %i Col: %i %s"%(line, col, message) for
123131
((line,col), message) in p.errors]
124132
errorMsg2 = "\n".join(["\n\nInput errors:\n" + "\n".join(errors),
@@ -135,16 +143,16 @@ def test_parser():
135143
if test == "":
136144
continue
137145
test = "#data\n" + test
138-
innerHTML, input, output, errors = parseTestcase(test)
139-
yield TestCase.runParserTest, innerHTML, input, output, errors, name, cls
146+
innerHTML, input, expected, errors = parseTestcase(test)
147+
yield TestCase.runParserTest, innerHTML, input, expected, errors, name, cls
140148

141149
def buildTestSuite():
142150
tests = 0
143-
for func, innerHTML, input, output, errors, treeName, treeCls in test_parser():
151+
for func, innerHTML, input, expected, errors, treeName, treeCls in test_parser():
144152
tests += 1
145153
testName = 'test%d' % tests
146-
testFunc = lambda self, method=func, innerHTML=innerHTML, input=input, output=output, \
147-
errors=errors, treeCls=treeCls: method(self, innerHTML, input, output, errors, treeCls)
154+
testFunc = lambda self, method=func, innerHTML=innerHTML, input=input, expected=expected, \
155+
errors=errors, treeCls=treeCls: method(self, innerHTML, input, expected, errors, treeCls)
148156
testFunc.__doc__ = 'Parser %s Tree %s Input: %s'%(testName, treeName, input)
149157
instanceMethod = new.instancemethod(testFunc, None, TestCase)
150158
setattr(TestCase, testName, instanceMethod)

0 commit comments

Comments
 (0)
0