Blame SOURCES/506.patch

ed2d53
From e6bd99e8f2497194ffd0a06c6954ebb28d7526bb Mon Sep 17 00:00:00 2001
ed2d53
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
ed2d53
Date: Sat, 8 Aug 2020 13:39:22 +0200
ed2d53
Subject: [PATCH] Use Node.from_parent() constructor to support pytest 6
ed2d53
ed2d53
Add a wrapper not to break pytest 4 (needed for Python 2 support).
ed2d53
ed2d53
    ============================= test session starts ==============================
ed2d53
    platform linux -- Python 3.9.0b5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
ed2d53
    rootdir: /builddir/build/BUILD/html5lib-1.1, configfile: pytest.ini
ed2d53
    plugins: expect-1.1.0
ed2d53
    collected 0 items / 1 error
ed2d53
ed2d53
    ==================================== ERRORS ====================================
ed2d53
    ________________________ ERROR collecting test session _________________________
ed2d53
    /usr/lib/python3.9/site-packages/pluggy/hooks.py:286: in __call__
ed2d53
        return self._hookexec(self, self.get_hookimpls(), kwargs)
ed2d53
    /usr/lib/python3.9/site-packages/pluggy/manager.py:93: in _hookexec
ed2d53
        return self._inner_hookexec(hook, methods, kwargs)
ed2d53
    /usr/lib/python3.9/site-packages/pluggy/manager.py:84: in <lambda>
ed2d53
        self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
ed2d53
    html5lib/tests/conftest.py:105: in pytest_collect_file
ed2d53
        return TokenizerFile(path, parent)
ed2d53
    /usr/lib/python3.9/site-packages/_pytest/nodes.py:95: in __call__
ed2d53
        warnings.warn(NODE_USE_FROM_PARENT.format(name=self.__name__), stacklevel=2)
ed2d53
    E   pytest.PytestDeprecationWarning: Direct construction of TokenizerFile has been deprecated, please use TokenizerFile.from_parent.
ed2d53
    E   See https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent for more details.
ed2d53
ed2d53
Fixes https://github.com/html5lib/html5lib-python/issues/505
ed2d53
---
ed2d53
 html5lib/tests/conftest.py          | 15 ++++++++++++---
ed2d53
 html5lib/tests/sanitizer.py         |  2 +-
ed2d53
 html5lib/tests/tokenizer.py         | 10 +++++-----
ed2d53
 html5lib/tests/tree_construction.py | 20 ++++++++++----------
ed2d53
 requirements-test.txt               |  2 +-
ed2d53
 5 files changed, 29 insertions(+), 20 deletions(-)
ed2d53
ed2d53
diff --git a/html5lib/tests/conftest.py b/html5lib/tests/conftest.py
ed2d53
index dad167c5..fffeb50c 100644
ed2d53
--- a/html5lib/tests/conftest.py
ed2d53
+++ b/html5lib/tests/conftest.py
ed2d53
@@ -99,10 +99,19 @@ def pytest_collect_file(path, parent):
ed2d53
 
ed2d53
     if _tree_construction in dir_and_parents:
ed2d53
         if path.ext == ".dat":
ed2d53
-            return TreeConstructionFile(path, parent)
ed2d53
+            return TreeConstructionFile.from_parent(parent, fspath=path)
ed2d53
     elif _tokenizer in dir_and_parents:
ed2d53
         if path.ext == ".test":
ed2d53
-            return TokenizerFile(path, parent)
ed2d53
+            return TokenizerFile.from_parent(parent, fspath=path)
ed2d53
     elif _sanitizer_testdata in dir_and_parents:
ed2d53
         if path.ext == ".dat":
ed2d53
-            return SanitizerFile(path, parent)
ed2d53
+            return SanitizerFile.from_parent(parent, fspath=path)
ed2d53
+
ed2d53
+
ed2d53
+# Tiny wrapper to allow .from_parent constructors on older pytest for PY27
ed2d53
+if not hasattr(pytest.Item.__base__, "from_parent"):
ed2d53
+    @classmethod
ed2d53
+    def from_parent(cls, parent, **kwargs):
ed2d53
+        return cls(parent=parent, **kwargs)
ed2d53
+
ed2d53
+    pytest.Item.__base__.from_parent = from_parent
ed2d53
diff --git a/html5lib/tests/sanitizer.py b/html5lib/tests/sanitizer.py
ed2d53
index bb483421..16e53868 100644
ed2d53
--- a/html5lib/tests/sanitizer.py
ed2d53
+++ b/html5lib/tests/sanitizer.py
ed2d53
@@ -13,7 +13,7 @@ def collect(self):
ed2d53
         with codecs.open(str(self.fspath), "r", encoding="utf-8") as fp:
ed2d53
             tests = json.load(fp)
ed2d53
         for i, test in enumerate(tests):
ed2d53
-            yield SanitizerTest(str(i), self, test=test)
ed2d53
+            yield SanitizerTest.from_parent(self, name=str(i), test=test)
ed2d53
 
ed2d53
 
ed2d53
 class SanitizerTest(pytest.Item):
