summaryrefslogtreecommitdiff
path: root/bs4/tests/test_tree.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2021-02-14 16:53:14 -0500
committerLeonard Richardson <leonardr@segfault.org>2021-02-14 16:53:14 -0500
commit34e0ce8a9dd43ada1c55b50a156fbce63b1e2ebb (patch)
treefdeb487c1f52e32c6eb4761cd2a530a24c10b8b0 /bs4/tests/test_tree.py
parent7201eecc09b51df5a0fb704670aa66bcc9d8e635 (diff)
NavigableString and its subclasses now implement the get_text()
method, as well as the properties .strings and .stripped_strings. These methods will either return the string itself, or nothing, so the only reason to use this is when iterating over a list of mixed Tag and NavigableString objects. [bug=1904309]
Diffstat (limited to 'bs4/tests/test_tree.py')
-rw-r--r--bs4/tests/test_tree.py78
1 files changed, 0 insertions, 78 deletions
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index d1ca5ea..875befe 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -1846,84 +1846,6 @@ class TestEncoding(SoupTest):
else:
self.assertEqual(b'<b>\\u2603</b>', repr(soup))
-
-class TestNavigableStringSubclasses(SoupTest):
-
- def test_cdata(self):
- # None of the current builders turn CDATA sections into CData
- # objects, but you can create them manually.
- soup = self.soup("")
- cdata = CData("foo")
- soup.insert(1, cdata)
- self.assertEqual(str(soup), "<![CDATA[foo]]>")
- self.assertEqual(soup.find(text="foo"), "foo")
- self.assertEqual(soup.contents[0], "foo")
-
- def test_cdata_is_never_formatted(self):
- """Text inside a CData object is passed into the formatter.
-
- But the return value is ignored.
- """
-
- self.count = 0
- def increment(*args):
- self.count += 1
- return "BITTER FAILURE"
-
- soup = self.soup("")
- cdata = CData("<><><>")
- soup.insert(1, cdata)
- self.assertEqual(
- b"<![CDATA[<><><>]]>", soup.encode(formatter=increment))
- self.assertEqual(1, self.count)
-
- def test_doctype_ends_in_newline(self):
- # Unlike other NavigableString subclasses, a DOCTYPE always ends
- # in a newline.
- doctype = Doctype("foo")
- soup = self.soup("")
- soup.insert(1, doctype)
- self.assertEqual(soup.encode(), b"<!DOCTYPE foo>\n")
-
- def test_declaration(self):
- d = Declaration("foo")
- self.assertEqual("<?foo?>", d.output_ready())
-
- def test_default_string_containers(self):
- # In some cases, we use different NavigableString subclasses for
- # the same text in different tags.
- soup = self.soup(
- "<div>text</div><script>text</script><style>text</style>"
- )
- self.assertEqual(
- [NavigableString, Script, Stylesheet],
- [x.__class__ for x in soup.find_all(text=True)]
- )
-
- # The TemplateString is a little unusual because it's generally found
- # _inside_ children of a <template> element, not a direct child of the
- # <template> element.
- soup = self.soup(
- "<template>Some text<p>In a tag</p></template>Some text outside"
- )
- assert all(
- isinstance(x, TemplateString)
- for x in soup.template._all_strings(types=None)
- )
-
- # Once the <template> tag closed, we went back to using
- # NavigableString.
- outside = soup.template.next_sibling
- assert isinstance(outside, NavigableString)
- assert not isinstance(outside, TemplateString)
-
- # The TemplateString is also unusual because it can contain
- # NavigableString subclasses of _other_ types, such as
- # Comment.
- markup = b"<template>Some text<p>In a tag</p><!--with a comment--></template>"
- soup = self.soup(markup)
- self.assertEqual(markup, soup.template.encode("utf8"))
-
class TestSoupSelector(TreeTest):