From 95b673f47e6338bd75f1005a622cfa388ed9b4f3 Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Sat, 22 Nov 2014 17:37:06 +0100 Subject: [PATCH 1/8] Fix over indentation --- html5lib/tests/test_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html5lib/tests/test_parser.py b/html5lib/tests/test_parser.py index 230cdb42..0f958c94 100644 --- a/html5lib/tests/test_parser.py +++ b/html5lib/tests/test_parser.py @@ -68,7 +68,7 @@ def runParserTest(innerHTML, input, expected, errors, treeClass, "\nExpected errors (" + str(len(errors)) + "):\n" + "\n".join(errors), "\nActual errors (" + str(len(p.errors)) + "):\n" + "\n".join(errStr)]) if checkParseErrors: - assert len(p.errors) == len(errors), errorMsg2 + assert len(p.errors) == len(errors), errorMsg2 def test_parser(): From 5ef00b1e91d717f583cbb951d90f99cef9fc83d4 Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Sat, 22 Nov 2014 18:39:13 +0100 Subject: [PATCH 2/8] Add expected failures for tree-construction tests. --- .../expected-failures/tree-construction.dat | 59 +++++++++++++++++++ html5lib/tests/support.py | 12 ++++ html5lib/tests/test_parser.py | 41 +++++++++++-- html5lib/tests/test_treewalkers.py | 34 ++++++++++- 4 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 html5lib/tests/expected-failures/tree-construction.dat diff --git a/html5lib/tests/expected-failures/tree-construction.dat b/html5lib/tests/expected-failures/tree-construction.dat new file mode 100644 index 00000000..69d8b307 --- /dev/null +++ b/html5lib/tests/expected-failures/tree-construction.dat @@ -0,0 +1,59 @@ +#data +abcd + +#data +ab + +#data + + +#data +ab + +#data +ab + +#data +ab + +#data +A + +#data +ab + +#data + + +#data +ab + +#data + te st + +#data +ab + +#data + te st + +#data +ab + +#data +ab + +#data +A + +#data + + +#data +ab + +#data +ab + +#data +ab diff --git a/html5lib/tests/support.py b/html5lib/tests/support.py index 41f2d2a0..0792731e 100644 --- a/html5lib/tests/support.py +++ b/html5lib/tests/support.py @@ -175,3 +175,15 @@ def processingInstruction(self, target, data): def skippedEntity(self, name): self.visited.append(('skippedEntity', name)) + + +def xfail(test): + """Expected fail decorator function""" + def t(*args, **kwargs): + try: + test(*args) + except: + return + else: + assert False, "UNEXPECTED PASS" + return t diff --git a/html5lib/tests/test_parser.py b/html5lib/tests/test_parser.py index 0f958c94..2b7f03be 100644 --- a/html5lib/tests/test_parser.py +++ b/html5lib/tests/test_parser.py @@ -10,6 +10,7 @@ from .support import get_data_files from .support import TestData, convert, convertExpected, treeTypes +from .support import xfail from html5lib import html5parser, constants # Run the parse error checks @@ -26,7 +27,11 @@ def convertTreeDump(data): def runParserTest(innerHTML, input, expected, errors, treeClass, - namespaceHTMLElements): + namespaceHTMLElements, scriptingDisabled): + if scriptingDisabled: + # We don't support the scripting disabled case! + return + with warnings.catch_warnings(record=True) as caughtWarnings: warnings.simplefilter("always") p = html5parser.HTMLParser(tree=treeClass, @@ -71,10 +76,24 @@ def runParserTest(innerHTML, input, expected, errors, treeClass, assert len(p.errors) == len(errors), errorMsg2 +@xfail +def xfailRunParserTest(*args, **kwargs): + return runParserTest(*args, **kwargs) + + def test_parser(): + # Testin' sys.stderr.write('Testing tree builders ' + " ".join(list(treeTypes.keys())) + "\n") - files = get_data_files('tree-construction') + # Get xfails + filename = os.path.join(os.path.split(__file__)[0], + "expected-failures", + "tree-construction.dat") + xfails = TestData(filename, "data") + xfails = frozenset([x["data"] for x in xfails]) + + # Get the tests + files = get_data_files('tree-construction') for filename in files: testName = os.path.basename(filename).replace(".dat", "") if testName in ("template",): @@ -84,13 +103,25 @@ def test_parser(): for index, test in enumerate(tests): input, errors, innerHTML, expected = [test[key] for key in - ('data', 'errors', + ('data', + 'errors', 'document-fragment', 'document')] + if errors: errors = errors.split("\n") + assert not ("script-off" in test and "script-on" in test), \ + ("The following test has scripting enabled" + + "and disabled all at once: %s in %s" % (input, filename)) + + scriptingDisabled = "script-off" in test + for treeName, treeCls in treeTypes.items(): for namespaceHTMLElements in (True, False): - yield (runParserTest, innerHTML, input, expected, errors, treeCls, - namespaceHTMLElements) + if input in xfails: + testFunc = xfailRunParserTest + else: + testFunc = runParserTest + yield (testFunc, innerHTML, input, expected, errors, treeCls, + namespaceHTMLElements, scriptingDisabled) diff --git a/html5lib/tests/test_treewalkers.py b/html5lib/tests/test_treewalkers.py index b7756035..34520f7a 100644 --- a/html5lib/tests/test_treewalkers.py +++ b/html5lib/tests/test_treewalkers.py @@ -11,7 +11,7 @@ except AttributeError: unittest.TestCase.assertEqual = unittest.TestCase.assertEquals -from .support import get_data_files, TestData, convertExpected +from .support import get_data_files, TestData, convertExpected, xfail from html5lib import html5parser, treewalkers, treebuilders, constants @@ -250,7 +250,11 @@ def test_all_tokens(self): self.assertEqual(expectedToken, outputToken) -def runTreewalkerTest(innerHTML, input, expected, errors, treeClass): +def runTreewalkerTest(innerHTML, input, expected, errors, treeClass, scriptingDisabled): + if scriptingDisabled: + # We don't support the scripting disabled case! + return + warnings.resetwarnings() warnings.simplefilter("error") try: @@ -281,9 +285,22 @@ def runTreewalkerTest(innerHTML, input, expected, errors, treeClass): pass # Amnesty for those that confess... +@xfail +def xfailRunTreewalkerTest(*args, **kwargs): + return runTreewalkerTest(*args, **kwargs) + + def test_treewalker(): sys.stdout.write('Testing tree walkers ' + " ".join(list(treeTypes.keys())) + "\n") + # Get xfails + filename = os.path.join(os.path.split(__file__)[0], + "expected-failures", + "tree-construction.dat") + xfails = TestData(filename, "data") + xfails = frozenset([x["data"] for x in xfails]) + + # Get the tests for treeName, treeCls in treeTypes.items(): files = get_data_files('tree-construction') for filename in files: @@ -299,7 +316,18 @@ def test_treewalker(): "document-fragment", "document")] errors = errors.split("\n") - yield runTreewalkerTest, innerHTML, input, expected, errors, treeCls + + assert not ("script-off" in test and "script-on" in test), \ + ("The following test has scripting enabled" + + "and disabled all at once: %s in %s" % (input, filename)) + + scriptingDisabled = "script-off" in test + + if input in xfails: + testFunc = xfailRunTreewalkerTest + else: + testFunc = runTreewalkerTest + yield testFunc, innerHTML, input, expected, errors, treeCls, scriptingDisabled def set_attribute_on_first_child(docfrag, name, value, treeName): From c66d41e4e729c8bd3284b953e6498ba0826d952c Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Sat, 22 Nov 2014 20:42:46 +0000 Subject: [PATCH 3/8] Use the nose skip plugin to actually properly skip tests. --- html5lib/tests/support.py | 4 ++++ html5lib/tests/test_encoding.py | 4 +++- html5lib/tests/test_parser.py | 6 ++++-- html5lib/tests/test_treewalkers.py | 8 +++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/html5lib/tests/support.py b/html5lib/tests/support.py index 0792731e..78c5164e 100644 --- a/html5lib/tests/support.py +++ b/html5lib/tests/support.py @@ -6,6 +6,8 @@ import glob import xml.sax.handler +from nose.plugins.skip import SkipTest + base_path = os.path.split(__file__)[0] test_dir = os.path.join(base_path, 'testdata') @@ -182,6 +184,8 @@ def xfail(test): def t(*args, **kwargs): try: test(*args) + except SkipTest: + raise except: return else: diff --git a/html5lib/tests/test_encoding.py b/html5lib/tests/test_encoding.py index d774ce0f..1653610a 100644 --- a/html5lib/tests/test_encoding.py +++ b/html5lib/tests/test_encoding.py @@ -8,6 +8,8 @@ except AttributeError: unittest.TestCase.assertEqual = unittest.TestCase.assertEquals +from nose.plugins.skip import SkipTest + from .support import get_data_files, TestData, test_dir, errorMessage from html5lib import HTMLParser, inputstream @@ -41,7 +43,7 @@ def runPreScanEncodingTest(data, encoding): # Very crude way to ignore irrelevant tests if len(data) > stream.numBytesMeta: - return + raise SkipTest() assert encoding == stream.charEncoding[0], errorMessage(data, encoding, stream.charEncoding[0]) diff --git a/html5lib/tests/test_parser.py b/html5lib/tests/test_parser.py index 2b7f03be..13a52e67 100644 --- a/html5lib/tests/test_parser.py +++ b/html5lib/tests/test_parser.py @@ -8,6 +8,8 @@ warnings.simplefilter("error") +from nose.plugins.skip import SkipTest + from .support import get_data_files from .support import TestData, convert, convertExpected, treeTypes from .support import xfail @@ -30,7 +32,7 @@ def runParserTest(innerHTML, input, expected, errors, treeClass, namespaceHTMLElements, scriptingDisabled): if scriptingDisabled: # We don't support the scripting disabled case! - return + raise SkipTest() with warnings.catch_warnings(record=True) as caughtWarnings: warnings.simplefilter("always") @@ -51,7 +53,7 @@ def runParserTest(innerHTML, input, expected, errors, treeClass, if not issubclass(x.category, constants.DataLossWarning)] assert len(otherWarnings) == 0, [(x.category, x.message) for x in otherWarnings] if len(caughtWarnings): - return + raise SkipTest() output = convertTreeDump(p.tree.testSerializer(document)) diff --git a/html5lib/tests/test_treewalkers.py b/html5lib/tests/test_treewalkers.py index 34520f7a..4458ea0c 100644 --- a/html5lib/tests/test_treewalkers.py +++ b/html5lib/tests/test_treewalkers.py @@ -11,6 +11,8 @@ except AttributeError: unittest.TestCase.assertEqual = unittest.TestCase.assertEquals +from nose.plugins.skip import SkipTest + from .support import get_data_files, TestData, convertExpected, xfail from html5lib import html5parser, treewalkers, treebuilders, constants @@ -253,7 +255,7 @@ def test_all_tokens(self): def runTreewalkerTest(innerHTML, input, expected, errors, treeClass, scriptingDisabled): if scriptingDisabled: # We don't support the scripting disabled case! - return + raise SkipTest() warnings.resetwarnings() warnings.simplefilter("error") @@ -265,7 +267,7 @@ def runTreewalkerTest(innerHTML, input, expected, errors, treeClass, scriptingDi document = p.parse(input) except constants.DataLossWarning: # Ignore testcases we know we don't pass - return + raise SkipTest() document = treeClass.get("adapter", lambda x: x)(document) try: @@ -282,7 +284,7 @@ def runTreewalkerTest(innerHTML, input, expected, errors, treeClass, scriptingDi "", "Diff:", diff, ]) except NotImplementedError: - pass # Amnesty for those that confess... + raise SkipTest() # Amnesty for those that confess... @xfail From 0081e81acaa4dfb370a2dd58cbb1549dba3ea637 Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Mon, 24 Nov 2014 00:15:03 +0000 Subject: [PATCH 4/8] Add expected failures for the tokenizer (except lone surrogates!). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can't currently add the lone-surrogates tests because the expected failures file is UTF-8 and we can't have lone-surrogates there. Le sigh… --- .../tests/expected-failures/tokenizer.dat | 43 +++++++++++++++++++ html5lib/tests/test_tokenizer.py | 22 +++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 html5lib/tests/expected-failures/tokenizer.dat diff --git a/html5lib/tests/expected-failures/tokenizer.dat b/html5lib/tests/expected-failures/tokenizer.dat new file mode 100644 index 00000000..a887ec2c --- /dev/null +++ b/html5lib/tests/expected-failures/tokenizer.dat @@ -0,0 +1,43 @@ +#data + + +#data + + +#data + Date: Mon, 24 Nov 2014 00:41:02 +0000 Subject: [PATCH 5/8] sys.version_info is only a "named tuple"-like obj from 2.7 --- html5lib/tests/support.py | 2 +- html5lib/treebuilders/etree_lxml.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/html5lib/tests/support.py b/html5lib/tests/support.py index 78c5164e..116387f9 100644 --- a/html5lib/tests/support.py +++ b/html5lib/tests/support.py @@ -130,7 +130,7 @@ def convertData(data): def errorMessage(input, expected, actual): msg = ("Input:\n%s\nExpected:\n%s\nRecieved\n%s\n" % (repr(input), repr(expected), repr(actual))) - if sys.version_info.major == 2: + if sys.version_info[0] == 2: msg = msg.encode("ascii", "backslashreplace") return msg diff --git a/html5lib/treebuilders/etree_lxml.py b/html5lib/treebuilders/etree_lxml.py index 35d08efa..fed37176 100644 --- a/html5lib/treebuilders/etree_lxml.py +++ b/html5lib/treebuilders/etree_lxml.py @@ -79,7 +79,7 @@ def serializeElement(element, indent=0): next_element = next_element.getnext() elif isinstance(element, str) or isinstance(element, bytes): # Text in a fragment - assert isinstance(element, str) or sys.version_info.major == 2 + assert isinstance(element, str) or sys.version_info[0] == 2 rv.append("|%s\"%s\"" % (' ' * indent, element)) else: # Fragment case From d0f3b7b81a3a06aa7d462edb9f037fc1afd32ce7 Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Mon, 24 Nov 2014 01:47:24 +0000 Subject: [PATCH 6/8] Move where we concatenate expected tokens to handle ignoreErrorOrder Also update the expected failures now we no longer fail a test. --- html5lib/tests/expected-failures/tokenizer.dat | 3 --- html5lib/tests/test_tokenizer.py | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/html5lib/tests/expected-failures/tokenizer.dat b/html5lib/tests/expected-failures/tokenizer.dat index a887ec2c..e4fd1b03 100644 --- a/html5lib/tests/expected-failures/tokenizer.dat +++ b/html5lib/tests/expected-failures/tokenizer.dat @@ -36,8 +36,5 @@ #data Date: Mon, 24 Nov 2014 01:49:47 +0000 Subject: [PATCH 7/8] Our tokenizer currently never outputs adjacent Character tokens; expect this. --- html5lib/tests/test_tokenizer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/html5lib/tests/test_tokenizer.py b/html5lib/tests/test_tokenizer.py index e01fc9ad..9de5fb70 100644 --- a/html5lib/tests/test_tokenizer.py +++ b/html5lib/tests/test_tokenizer.py @@ -152,7 +152,6 @@ def runTokenizerTest(test): parser = TokenizerTestParser(test['initialState'], test['lastStartTag']) tokens = parser.parse(test['input']) - tokens = concatenateCharacterTokens(tokens) received = normalizeTokens(tokens) errorMsg = "\n".join(["\n\nInitial state:", test['initialState'], From 505fb526dbe35826f19cf8076c8f34042407e56e Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Sat, 29 Nov 2014 17:44:44 +0000 Subject: [PATCH 8/8] Update html5lib-tests submodule to current master. --- html5lib/tests/testdata | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html5lib/tests/testdata b/html5lib/tests/testdata index a9badff0..11aec478 160000 --- a/html5lib/tests/testdata +++ b/html5lib/tests/testdata @@ -1 +1 @@ -Subproject commit a9badff0cd2fe337170769d42ca2df5e96d30f97 +Subproject commit 11aec478545744fe89ba17bac70fbcacdd76922b pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy