|
| 1 | +import os |
1 | 2 | import sys |
2 | 3 | import StringIO |
3 | 4 | import unittest |
@@ -218,38 +219,38 @@ def runTest(self, innerHTML, input, expected, errors, treeClass): |
218 | 219 | output = convertTokens(LintFilter(treeClass["walker"](document))) |
219 | 220 | output = attrlist.sub(sortattrs, output) |
220 | 221 | expected = attrlist.sub(sortattrs, expected) |
221 | | - errorMsg = "\n".join(["\n\nExpected:", expected, |
222 | | - "\nRecieved:", output]) |
223 | | - self.assertEquals(expected, output, errorMsg) |
| 222 | + self.assertEquals(expected, output, "\n".join([ |
| 223 | + "", "Input:", input, |
| 224 | + "", "Expected:", expected, |
| 225 | + "", "Recieved:", output |
| 226 | + ])) |
224 | 227 | except LintError, le: |
225 | 228 | self.fail(le.message) |
226 | 229 | except NotImplementedError: |
227 | 230 | pass # Amnesty for those that confess... |
228 | 231 |
|
229 | | -def test_treewalker(): |
| 232 | +def buildTestSuite(): |
230 | 233 | sys.stdout.write('Testing tree walkers '+ " ".join(treeTypes.keys()) + "\n") |
231 | 234 |
|
232 | | - for name, cls in treeTypes.iteritems(): |
| 235 | + for treeName, treeCls in treeTypes.iteritems(): |
233 | 236 | for filename in html5lib_test_files('tree-construction'): |
| 237 | + testName = os.path.basename(filename).replace(".dat","") |
| 238 | + if testName == "tests5": continue # TODO |
| 239 | + |
234 | 240 | f = open(filename) |
235 | 241 | tests = f.read().split("#data\n") |
236 | | - for test in tests: |
237 | | - if test == "": |
238 | | - continue |
| 242 | + |
| 243 | + for index, test in enumerate(tests): |
| 244 | + if test == "": continue |
239 | 245 | test = "#data\n" + test |
240 | 246 | innerHTML, input, expected, errors = parseTestcase(test) |
241 | | - yield TestCase.runTest, innerHTML, input, expected, errors, name, cls |
242 | 247 |
|
243 | | -def buildTestSuite(): |
244 | | - tests = 0 |
245 | | - for func, innerHTML, input, expected, errors, treeName, treeCls in test_treewalker(): |
246 | | - tests += 1 |
247 | | - testName = 'test%d' % tests |
248 | | - def testFunc(self, method=func, innerHTML=innerHTML, input=input, |
249 | | - expected=expected, errors=errors, treeCls=treeCls): |
250 | | - method(self, innerHTML, input, expected, errors, treeCls) |
251 | | - testFunc.__doc__ = 'Parser %s Tree %s Input: %s'%(testName, treeName, input) |
252 | | - setattr(TestCase, testName, testFunc) |
| 248 | + def testFunc(self, innerHTML=innerHTML, input=input, |
| 249 | + expected=expected, errors=errors, treeCls=treeCls): |
| 250 | + self.runTest(innerHTML, input, expected, errors, treeCls) |
| 251 | + setattr(TestCase, "test_%s_%d_%s" % (testName,index+1,treeName), |
| 252 | + testFunc) |
| 253 | + |
253 | 254 | return unittest.TestLoader().loadTestsFromTestCase(TestCase) |
254 | 255 |
|
255 | 256 | def main(): |
|
0 commit comments