Skip to content

Commit 14ee2b6

Browse files
author
Mark Pilgrim
committed
attribute existence tests for conformance checker
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40966
1 parent d9f62c0 commit 14ee2b6

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

src/html5lib/filters/validator.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
'onmousewheel', 'onresize', 'onscroll', 'onselect', 'onsubmit', 'onunload']
3636
# XXX lang in HTML only, xml:lang in XHTML only
3737

38-
modAttributes = ['cite', 'datetime']
39-
mediaAttributes = ['src', 'autoplay', 'start', 'loopstart', 'loopend', 'end',
40-
'loopcount', 'controls'],
4138
allowedAttributeMap = {
4239
'html': ['xmlns'],
4340
'base': ['href', 'target'],
@@ -52,14 +49,16 @@
5249
'time': ['datetime'],
5350
'meter': ['value', 'min', 'low', 'high', 'max', 'optimum'],
5451
'progress': ['value', 'max'],
55-
'ins': modAttributes,
56-
'del': modAttributes,
52+
'ins': ['cite', 'datetime'],
53+
'del': ['cite', 'datetime'],
5754
'img': ['alt', 'src', 'usemap', 'ismap', 'height', 'width'], # XXX ismap depends on parent
5855
'iframe': ['src'],
5956
'object': ['data', 'type', 'usemap', 'height', 'width'],
6057
'param': ['name', 'value'],
61-
'video': mediaAttributes,
62-
'audio': mediaAttributes,
58+
'video': ['src', 'autoplay', 'start', 'loopstart', 'loopend', 'end',
59+
'loopcount', 'controls'],
60+
'audio': ['src', 'autoplay', 'start', 'loopstart', 'loopend', 'end',
61+
'loopcount', 'controls'],
6362
'source': ['src', 'type', 'media'],
6463
'canvas': ['height', 'width'],
6564
'area': ['alt', 'coords', 'shape', 'href', 'target', 'ping', 'rel',

tests/test_validator.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os, unittest
2+
from support import simplejson, html5lib_test_files
3+
from html5lib.html5parser import HTMLParser
4+
from html5lib.filters.validator import HTMLConformanceChecker
5+
6+
class TestCase(unittest.TestCase):
7+
def runValidatorTest(self, test):
8+
p = HTMLParser(tokenizer=HTMLConformanceChecker)
9+
p.parse(test['input'])
10+
errorCodes = [errorcode for position, errorcode, datavars in p.errors]
11+
if test.has_key('fail-if'):
12+
self.failIf(test['fail-if'] in errorCodes)
13+
if test.has_key('fail-unless'):
14+
self.failUnless(test['fail-unless'] in errorCodes)
15+
16+
def buildTestSuite():
17+
for filename in html5lib_test_files('validator', '*.test'):
18+
tests = simplejson.load(file(filename))
19+
testName = os.path.basename(filename).replace(".test","")
20+
for index,test in enumerate(tests['tests']):
21+
def testFunc(self, test=test):
22+
self.runValidatorTest(test)
23+
testFunc.__doc__ = "\t".join([testName, test['description']])
24+
setattr(TestCase, 'test_%s_%d' % (testName, index), testFunc)
25+
return unittest.TestLoader().loadTestsFromTestCase(TestCase)
26+
27+
def main():
28+
buildTestSuite()
29+
unittest.main()
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)