Skip to content

Commit 4347922

Browse files
author
Huzaifa Iftikhar
committed
skip the c1 tests on old libxml2 instead of asserting the old behaviour
1 parent 81920e1 commit 4347922

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎tests/test_selector.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525

2626

2727
# libxml2 sends numeric references in the c1 range through the cp1252 table from 2.14 on,
28-
# where its html tokenizer became html5 conforming. older builds keep the raw character, and
29-
# some wheels still ship one, so the tests below pin whichever applies.
30-
C1_REFERENCES_REMAPPED = etree.LIBXML_VERSION >= (2, 14)
28+
# where its html tokenizer became html5 conforming. older builds keep the raw character and
29+
# some wheels still ship one, so the tests that need the mapping do not run there.
30+
needs_c1_remapping = pytest.mark.skipif(
31+
etree.LIBXML_VERSION < (2, 14),
32+
reason=f"libxml2 {etree.LIBXML_VERSION} does not map c1 character references, needs 2.14",
33+
)
3134

3235

3336
class TestSelector:
@@ -858,29 +861,26 @@ def test_xml_entity_expansion(self) -> None:
858861

859862
assert sel.extract() == "<foo>&xxe;</foo>"
860863

864+
@needs_c1_remapping
861865
def test_html_c1_character_references(self) -> None:
862866
"""HTML maps numeric references in the C1 range through the CP1252 table.
863867
864868
``&#133;`` is an ellipsis rather than U+0085, which is what browsers show
865869
and what the HTML standard requires. ``html.unescape`` implements the same
866870
table, so it is used as the reference. See #76.
867-
868-
On a libxml2 older than 2.14 the reference comes back as the raw character
869-
instead, which is the behaviour the report describes.
870871
"""
871872
for code_point in range(0x80, 0xA0):
872873
reference = f"&#{code_point};"
873-
if C1_REFERENCES_REMAPPED:
874-
expected = html.unescape(reference)
875-
else:
876-
expected = chr(code_point)
874+
expected = html.unescape(reference)
877875
sel = self.sscls(text=f"<p>{reference}</p>")
878876
assert sel.css("p::text").get() == expected, reference
879877
assert sel.xpath("//p/text()").get() == expected, reference
880878

881-
def test_html_c1_character_references_hex_and_named(self) -> None:
882-
expected = "\u2026" if C1_REFERENCES_REMAPPED else "\x85"
883-
assert self.sscls(text="<p>&#x85;</p>").css("p::text").get() == expected
879+
@needs_c1_remapping
880+
def test_html_c1_character_reference_hex(self) -> None:
881+
assert self.sscls(text="<p>&#x85;</p>").css("p::text").get() == "\u2026"
882+
883+
def test_html_named_character_reference(self) -> None:
884884
# a named reference does not go through the c1 table, so it is the same everywhere
885885
assert self.sscls(text="<p>&hellip;</p>").css("p::text").get() == "\u2026"
886886

0 commit comments

Comments
 (0)