From fdc2bf6d1490d536fb583986b40a34f80ed5a0bc Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 25 Jun 2015 20:21:09 -0400 Subject: Improved the exception raised when you call .unwrap() or .replace_with() on an element that's not attached to a tree. --- bs4/tests/test_tree.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'bs4/tests/test_tree.py') 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("FooBar") + 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 = "Foo" soup = self.soup(text) -- cgit v1.2.3