Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2db6861

Browse files
committed
First pass at changing parser test runner to test both namespaced and non-namespaced modes. This also removes the checks to stop namespaced HTML elements having their prefixes removed during test serialization.
1 parentdafe834 commit2db6861

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

‎src/html5lib/treebuilders/dom.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ def serializeElement(element, indent=0):
192192
rv.append("|%s\"%s\""%(' '*indent,element.nodeValue))
193193
else:
194194
if (hasattr(element,"namespaceURI")and
195-
element.namespaceURInotin (None,
196-
constants.namespaces["html"])):
195+
element.namespaceURI!=None):
197196
name="%s %s"%(constants.prefixes[element.namespaceURI],
198197
element.nodeName)
199198
else:

‎src/html5lib/treebuilders/etree.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ def serializeElement(element, indent=0):
227227
else:
228228
ns,name=nsmatch.groups()
229229
prefix=constants.prefixes[ns]
230-
ifprefix!="html":
231-
name="%s %s"%(prefix,name)
230+
name="%s %s"%(prefix,name)
232231
rv.append("|%s<%s>"%(' '*indent,name))
233232

234233
ifhasattr(element,"attrib"):

‎src/html5lib/treebuilders/etree_lxml.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,8 @@ def serializeElement(element, indent=0):
8686
ns=nsmatch.group(1)
8787
tag=nsmatch.group(2)
8888
prefix=constants.prefixes[ns]
89-
ifprefix!="html":
90-
rv.append("|%s<%s %s>"%(' '*indent,prefix,
91-
filter.fromXmlName(tag)))
92-
else:
93-
rv.append("|%s<%s>"%(' '*indent,
94-
filter.fromXmlName(tag)))
89+
rv.append("|%s<%s %s>"%(' '*indent,prefix,
90+
filter.fromXmlName(tag)))
9591
else:
9692
rv.append("|%s<%s>"%(' '*indent,
9793
filter.fromXmlName(element.tag)))

‎src/html5lib/treebuilders/simpletree.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(self, name, namespace=None):
162162
self.attributes= {}
163163

164164
def__unicode__(self):
165-
ifself.namespacein (None,namespaces["html"]):
165+
ifself.namespace==None:
166166
returnu"<%s>"%self.name
167167
else:
168168
returnu"<%s %s>"%(prefixes[self.namespace],self.name)

‎tests/test_parser.py‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ def sortattrs(x):
7373
lines=x.group(0).split("\n")
7474
lines.sort()
7575
return"\n".join(lines)
76+
namespaceExpected=re.compile(r"^(\s*)<(\w+)>",re.M).sub
7677

7778
classTestCase(unittest.TestCase):
78-
defrunParserTest(self,innerHTML,input,expected,errors,treeClass):
79+
defrunParserTest(self,innerHTML,input,expected,errors,treeClass,
80+
namespaceHTMLElements):
7981
#XXX - move this out into the setup function
8082
#concatenate all consecutive character tokens into a single token
81-
p=html5parser.HTMLParser(tree=treeClass)
83+
p=html5parser.HTMLParser(tree=treeClass,
84+
namespaceHTMLElements=namespaceHTMLElements)
8285

8386
errors= [item.decode("utf-8")foriteminerrors]
8487

@@ -101,6 +104,9 @@ def runParserTest(self, innerHTML, input, expected, errors, treeClass):
101104

102105
expected=convertExpected(expected)
103106
expected=attrlist.sub(sortattrs,expected)
107+
ifnamespaceHTMLElements:
108+
expected=namespaceExpected(r"\1<html \2>",expected)
109+
104110
errorMsg="\n".join(["\n\nInput:",input,"\nExpected:",expected,
105111
"\nReceived:",output])
106112
self.assertEquals(expected,output,errorMsg.encode("utf-8"))
@@ -133,12 +139,17 @@ def buildTestSuite():
133139
'document']
134140
iferrors:
135141
errors=errors.split("\n")
136-
deftestFunc(self,innerHTML=innerHTML,input=input,
137-
expected=expected,errors=errors,treeCls=treeCls):
138-
returnself.runParserTest(innerHTML,input,expected,errors,treeCls)
139-
testFunc.__name__="test_%s_%d_%s"% (testName,index+1,treeName)
140-
setattr(TestCase,testFunc.__name__,
141-
testFunc)
142+
143+
fornamespaceHTMLElementsin (True,False):
144+
deftestFunc(self,innerHTML=innerHTML,input=input,
145+
expected=expected,errors=errors,treeCls=treeCls,
146+
namespaceHTMLElements=namespaceHTMLElements):
147+
returnself.runParserTest(innerHTML,input,expected,
148+
errors,treeCls,
149+
namespaceHTMLElements)
150+
testFunc.__name__="test_%s_%d_%s_%s"% (testName,index+1,treeName,namespaceHTMLElementsand"namespaced"or"no_html_namespace")
151+
setattr(TestCase,testFunc.__name__,
152+
testFunc)
142153

143154
returnunittest.TestLoader().loadTestsFromTestCase(TestCase)
144155

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp