summaryrefslogtreecommitdiff
path: root/bs4/tests/test_css.py
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/tests/test_css.py')
-rw-r--r--bs4/tests/test_css.py29
1 files changed, 12 insertions, 17 deletions
diff --git a/bs4/tests/test_css.py b/bs4/tests/test_css.py
index cf73831..c9ade48 100644
--- a/bs4/tests/test_css.py
+++ b/bs4/tests/test_css.py
@@ -15,6 +15,7 @@ from . import (
if SOUP_SIEVE_PRESENT:
from soupsieve import SelectorSyntaxError
+ from soupsieve import compile as sv_compile
@pytest.mark.skipif(not SOUP_SIEVE_PRESENT, reason="Soup Sieve not installed")
@@ -94,6 +95,17 @@ class TestCSSSelectors(SoupTest):
for selector, expected_ids in tests:
self.assert_selects(selector, expected_ids)
+ def test_precompiled(self):
+ sel = sv_compile('div')
+
+ els = self.soup.select(sel)
+ assert len(els) == 4
+ for div in els:
+ assert div.name == 'div'
+
+ el = self.soup.select_one(sel)
+ assert 'main' == el['id']
+
def test_one_tag_one(self):
els = self.soup.select('title')
assert len(els) == 1
@@ -474,20 +486,3 @@ class TestCSSSelectors(SoupTest):
assert m(".foo#bar") == '\\.foo\\#bar'
assert m("()[]{}") == '\\(\\)\\[\\]\\{\\}'
assert m(".foo") == self.soup.css.escape(".foo")
-
- def test_api_replacement(self):
- # You can pass in another object to act as a drop-in
- # replacement for the soupsieve module.
- class Mock():
- attribute = "value"
- pass
- mock_soupsieve = Mock()
- mock_soupsieve.escape = MagicMock()
-
- # If an unknown method turns out to be present in Soup Sieve,
- # we may still be able to call it.
- css = CSS(self.soup, api=mock_soupsieve)
- css.escape("identifier")
- mock_soupsieve.escape.assert_called_with(
- "selector", self.soup, 1, flags=0
- )