summaryrefslogtreecommitdiff
path: root/bs4/tests/test_soup.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2019-08-22 08:27:17 -0400
committerLeonard Richardson <leonardr@segfault.org>2019-08-22 08:27:17 -0400
commitbf941577b7b78ddcc7a62c5947966519f637d8b4 (patch)
treec8d466cf3943cc715f9e9cbd7897126127e760a8 /bs4/tests/test_soup.py
parent694a432f6ed1a62de742c7dfda0ed39ca4f2bb63 (diff)
Test the ability to build a tree using objects other than Tag and NavigableString.
Diffstat (limited to 'bs4/tests/test_soup.py')
-rw-r--r--bs4/tests/test_soup.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py
index dc85bb6..07f29c4 100644
--- a/bs4/tests/test_soup.py
+++ b/bs4/tests/test_soup.py
@@ -16,6 +16,8 @@ from bs4.element import (
ContentMetaAttributeValue,
SoupStrainer,
NamespacedAttribute,
+ Tag,
+ NavigableString,
)
import bs4.dammit
from bs4.dammit import (
@@ -120,6 +122,27 @@ class TestConstructor(SoupTest):
self.assertEqual(["an", "id"], a['id'])
self.assertEqual(" a class ", a['class'])
+ def test_replacement_classes(self):
+ # Test the ability to pass in replacements for the Tag and
+ # NavigableString class, which will be used when building
+ # the tree.
+ class TagPlus(Tag):
+ pass
+
+ class StringPlus(NavigableString):
+ pass
+
+ soup = self.soup(
+ "<a><b>foo</b>bar</a>",
+ tag_class=TagPlus, string_class=StringPlus
+ )
+
+ # The tree was built with TagPlus and StringPlus objects,
+ # rather than Tag and String objects.
+ assert all(
+ isinstance(x, (TagPlus, StringPlus))
+ for x in soup.recursiveChildGenerator()
+ )
class TestWarnings(SoupTest):