summaryrefslogtreecommitdiff
path: root/bs4/tests/test_tree.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2013-05-06 21:25:16 -0400
committerLeonard Richardson <leonardr@segfault.org>2013-05-06 21:25:16 -0400
commitc4ce22b415ab81ba0e3fb4a3fb28f4ce68dccbde (patch)
treef021dbfe567fea9cbaba09821e9311e71668d5f1 /bs4/tests/test_tree.py
parent3ad71fceec0002be87306174f0b2464cc2342a7e (diff)
Methods like get_text() and properties like .strings now only give
you strings that are visible in the document--no comments or processing commands. [bug=1050164]
Diffstat (limited to 'bs4/tests/test_tree.py')
-rw-r--r--bs4/tests/test_tree.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index a5e761f..5e4a9dd 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -20,6 +20,7 @@ from bs4.builder import (
)
from bs4.element import (
CData,
+ Comment,
Doctype,
NavigableString,
SoupStrainer,
@@ -1167,6 +1168,20 @@ class TestElementObjects(SoupTest):
self.assertEqual(soup.a.get_text(","), "a,r, , t ")
self.assertEqual(soup.a.get_text(",", strip=True), "a,r,t")
+ def test_get_text_ignores_comments(self):
+ soup = self.soup("foo<!--IGNORE-->bar")
+ self.assertEqual(soup.get_text(), "foobar")
+
+ self.assertEqual(
+ soup.get_text(types=(NavigableString, Comment)), "fooIGNOREbar")
+ self.assertEqual(
+ soup.get_text(types=None), "fooIGNOREbar")
+
+ def test_all_strings_ignores_comments(self):
+ soup = self.soup("foo<!--IGNORE-->bar")
+ self.assertEqual(['foo', 'bar'], list(soup.strings))
+
+
class TestCDAtaListAttributes(SoupTest):
"""Testing cdata-list attributes like 'class'.