2
2
import sys
3
3
import StringIO
4
4
import unittest
5
- from support import html5lib_test_files , TestData
5
+ from support import html5lib_test_files , TestData , convert , convertExpected
6
6
7
7
from html5lib import html5parser , treebuilders
8
8
46
46
#Run the parse error checks
47
47
checkParseErrors = False # TODO
48
48
49
- def convert (stripChars ):
50
- def convertData (data ):
51
- """convert the output of str(document) to the format used in the testcases"""
52
- data = data .split ("\n " )
53
- rv = []
54
- for line in data :
55
- if line .startswith ("|" ):
56
- rv .append (line [stripChars :])
57
- else :
58
- rv .append (line )
59
- return "\n " .join (rv )
60
- return convertData
61
49
#XXX - There should just be one function here but for some reason the testcase
62
50
#format differs from the treedump format by a single space character
63
-
64
51
def convertTreeDump (data ):
65
52
return "\n " .join (convert (3 )(data ).split ("\n " )[1 :])
66
53
67
- convertExpected = convert (2 )
68
-
69
54
import re
70
55
attrlist = re .compile (r"^(\s+)\w+=.*(\n\1\w+=.*)+" ,re .M )
71
56
def sortattrs (x ):
@@ -98,9 +83,6 @@ def runParserTest(self, innerHTML, input, expected, errors, treeClass):
98
83
if checkParseErrors :
99
84
self .assertEquals (len (p .errors ), len (errors ), errorMsg2 )
100
85
101
- def test_parser ():
102
- yield innerHTML , input , expected , errors , treeName , treeCls
103
-
104
86
def buildTestSuite ():
105
87
sys .stdout .write ('Testing tree builders ' + " " .join (treeTypes .keys ()) + "\n " )
106
88
@@ -112,10 +94,10 @@ def buildTestSuite():
112
94
tests = TestData (filename , ("data" , "errors" , "document-fragment" ,
113
95
"document" ))
114
96
115
- for index , test in enumerate (tests ):
116
- errors = test [ ' errors' ] .split ("\n " )
117
- def testFunc (self , innerHTML = test [ 'document-fragment' ] , input = test [ 'data' ] ,
118
- expected = test [ 'document' ] , errors = errors , treeCls = treeCls ):
97
+ for index , ( input , errors , innerHTML , expected ) in enumerate (tests ):
98
+ errors = errors .split ("\n " )
99
+ def testFunc (self , innerHTML = innerHTML , input = input ,
100
+ expected = expected , errors = errors , treeCls = treeCls ):
119
101
return self .runParserTest (innerHTML , input , expected , errors , treeCls )
120
102
setattr (TestCase , "test_%s_%d_%s" % (testName ,index + 1 ,treeName ),
121
103
testFunc )
0 commit comments