10BC0 Add back in testing of Ruby simpletree treebuilder · awesome-python/html5lib-python@c0b8bb7 · GitHub
[go: up one dir, main page]

Skip to content

Commit c0b8bb7

Browse files
committed
Add back in testing of Ruby simpletree treebuilder
Rearrange tests so that tests that fail won't be tested against other builders Add simple shell script to run the python and ruby suites back to back --HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40573
1 parent 8bccf2c commit c0b8bb7

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines 8000 changed

runtests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
#
3+
# A simple script to run both the python and ruby tests back to back
4+
#
5+
python tests/runtests.py && (cd ruby; ruby runtests.rb)

tests/runtests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def main():
1717
import test_parser
1818
test_parser.checkParseErrors = False
1919

20-
unittest.TextTestRunner().run(buildTestSuite())
20+
results = unittest.TextTestRunner().run(buildTestSuite())
21+
if not results.wasSuccessful(): sys.exit(1)
2122

2223
if __name__ == "__main__":
2324
#Allow us to import the parent module

tests/test_parser.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -113,47 +113,49 @@ def sortattrs(x):
113113
return "\n".join(lines)
114114

115115
class TestCase(unittest.TestCase):
116-
def runParserTest(self, innerHTML, input, expected, errors, treeClass):
117-
#XXX - move this out into the setup function
118-
#concatenate all consecutive character tokens into a single token
119-
p = html5parser.HTMLParser(tree = treeClass)
120-
if innerHTML:
121-
document = p.parseFragment(StringIO.StringIO(input), innerHTML)
122-
else:
123-
document = p.parse(StringIO.StringIO(input))
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)
130-
errStr = ["Line: %i Col: %i %s"%(line, col, message) for
131-
((line,col), message) in p.errors]
132-
errorMsg2 = "\n".join(["\n\nInput errors:\n" + "\n".join(errors),
133-
"Actual errors:\n" + "\n".join(errStr)])
134-
if checkParseErrors:
135-
self.assertEquals(len(p.errors), len(errors), errorMsg2)
136-
116+
def runParserTest(self, innerHTML, input, expected, errors):
117+
for treeName, treeClass in treeTypes.iteritems():
118+
#XXX - move this out into the setup function
119+
#concatenate all consecutive character tokens into a single token
120+
p = html5parser.HTMLParser(tree = treeClass)
121+
if innerHTML:
122+
document = p.parseFragment(StringIO.StringIO(input), innerHTML)
123+
else:
124+
document = p.parse(StringIO.StringIO(input))
125+
output = convertTreeDump(p.tree.testSerializer(document))
126+
output = attrlist.sub(sortattrs, output)
127+
expected = attrlist.sub(sortattrs, expected)
128+
errorMsg = "\n".join(["\n\nTree:", treeName,
129+
"\nExpected:", expected,
130+
"\nRecieved:", output])
131+
self.assertEquals(expected, output, errorMsg)
132+
errStr = ["Line: %i Col: %i %s"%(line, col, message) for
133+
((line,col), message) in p.errors]
134+
errorMsg2 = "\n".join(["\n\nInput errors:\n" + "\n".join(errors),
135+
"Actual errors:\n" + "\n".join(errStr)])
136+
if checkParseErrors:
137+
self.assertEquals(len(p.errors), len(errors), errorMsg2)
138+
137139
def test_parser():
138-
for name, cls in treeTypes.iteritems():
139-
for filename in glob.glob('tree-construction/*.dat'):
140-
f = open(filename)
141-
tests = f.read().split("#data\n")
142-
for test in tests:
143-
if test == "":
144-
continue
145-
test = "#data\n" + test
146-
innerHTML, input, expected, errors = parseTestcase(test)
147-
yield TestCase.runParserTest, innerHTML, input, expected, errors, name, cls
140+
for filename in glob.glob('tree-construction/*.dat'):
141+
f = open(filename)
142+
tests = f.read().split("#data\n")
143+
for test in tests:
144+
if test == "":
145+
continue
146+
test = "#data\n" + test
147+
innerHTML, input, expected, errors = parseTestcase(test)
148+
yield TestCase.runParserTest, innerHTML, input, expected, errors
148149

149150
def buildTestSuite():
150151
tests = 0
151-
for func, innerHTML, input, expected, errors, treeName, treeCls in test_parser():
152+
for func, innerHTML, input, expected, errors in test_parser():
152153
tests += 1
153154
testName = 'test%d' % tests
154-
testFunc = lambda self, method=func, innerHTML=innerHTML, input=input, expected=expected, \
155-
errors=errors, treeCls=treeCls: method(self, innerHTML, input, expected, errors, treeCls)
156-
testFunc.__doc__ = 'Parser %s Tree %s Input: %s'%(testName, treeName, input)
155+
testFunc = lambda self, method=func, innerHTML=innerHTML, input=input, \
156+
expected=expected, errors=errors: \
157+
method(self, innerHTML, input, expected, errors)
158+
testFunc.__doc__ = 'Parser %s Input: %s'%(testName, input)
157159
instanceMethod = new.instancemethod(testFunc, None, TestCase)
158160
setattr(TestCase, testName, instanceMethod)
159161
return unittest.TestLoader().loadTestsFromTestCase(TestCase)

0 commit comments

Comments
 (0)
0