diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-04-26 10:45:59 -0400 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-04-26 10:45:59 -0400 |
commit | c244fa5be5185a23addb98da68f937fd4be6f582 (patch) | |
tree | d737ac07e3688400e1ade452f6b6bee08a262f0d /bs4/tests/test_tree.py | |
parent | e82a52cacd936b66d9f6290136278af00ea1428c (diff) |
Upon document generation, CData objects are no longer run through the formatter. [bug=988905]
Diffstat (limited to 'bs4/tests/test_tree.py')
-rw-r--r-- | bs4/tests/test_tree.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 5acaeea..2dea886 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -995,6 +995,12 @@ class TestTreeModification(SoupTest): soup.b.string = soup.c.string self.assertEqual(soup.a.encode(), b"<a><b>bar</b><c>bar</c></a>") + def test_set_string_preserves_class_of_string(self): + soup = self.soup("<a></a>") + cdata = CData("foo") + soup.a.string = cdata + self.assertTrue(isinstance(soup.a.string, CData)) + class TestElementObjects(SoupTest): """Test various features of element objects.""" @@ -1346,6 +1352,24 @@ class TestNavigableStringSubclasses(SoupTest): 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. |