summaryrefslogtreecommitdiff
path: root/bs4/tests/test_soup.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2019-08-26 18:36:43 -0400
committerLeonard Richardson <leonardr@segfault.org>2019-08-26 18:36:43 -0400
commitcf028c24cfa8b8b4787aea50ad73cc8b18f15770 (patch)
tree6183099fe99471e1e0bf866f479f9732e3b1bf27 /bs4/tests/test_soup.py
parent344ee4494196eb41ee049761193cdad529ee59de (diff)
It's now possible to override any of the element classes.
Diffstat (limited to 'bs4/tests/test_soup.py')
-rw-r--r--bs4/tests/test_soup.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py
index 07f29c4..af5f791 100644
--- a/bs4/tests/test_soup.py
+++ b/bs4/tests/test_soup.py
@@ -13,6 +13,7 @@ from bs4 import (
)
from bs4.element import (
CharsetMetaAttributeValue,
+ Comment,
ContentMetaAttributeValue,
SoupStrainer,
NamespacedAttribute,
@@ -123,24 +124,30 @@ class TestConstructor(SoupTest):
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.
+ # Test the ability to pass in replacements for element classes
+ # which will be used when building the tree.
class TagPlus(Tag):
pass
class StringPlus(NavigableString):
pass
+ class CommentPlus(Comment):
+ pass
+
soup = self.soup(
- "<a><b>foo</b>bar</a>",
- tag_class=TagPlus, string_class=StringPlus
+ "<a><b>foo</b>bar</a><!--whee-->",
+ element_classes = {
+ Tag: TagPlus,
+ NavigableString: StringPlus,
+ Comment: CommentPlus,
+ }
)
- # The tree was built with TagPlus and StringPlus objects,
- # rather than Tag and String objects.
+ # The tree was built with TagPlus, StringPlus, and CommentPlus objects,
+ # rather than Tag, String, and Comment objects.
assert all(
- isinstance(x, (TagPlus, StringPlus))
+ isinstance(x, (TagPlus, StringPlus, CommentPlus))
for x in soup.recursiveChildGenerator()
)