forked from html5lib/html5lib-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validator.py
More file actions
executable file
·32 lines (28 loc) · 1.23 KB
/
test_validator.py
File metadata and controls
executable file
·32 lines (28 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os, unittest
from support import simplejson, html5lib_test_files
from html5lib.html5parser import HTMLParser
from html5lib.filters.validator import HTMLConformanceChecker
class TestCase(unittest.TestCase):
def runValidatorTest(self, test):
p = HTMLParser(tokenizer=HTMLConformanceChecker)
p.parse(test['input'])
errorCodes = [errorcode for position, errorcode, datavars in p.errors]
if test.has_key('fail-if'):
self.failIf(test['fail-if'] in errorCodes)
if test.has_key('fail-unless'):
self.failUnless(test['fail-unless'] in errorCodes)
def buildTestSuite():
for filename in html5lib_test_files('validator', '*.test'):
tests = simplejson.load(file(filename))
testName = os.path.basename(filename).replace(".test","")
for index,test in enumerate(tests['tests']):
def testFunc(self, test=test):
self.runValidatorTest(test)
testFunc.__doc__ = "\t".join([testName, test['description']])
setattr(TestCase, 'test_%s_%d' % (testName, index), testFunc)
return unittest.TestLoader().loadTestsFromTestCase(TestCase)
def main():
buildTestSuite()
unittest.main()
if __name__ == "__main__":
main()