def runTreewalkerTest(innerHTML, input, expected, errors, treeClass): warnings.resetwarnings() warnings.simplefilter("error") try: p = html5parser.HTMLParser(tree=treeClass["builder"]) if innerHTML: document = p.parseFragment(input, innerHTML) else: document = p.parse(input) except constants.DataLossWarning: # Ignore testcases we know we don't pass return document = treeClass.get("adapter", lambda x: x)(document) try: output = treewalkers.pprint(treeClass["walker"](document)) output = attrlist.sub(sortattrs, output) expected = attrlist.sub(sortattrs, convertExpected(expected)) diff = "".join(unified_diff([line + "\n" for line in expected.splitlines()], [line + "\n" for line in output.splitlines()], "Expected", "Received")) assert expected == output, "\n".join([ "", "Input:", input, "", "Expected:", expected, "", "Received:", output, "", "Diff:", diff, ]) except NotImplementedError: pass # Amnesty for those that confess...
def runTreewalkerTest(innerHTML, input, expected, errors, treeClass): warnings.resetwarnings() warnings.simplefilter("error") try: p = html5parser.HTMLParser(tree=treeClass["builder"]) if innerHTML: document = p.parseFragment(input, innerHTML) else: document = p.parse(input) except constants.DataLossWarning: # Ignore testcases we know we don't pass return document = treeClass.get("adapter", lambda x: x)(document) try: output = treewalkers.pprint(Lint(treeClass["walker"](document))) output = attrlist.sub(sortattrs, output) expected = attrlist.sub(sortattrs, convertExpected(expected)) diff = "".join(unified_diff([line + "\n" for line in expected.splitlines()], [line + "\n" for line in output.splitlines()], "Expected", "Received")) assert expected == output, "\n".join([ "", "Input:", input, "", "Expected:", expected, "", "Received:", output, "", "Diff:", diff, ]) except NotImplementedError: pass # Amnesty for those that confess...
def runtest(self): if self.treeAPIs is None: pytest.skip("Treebuilder not loaded") p = html5parser.HTMLParser(tree=self.treeAPIs["builder"]) input = self.test['data'] fragmentContainer = self.test['document-fragment'] expected = convertExpected(self.test['document']) scripting = False if 'script-on' in self.test: scripting = True with warnings.catch_warnings(): warnings.simplefilter("error") try: if fragmentContainer: document = p.parseFragment(input, fragmentContainer, scripting=scripting) else: document = p.parse(input, scripting=scripting) except constants.DataLossWarning: pytest.skip("data loss warning") poutput = convertTreeDump(p.tree.testSerializer(document)) namespace_expected = namespaceExpected(r"\1<html \2>", expected) if poutput != namespace_expected: pytest.skip("parser output incorrect") document = self.treeAPIs.get("adapter", lambda x: x)(document) try: output = treewalkers.pprint(Lint( self.treeAPIs["walker"](document))) output = sortattrs(output) expected = sortattrs(expected) diff = "".join( unified_diff([line + "\n" for line in expected.splitlines()], [line + "\n" for line in output.splitlines()], "Expected", "Received")) assert expected == output, "\n".join([ "", "Input:", input, "", "Expected:", expected, "", "Received:", output, "", "Diff:", diff, ]) except NotImplementedError: pytest.skip("tree walker NotImplementedError")
def runTreewalkerEditTest(intext, expected, attrs_to_add, tree): """tests what happens when we add attributes to the intext""" treeName, treeClass = tree parser = html5parser.HTMLParser(tree=treeClass["builder"]) document = parser.parseFragment(intext) for nom, val in attrs_to_add: set_attribute_on_first_child(document, nom, val, treeName) document = treeClass.get("adapter", lambda x: x)(document) output = treewalkers.pprint(treeClass["walker"](document)) output = attrlist.sub(sortattrs, output) if not output in expected: raise AssertionError("TreewalkerEditTest: %s\nExpected:\n%s\nReceived:\n%s" % (treeName, expected, output))
def runtest(self): p = html5parser.HTMLParser(tree=self.treeAPIs["builder"]) input = self.test['data'] fragmentContainer = self.test['document-fragment'] expected = convertExpected(self.test['document']) scripting = False if 'script-on' in self.test: scripting = True with warnings.catch_warnings(): warnings.simplefilter("error") try: if fragmentContainer: document = p.parseFragment(input, fragmentContainer, scripting=scripting) else: document = p.parse(input, scripting=scripting) except constants.DataLossWarning: pytest.skip("data loss warning") poutput = convertTreeDump(p.tree.testSerializer(document)) namespace_expected = namespaceExpected(r"\1<html \2>", expected) if poutput != namespace_expected: pytest.skip("parser output incorrect") document = self.treeAPIs.get("adapter", lambda x: x)(document) try: output = treewalkers.pprint(Lint(self.treeAPIs["walker"](document))) output = sortattrs(output) expected = sortattrs(expected) diff = "".join(unified_diff([line + "\n" for line in expected.splitlines()], [line + "\n" for line in output.splitlines()], "Expected", "Received")) assert expected == output, "\n".join([ "", "Input:", input, "", "Expected:", expected, "", "Received:", output, "", "Diff:", diff, ]) except NotImplementedError: pytest.skip("tree walker NotImplementedError")
def runTreewalkerTest(innerHTML, input, expected, errors, treeClass): warnings.resetwarnings() warnings.simplefilter('error') try: p = html5parser.HTMLParser(tree=treeClass['builder']) if innerHTML: document = p.parseFragment(input, innerHTML) else: document = p.parse(input) except constants.DataLossWarning: # Ignore testcases we know we don't pass return document = treeClass.get('adapter', lambda x: x)(document) try: output = treewalkers.pprint(treeClass['walker'](document)) output = attrlist.sub(sortattrs, output) expected = attrlist.sub(sortattrs, convertExpected(expected)) diff = ''.join( unified_diff([line + '\n' for line in expected.splitlines()], [line + '\n' for line in output.splitlines()], 'Expected', 'Received')) assert expected == output, '\n'.join([ '', 'Input:', input, '', 'Expected:', expected, '', 'Received:', output, '', 'Diff:', diff, ]) except NotImplementedError: pass # Amnesty for those that confess...