Skip to content

Commit 571ac99

Browse files
committed
Add expected failures for tree-construction tests.
1 parent 95b673f commit 571ac99

File tree

4 files changed

+119
-8
lines changed

4 files changed

+119
-8
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#data
2+
<html><ruby>a<rtc>b<rt>c<rb>d</ruby></html>
3+
#data
4+
<html><ruby>a<rb>b<rt></ruby></html>
5+
#data
6+
<!DOCTYPE html><body><svg attributename='' attributetype='' basefrequency='' baseprofile='' calcmode='' clippathunits='' contentscripttype='' contentstyletype='' diffuseconstant='' edgemode='' externalresourcesrequired='' filterres='' filterunits='' glyphref='' gradienttransform='' gradientunits='' kernelmatrix='' kernelunitlength='' keypoints='' keysplines='' keytimes='' lengthadjust='' limitingconeangle='' markerheight='' markerunits='' markerwidth='' maskcontentunits='' maskunits='' numoctaves='' pathlength='' patterncontentunits='' patterntransform='' patternunits='' pointsatx='' pointsaty='' pointsatz='' preservealpha='' preserveaspectratio='' primitiveunits='' refx='' refy='' repeatcount='' repeatdur='' requiredextensions='' requiredfeatures='' specularconstant='' specularexponent='' spreadmethod='' startoffset='' stddeviation='' stitchtiles='' surfacescale='' systemlanguage='' tablevalues='' targetx='' targety='' textlength='' viewbox='' viewtarget='' xchannelselector='' ychannelselector='' zoomandpan=''></svg>
7+
#data
8+
<html><ruby>a<rt>b<rb></ruby></html>
9+
#data
10+
<html><ruby>a<rt>b<rtc></ruby></html>
11+
#data
12+
<html><ruby><rtc><ruby>a<rb>b<rt></ruby></ruby></html>
13+
#data
14+
<!DOCTYPE html><body><command>A
15+
#data
16+
<html><ruby>a<rb>b<rp></ruby></html>
17+
#data
18+
<!DOCTYPE html><body><svg attributeName='' attributeType='' baseFrequency='' baseProfile='' calcMode='' clipPathUnits='' contentScriptType='' contentStyleType='' diffuseConstant='' edgeMode='' externalResourcesRequired='' filterRes='' filterUnits='' glyphRef='' gradientTransform='' gradientUnits='' kernelMatrix='' kernelUnitLength='' keyPoints='' keySplines='' keyTimes='' lengthAdjust='' limitingConeAngle='' markerHeight='' markerUnits='' markerWidth='' maskContentUnits='' maskUnits='' numOctaves='' pathLength='' patternContentUnits='' patternTransform='' patternUnits='' pointsAtX='' pointsAtY='' pointsAtZ='' preserveAlpha='' preserveAspectRatio='' primitiveUnits='' refX='' refY='' repeatCount='' repeatDur='' requiredExtensions='' requiredFeatures='' specularConstant='' specularExponent='' spreadMethod='' startOffset='' stdDeviation='' stitchTiles='' surfaceScale='' systemLanguage='' tableValues='' targetX='' targetY='' textLength='' viewBox='' viewTarget='' xChannelSelector='' yChannelSelector='' zoomAndPan=''></svg>
19+
#data
20+
<html><ruby>a<rtc>b<rtc></ruby></html>
21+
#data
22+
<!DOCTYPE html><frameset> te st
23+
#data
24+
<html><ruby>a<rp>b<rtc></ruby></html>
25+
#data
26+
<!DOCTYPE html><frameset></frameset> te st
27+
#data
28+
<html><ruby>a<rb>b<rb></ruby></html>
29+
#data
30+
<html><ruby>a<rtc>b<rp></ruby></html>
31+
#data
32+
<!DOCTYPE html><body><menuitem>A
33+
#data
34+
<!DOCTYPE html><BODY><SVG ATTRIBUTENAME='' ATTRIBUTETYPE='' BASEFREQUENCY='' BASEPROFILE='' CALCMODE='' CLIPPATHUNITS='' CONTENTSCRIPTTYPE='' CONTENTSTYLETYPE='' DIFFUSECONSTANT='' EDGEMODE='' EXTERNALRESOURCESREQUIRED='' FILTERRES='' FILTERUNITS='' GLYPHREF='' GRADIENTTRANSFORM='' GRADIENTUNITS='' KERNELMATRIX='' KERNELUNITLENGTH='' KEYPOINTS='' KEYSPLINES='' KEYTIMES='' LENGTHADJUST='' LIMITINGCONEANGLE='' MARKERHEIGHT='' MARKERUNITS='' MARKERWIDTH='' MASKCONTENTUNITS='' MASKUNITS='' NUMOCTAVES='' PATHLENGTH='' PATTERNCONTENTUNITS='' PATTERNTRANSFORM='' PATTERNUNITS='' POINTSATX='' POINTSATY='' POINTSATZ='' PRESERVEALPHA='' PRESERVEASPECTRATIO='' PRIMITIVEUNITS='' REFX='' REFY='' REPEATCOUNT='' REPEATDUR='' REQUIREDEXTENSIONS='' REQUIREDFEATURES='' SPECULARCONSTANT='' SPECULAREXPONENT='' SPREADMETHOD='' STARTOFFSET='' STDDEVIATION='' STITCHTILES='' SURFACESCALE='' SYSTEMLANGUAGE='' TABLEVALUES='' TARGETX='' TARGETY='' TEXTLENGTH='' VIEWBOX='' VIEWTARGET='' XCHANNELSELECTOR='' YCHANNELSELECTOR='' ZOOMANDPAN=''></SVG>
35+
#data
36+
<html><ruby>a<rp>b<rb></ruby></html>
37+
#data
38+
<html><ruby>a<rb>b<rtc></ruby></html>
39+
#data
40+
<html><ruby>a<rtc>b<rb></ruby></html>

html5lib/tests/support.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,15 @@ def processingInstruction(self, target, data):
175175

176176
def skippedEntity(self, name):
177177
self.visited.append(('skippedEntity', name))
178+
179+
180+
def xfail(test):
181+
"""Expected fail decorator function"""
182+
def t(*args, **kwargs):
183+
try:
184+
test(*args)
185+
except:
186+
return
187+
else:
188+
assert False, "UNEXPECTED PASS"
189+
return t

html5lib/tests/test_parser.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from .support import get_data_files
1212
from .support import TestData, convert, convertExpected, treeTypes
13+
from .support import xfail
1314
from html5lib import html5parser, constants
1415

1516
# Run the parse error checks
@@ -26,7 +27,11 @@ def convertTreeDump(data):
2627

2728

2829
def runParserTest(innerHTML, input, expected, errors, treeClass,
29-
namespaceHTMLElements):
30+
namespaceHTMLElements, scriptingDisabled):
31+
if scriptingDisabled:
32+
# We don't support the scripting disabled case!
33+
return
34+
3035
with warnings.catch_warnings(record=True) as caughtWarnings:
3136
warnings.simplefilter("always")
3237
p = html5parser.HTMLParser(tree=treeClass,
@@ -71,10 +76,24 @@ def runParserTest(innerHTML, input, expected, errors, treeClass,
7176
assert len(p.errors) == len(errors), errorMsg2
7277

7378

79+
@xfail
80+
def xfailRunParserTest(*args, **kwargs):
81+
return runParserTest(*args, **kwargs)
82+
83+
7484
def test_parser():
85+
# Testin'
7586
sys.stderr.write('Testing tree builders ' + " ".join(list(treeTypes.keys())) + "\n")
76-
files = get_data_files('tree-construction')
7787

88+
# Get xfails
89+
filename = os.path.join(os.path.split(__file__)[0],
90+
"expected-failures",
91+
"tree-construction.dat")
92+
xfails = TestData(filename, "data")
93+
xfails = frozenset([x["data"] for x in xfails])
94+
95+
# Get the tests
96+
files = get_data_files('tree-construction')
7897
for filename in files:
7998
testName = os.path.basename(filename).replace(".dat", "")
8099
if testName in ("template",):
@@ -84,13 +103,25 @@ def test_parser():
84103

85104
for index, test in enumerate(tests):
86105
input, errors, innerHTML, expected = [test[key] for key in
87-
('data', 'errors',
106+
('data',
107+
'errors',
88108
'document-fragment',
89109
'document')]
110+
90111
if errors:
91112
errors = errors.split("\n")
92113

114+
assert not ("script-off" in test and "script-on" in test), \
115+
("The following test has scripting enabled" +
116+
"and disabled all at once: %s in %s" % (input, filename))
117+
118+
scriptingDisabled = "script-off" in test
119+
93120
for treeName, treeCls in treeTypes.items():
94121
for namespaceHTMLElements in (True, False):
95-
yield (runParserTest, innerHTML, input, expected, errors, treeCls,
96-
namespaceHTMLElements)
122+
if input in xfails:
123+
testFunc = xfailRunParserTest
124+
else:
125+
testFunc = runParserTest
126+
yield (testFunc, innerHTML, input, expected, errors, treeCls,
127+
namespaceHTMLElements, scriptingDisabled)

html5lib/tests/test_treewalkers.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
except AttributeError:
1212
unittest.TestCase.assertEqual = unittest.TestCase.assertEquals
1313

14-
from .support import get_data_files, TestData, convertExpected
14+
from .support import get_data_files, TestData, convertExpected, xfail
1515

1616
from html5lib import html5parser, treewalkers, treebuilders, constants
1717

@@ -250,7 +250,11 @@ def test_all_tokens(self):
250250
self.assertEqual(expectedToken, outputToken)
251251

252252

253-
def runTreewalkerTest(innerHTML, input, expected, errors, treeClass):
253+
def runTreewalkerTest(innerHTML, input, expected, errors, treeClass, scriptingDisabled):
254+
if scriptingDisabled:
255+
# We don't support the scripting disabled case!
256+
return
257+
254258
warnings.resetwarnings()
255259
warnings.simplefilter("error")
256260
try:
@@ -281,9 +285,22 @@ def runTreewalkerTest(innerHTML, input, expected, errors, treeClass):
281285
pass # Amnesty for those that confess...
282286

283287

288+
@xfail
289+
def xfailRunTreewalkerTest(*args, **kwargs):
290+
return runTreewalkerTest(*args, **kwargs)
291+
292+
284293
def test_treewalker():
285294
sys.stdout.write('Testing tree walkers ' + " ".join(list(treeTypes.keys())) + "\n")
286295

296+
# Get xfails
297+
filename = os.path.join(os.path.split(__file__)[0],
298+
"expected-failures",
299+
"tree-construction.dat")
300+
xfails = TestData(filename, "data")
301+
xfails = frozenset([x["data"] for x in xfails])
302+
303+
# Get the tests
287304
for treeName, treeCls in treeTypes.items():
288305
files = get_data_files('tree-construction')
289306
for filename in files:
@@ -299,7 +316,18 @@ def test_treewalker():
299316
"document-fragment",
300317
"document")]
301318
errors = errors.split("\n")
302-
yield runTreewalkerTest, innerHTML, input, expected, errors, treeCls
319+
320+
assert not ("script-off" in test and "script-on" in test), \
321+
("The following test has scripting enabled" +
322+
"and disabled all at once: %s in %s" % (input, filename))
323+
324+
scriptingDisabled = "script-off" in test
325+
326+
if input in xfails:
327+
testFunc = xfailRunTreewalkerTest
328+
else:
329+
testFunc = runTreewalkerTest
330+
yield testFunc, innerHTML, input, expected, errors, treeCls, scriptingDisabled
303331

304332

305333
def set_attribute_on_first_child(docfrag, name, value, treeName):

0 commit comments

Comments
 (0)