From dd8aa7237b88569c99e85b300b0cf537aeaebfbd Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 24 Oct 2021 13:26:39 -0400 Subject: Used a warning to formally deprecate the 'text' argument in favor of 'string'. --- bs4/tests/test_tree.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'bs4/tests/test_tree.py') diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 9d3ac4a..bfd6826 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -76,9 +76,7 @@ class TestFindAll(SoupTest): # Exact match. assert soup.find_all(string="bar") == ["bar"] - # 'text' is a deprecated alias for 'string'. - assert soup.find_all(text="bar") == ["bar"] - + # Match any of a number of strings. assert soup.find_all(string=["Foo", "bar"]) == ["Foo", "bar"] # Match a regular expression. @@ -1271,3 +1269,22 @@ class TestTreeModification(SoupTest): soup.a.string = cdata assert isinstance(soup.a.string, CData) + +class TestDeprecatedArguments(SoupTest): + + def test_find_type_method_string(self): + soup = self.soup("somemarkup") + with warnings.catch_warnings(record=True) as w: + [result] = soup.find_all(text='markup') + assert result == 'markup' + assert result.parent.name == 'b' + msg = str(w[0].message) + assert msg == "The 'text' argument to find()-type methods is deprecated. Use 'string' instead." + + def test_soupstrainer_constructor_string(self): + with warnings.catch_warnings(record=True) as w: + strainer = SoupStrainer(text="text") + assert strainer.text == 'text' + msg = str(w[0].message) + assert msg == "The 'text' argument to the SoupStrainer constructor is deprecated. Use 'string' instead." + -- cgit v1.2.3