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.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/bs4/tests/test_css.py b/bs4/tests/test_css.py
index 51662ed..a6c17de 100644
--- a/bs4/tests/test_css.py
+++ b/bs4/tests/test_css.py
@@ -1,5 +1,6 @@
import pytest
import types
+from unittest.mock import MagicMock
from bs4 import (
CSS,
@@ -469,7 +470,29 @@ class TestCSSSelectors(SoupTest):
assert result['id'] == 'header3'
def test_escape(self):
- m = CSS.escape
+ m = self.soup.css.escape
assert m(".foo#bar") == '\\.foo\\#bar'
assert m("()[]{}") == '\\(\\)\\[\\]\\{\\}'
assert m(".foo") == self.soup.css.escape(".foo")
+
+ def test_fallback(self):
+ class Mock():
+ attribute = "value"
+ pass
+ mock_soupsieve = Mock()
+ mock_soupsieve.some_other_method = 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.some_other_method("selector", 1, flags=0)
+ mock_soupsieve.some_other_method.assert_called_with(
+ "selector", self.soup, 1, flags=0
+ )
+
+ # If the attribute is not callable, getattr is a passthrough.
+ assert mock_soupsieve.attribute == "value"
+
+ # If the method just isn't there, too bad.
+ with pytest.raises(AttributeError):
+ mock_soupsieve.no_such_method()