python3-soupsieve: fix tests with Python 3.10.20

The latest Python upgrade in oe-core has broken some
ptests. This backported patch fixes them, they should work
with both the latest and previous versions.

Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
This commit is contained in:
Gyorgy Sarvari
2026-05-04 15:59:37 +02:00
parent 1da9d7f2f9
commit ce8539c941
2 changed files with 194 additions and 4 deletions
@@ -0,0 +1,190 @@
From b799b964ef020f18daab3d0b7193b217e7412050 Mon Sep 17 00:00:00 2001
From: Isaac Muse <faceless.shop@gmail.com>
Date: Wed, 17 Dec 2025 19:33:55 -0700
Subject: [PATCH] Adjustments for changes in HTML parser (#285)
Fixes #284
Fixes running with python 3.10.20
Upstream-Status: Backport [https://github.com/facelessuser/soupsieve/commit/046ce54956a0c30120038561e53b40994d29de2c]
Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
---
soupsieve/css_match.py | 2 +-
tests/test_extra/test_soup_contains.py | 4 +++-
tests/test_level2/test_lang.py | 4 +++-
tests/test_level3/test_root.py | 11 ++++++++---
tests/test_level4/test_default.py | 4 +++-
tests/test_level4/test_dir.py | 4 +++-
tests/test_level4/test_indeterminate.py | 5 ++++-
7 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/soupsieve/css_match.py b/soupsieve/css_match.py
index 79bb870..c168436 100644
--- a/soupsieve/css_match.py
+++ b/soupsieve/css_match.py
@@ -1185,7 +1185,7 @@ class CSSMatch(_DocumentNav):
# Use cached meta language.
if not found_lang and self.cached_meta_lang:
for cache in self.cached_meta_lang:
- if root is cache[0]:
+ if root is not None and cast(str, root) is cache[0]:
found_lang = cache[1]
# If we couldn't find a language, and the document is HTML, look to meta to determine language.
diff --git a/tests/test_extra/test_soup_contains.py b/tests/test_extra/test_soup_contains.py
index 66240db..fdd8027 100644
--- a/tests/test_extra/test_soup_contains.py
+++ b/tests/test_extra/test_soup_contains.py
@@ -2,7 +2,9 @@
from .. import util
import warnings
import soupsieve as sv
+from bs4 import BeautifulSoup
+IFRAME_TEXT = BeautifulSoup('<iframe><div></div></iframe>', 'html.parser').iframe.text == '<div></div>'
class TestSoupContains(util.TestCase):
"""Test soup-contains selectors."""
@@ -250,7 +252,7 @@ class TestSoupContains(util.TestCase):
self.assert_selector(
markup,
'span:-soup-contains("iframe")',
- ['2'],
+ [] if IFRAME_TEXT else ['2'],
flags=util.PYHTML
)
diff --git a/tests/test_level2/test_lang.py b/tests/test_level2/test_lang.py
index 83b9ee4..082921c 100644
--- a/tests/test_level2/test_lang.py
+++ b/tests/test_level2/test_lang.py
@@ -1,6 +1,8 @@
"""Test language selector."""
from .. import util
+from bs4 import BeautifulSoup
+IFRAME_TEXT = BeautifulSoup('<iframe><div></div></iframe>', 'html.parser').iframe.text == '<div></div>'
class TestLang(util.TestCase):
"""Test language selector."""
@@ -58,7 +60,7 @@ class TestLang(util.TestCase):
self.assert_selector(
markup,
"p:lang(en)",
- ['3'],
+ [] if IFRAME_TEXT else ['3'],
flags=util.PYHTML
)
diff --git a/tests/test_level3/test_root.py b/tests/test_level3/test_root.py
index 60f7e75..3c6843c 100644
--- a/tests/test_level3/test_root.py
+++ b/tests/test_level3/test_root.py
@@ -1,6 +1,10 @@
"""Test root selectors."""
from .. import util
import soupsieve as sv
+from bs4 import BeautifulSoup
+import pytest
+
+IFRAME_TEXT = BeautifulSoup('<iframe><div></div></iframe>', 'html.parser').iframe.text == '<div></div>'
class TestRoot(util.TestCase):
@@ -65,7 +69,7 @@ class TestRoot(util.TestCase):
self.assert_selector(
self.MARKUP_IFRAME,
":root",
- ["root", "root2"],
+ ["root"] if IFRAME_TEXT else ["root", "root2"],
flags=util.PYHTML
)
@@ -85,17 +89,18 @@ class TestRoot(util.TestCase):
self.assert_selector(
self.MARKUP_IFRAME,
":root div",
- ["div", "div2", "other-div"],
+ ["div", "other-div"] if IFRAME_TEXT else ["div", "div2", "other-div"],
flags=util.PYHTML
)
self.assert_selector(
self.MARKUP_IFRAME,
":root > body > div",
- ["div", "div2", "other-div"],
+ ["div", "other-div"] if IFRAME_TEXT else ["div", "div2", "other-div"],
flags=util.PYHTML
)
+ @pytest.mark.skipif(IFRAME_TEXT, reason="Requires old Python HTML handling")
def test_iframe(self):
"""
Test that we only count `iframe` as root since the scoped element is the root.
diff --git a/tests/test_level4/test_default.py b/tests/test_level4/test_default.py
index 852948d..dd7b53a 100644
--- a/tests/test_level4/test_default.py
+++ b/tests/test_level4/test_default.py
@@ -1,6 +1,8 @@
"""Test default selectors."""
from .. import util
+from bs4 import BeautifulSoup
+IFRAME_TEXT = BeautifulSoup('<iframe><div></div></iframe>', 'html.parser').iframe.text == '<div></div>'
class TestDefault(util.TestCase):
"""Test default selectors."""
@@ -113,7 +115,7 @@ class TestDefault(util.TestCase):
self.assert_selector(
markup,
":default",
- ['d1', 'd3', 'd4'],
+ ['d1', 'd3'] if IFRAME_TEXT else ['d1', 'd3', 'd4'],
flags=util.PYHTML
)
diff --git a/tests/test_level4/test_dir.py b/tests/test_level4/test_dir.py
index e427715..e1a68f2 100644
--- a/tests/test_level4/test_dir.py
+++ b/tests/test_level4/test_dir.py
@@ -2,7 +2,9 @@
"""Test direction selectors."""
from .. import util
import soupsieve as sv
+from bs4 import BeautifulSoup
+IFRAME_TEXT = BeautifulSoup('<iframe><div></div></iframe>', 'html.parser').iframe.text == '<div></div>'
class TestDir(util.TestCase):
"""Test direction selectors."""
@@ -170,7 +172,7 @@ class TestDir(util.TestCase):
self.assert_selector(
markup,
"div:dir(rtl)",
- ['2'],
+ [] if IFRAME_TEXT else ['2'],
flags=util.PYHTML
)
diff --git a/tests/test_level4/test_indeterminate.py b/tests/test_level4/test_indeterminate.py
index 8e949ff..6867dae 100644
--- a/tests/test_level4/test_indeterminate.py
+++ b/tests/test_level4/test_indeterminate.py
@@ -1,5 +1,8 @@
"""Test indeterminate selectors."""
from .. import util
+from bs4 import BeautifulSoup
+
+IFRAME_TEXT = BeautifulSoup('<iframe><div></div></iframe>', 'html.parser').iframe.text == '<div></div>'
class TestIndeterminate(util.TestCase):
@@ -68,6 +71,6 @@ class TestIndeterminate(util.TestCase):
self.assert_selector(
markup,
":indeterminate",
- ['radio1', 'radio3'],
+ ['radio1'] if IFRAME_TEXT else ['radio1', 'radio3'],
flags=util.PYHTML
)
@@ -8,10 +8,10 @@ SRC_URI[sha256sum] = "b8d49b1cd4f037c7082a9683dfa1801aa2597fb11c3a1155b7a5b94829
inherit pypi python_setuptools_build_meta ptest inherit pypi python_setuptools_build_meta ptest
SRC_URI += " \ SRC_URI += "file://run-ptest \
file://run-ptest \ file://update_tests_for_latest_libxml.patch \
file://update_tests_for_latest_libxml.patch \ file://0001-Adjustments-for-changes-in-HTML-parser-285.patch \
" "
RDEPENDS:${PN}-ptest += " \ RDEPENDS:${PN}-ptest += " \
${PYTHON_PN}-pytest \ ${PYTHON_PN}-pytest \