Skip to content

Commit

Permalink
Add support for the new cssselect API used in :has() (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR authored Oct 27, 2022
1 parent e6c14c7 commit 96fc3d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions parsel/csstranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def __str__(self):

return path

def join(self, combiner, other):
super().join(combiner, other)
def join(self, combiner, other, *args, **kwargs):
super().join(combiner, other, *args, **kwargs)
self.textnode = other.textnode
self.attribute = other.attribute
return self
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
install_requires=[
"cssselect>=0.9",
"lxml",
"packaging",
"w3lib>=1.19.0",
],
python_requires=">=3.7",
Expand Down
12 changes: 12 additions & 0 deletions tests/test_selector_csstranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Selector tests for cssselect backend
"""
import unittest

import cssselect
import pytest
from packaging.version import Version

from parsel.csstranslator import GenericTranslator, HTMLTranslator
from parsel import Selector
from cssselect.parser import SelectorSyntaxError
Expand Down Expand Up @@ -196,3 +201,10 @@ def test_nested_selector(self):
self.sel.css("div").css("area:last-child").extract(),
['<area shape="default" id="area-nohref">'],
)

@pytest.mark.xfail(
Version(cssselect.__version__) < Version("1.2.0"),
reason="Support added in cssselect 1.2.0",
)
def test_pseudoclass_has(self):
self.assertEqual(self.x("p:has(b)::text"), ["lorem ipsum text"])

0 comments on commit 96fc3d7

Please sign in to comment.