ed2d53
diff --git a/html5lib/tests/tokenizer.py b/html5lib/tests/tokenizer.py
ed2d53
index 47264cc3..cc9897a4 100644
ed2d53
--- a/html5lib/tests/tokenizer.py
ed2d53
+++ b/html5lib/tests/tokenizer.py
ed2d53
@@ -192,7 +192,7 @@ def collect(self):
ed2d53
             tests = json.load(fp)
ed2d53
         if 'tests' in tests:
ed2d53
             for i, test in enumerate(tests['tests']):
ed2d53
-                yield TokenizerTestCollector(str(i), self, testdata=test)
ed2d53
+                yield TokenizerTestCollector.from_parent(self, name=str(i), testdata=test)
ed2d53
 
ed2d53
 
ed2d53
 class TokenizerTestCollector(pytest.Collector):
ed2d53
@@ -207,10 +207,10 @@ def __init__(self, name, parent=None, config=None, session=None, testdata=None):
ed2d53
     def collect(self):
ed2d53
         for initialState in self.testdata["initialStates"]:
ed2d53
             initialState = capitalize(initialState)
ed2d53
-            item = TokenizerTest(initialState,
ed2d53
-                                 self,
ed2d53
-                                 self.testdata,
ed2d53
-                                 initialState)
ed2d53
+            item = TokenizerTest.from_parent(self,
ed2d53
+                                             name=initialState,
ed2d53
+                                             test=self.testdata,
ed2d53
+                                             initialState=initialState)
ed2d53
             if self.testdata["input"] is None:
ed2d53
                 item.add_marker(pytest.mark.skipif(True, reason="Relies on lone surrogates"))
ed2d53
             yield item
ed2d53
diff --git a/html5lib/tests/tree_construction.py b/html5lib/tests/tree_construction.py
ed2d53
index 1ef6e725..fb0657bf 100644
ed2d53
--- a/html5lib/tests/tree_construction.py
ed2d53
+++ b/html5lib/tests/tree_construction.py
ed2d53
@@ -26,7 +26,7 @@ class TreeConstructionFile(pytest.File):
ed2d53
     def collect(self):
ed2d53
         tests = TestData(str(self.fspath), "data")
ed2d53
         for i, test in enumerate(tests):
ed2d53
-            yield TreeConstructionTest(str(i), self, testdata=test)
ed2d53
+            yield TreeConstructionTest.from_parent(self, name=str(i), testdata=test)
ed2d53
 
ed2d53
 
ed2d53
 class TreeConstructionTest(pytest.Collector):
ed2d53
@@ -48,11 +48,11 @@ def _getParserTests(self, treeName, treeAPIs):
ed2d53
                 nodeid = "%s::parser::namespaced" % treeName
ed2d53
             else:
ed2d53
                 nodeid = "%s::parser::void-namespace" % treeName
ed2d53
-            item = ParserTest(nodeid,
ed2d53
-                              self,
ed2d53
-                              self.testdata,
ed2d53
-                              treeAPIs["builder"] if treeAPIs is not None else None,
ed2d53
-                              namespaceHTMLElements)
ed2d53
+            item = ParserTest.from_parent(self,
ed2d53
+                                          name=nodeid,
ed2d53
+                                          test=self.testdata,
ed2d53
+                                          treeClass=treeAPIs["builder"] if treeAPIs is not None else None,
ed2d53
+                                          namespaceHTMLElements=namespaceHTMLElements)
ed2d53
             item.add_marker(getattr(pytest.mark, treeName))
ed2d53
             item.add_marker(pytest.mark.parser)
ed2d53
             if namespaceHTMLElements:
ed2d53
@@ -61,10 +61,10 @@ def _getParserTests(self, treeName, treeAPIs):
ed2d53
 
ed2d53
     def _getTreeWalkerTests(self, treeName, treeAPIs):
ed2d53
         nodeid = "%s::treewalker" % treeName
ed2d53
-        item = TreeWalkerTest(nodeid,
ed2d53
-                              self,
ed2d53
-                              self.testdata,
ed2d53
-                              treeAPIs)
ed2d53
+        item = TreeWalkerTest.from_parent(self,
ed2d53
+                                          name=nodeid,
ed2d53
+                                          test=self.testdata,
ed2d53
+                                          treeAPIs=treeAPIs)
ed2d53
         item.add_marker(getattr(pytest.mark, treeName))
ed2d53
         item.add_marker(pytest.mark.treewalker)
ed2d53
         yield item
ed2d53
diff --git a/requirements-test.txt b/requirements-test.txt
ed2d53
index 703d0e69..57f8f617 100644
ed2d53
--- a/requirements-test.txt
ed2d53
+++ b/requirements-test.txt
ed2d53
@@ -3,7 +3,7 @@
ed2d53
 tox>=3.15.1,<4
ed2d53
 flake8>=3.8.1,<3.9
ed2d53
 pytest>=4.6.10,<5 ; python_version < '3'
ed2d53
-pytest>=5.4.2,<6 ; python_version >= '3'
ed2d53
+pytest>=5.4.2,<7 ; python_version >= '3'
ed2d53
 coverage>=5.1,<6
ed2d53
 pytest-expect>=1.1.0,<2
ed2d53
 mock>=3.0.5,<4 ; python_version < '3.6'