diff options
author | Leonard Richardson <leonardr@segfault.org> | 2021-10-24 13:26:39 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2021-10-24 13:26:39 -0400 |
commit | dd8aa7237b88569c99e85b300b0cf537aeaebfbd (patch) | |
tree | a6923b9558dab70df4de12ccbef0e0612ad909a6 /bs4/tests | |
parent | f7ec284182f3e78974fcdc7b62c88a5c3a6dbbbd (diff) |
Used a warning to formally deprecate the 'text' argument in favor of 'string'.
Diffstat (limited to 'bs4/tests')
-rw-r--r-- | bs4/tests/__init__.py | 6 | ||||
-rw-r--r-- | bs4/tests/test_navigablestring.py | 4 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 23 |
3 files changed, 25 insertions, 8 deletions
diff --git a/bs4/tests/__init__.py b/bs4/tests/__init__.py index 5147f0e..224c9d8 100644 --- a/bs4/tests/__init__.py +++ b/bs4/tests/__init__.py @@ -510,13 +510,13 @@ Hello, world! self.assert_soup(markup) soup = self.soup(markup) - comment = soup.find(text="foobar") + comment = soup.find(string="foobar") assert comment.__class__ == Comment # The comment is properly integrated into the tree. - foo = soup.find(text="foo") + foo = soup.find(string="foo") assert comment == foo.next_element - baz = soup.find(text="baz") + baz = soup.find(string="baz") assert comment == baz.previous_element def test_preserved_whitespace_in_pre_and_textarea(self): diff --git a/bs4/tests/test_navigablestring.py b/bs4/tests/test_navigablestring.py index 649acc0..e4c179e 100644 --- a/bs4/tests/test_navigablestring.py +++ b/bs4/tests/test_navigablestring.py @@ -64,7 +64,7 @@ class TestNavigableStringSubclasses(SoupTest): cdata = CData("foo") soup.insert(1, cdata) assert str(soup) == "<![CDATA[foo]]>" - assert soup.find(text="foo") == "foo" + assert soup.find(string="foo") == "foo" assert soup.contents[0] == "foo" def test_cdata_is_never_formatted(self): @@ -103,7 +103,7 @@ class TestNavigableStringSubclasses(SoupTest): "<div>text</div><script>text</script><style>text</style>" ) assert [NavigableString, Script, Stylesheet] == [ - x.__class__ for x in soup.find_all(text=True) + x.__class__ for x in soup.find_all(string=True) ] # The TemplateString is a little unusual because it's generally found 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("<a>some</a><b>markup</b>") + 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." + |