diff options
author | Leonard Richardson <leonardr@segfault.org> | 2015-06-25 20:21:09 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2015-06-25 20:21:09 -0400 |
commit | fdc2bf6d1490d536fb583986b40a34f80ed5a0bc (patch) | |
tree | ca1a86d493158086e7a852f9e9d9d171f8b1d8a2 /bs4/tests/test_tree.py | |
parent | aab2501c3998174f0ce69d93691a5fe1d4922c02 (diff) |
Improved the exception raised when you call .unwrap() or
.replace_with() on an element that's not attached to a tree.
Diffstat (limited to 'bs4/tests/test_tree.py')
-rw-r--r-- | bs4/tests/test_tree.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index bab73c6..0bd4713 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -9,6 +9,7 @@ same markup, but all Beautiful Soup trees can be traversed with the methods tested here. """ +from pdb import set_trace import copy import pickle import re @@ -780,6 +781,14 @@ class TestTreeModification(SoupTest): new_a = a.unwrap() self.assertEqual(a, new_a) + def test_replace_with_and_unwrap_give_useful_exception_when_tag_has_no_parent(self): + soup = self.soup("<a><b>Foo</b></a><c>Bar</c>") + a = soup.a + a.extract() + self.assertEqual(None, a.parent) + self.assertRaises(ValueError, a.unwrap) + self.assertRaises(ValueError, a.replace_with, soup.c) + def test_replace_tag_with_itself(self): text = "<a><b></b><c>Foo<d></d></c></a><a><e></e></a>" soup = self.soup(text) |