summaryrefslogtreecommitdiff
path: root/src/lxml/tests/test_etree.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2014-08-28 15:25:17 +0200
committerStefan Behnel <stefan_ml@behnel.de>2014-08-28 15:25:17 +0200
commitbeab69f059d24b7cdc03d7df4a70c551f6835192 (patch)
tree7cc5ff0bd141bbb7546d4e6fe00c1d43be4e22fa /src/lxml/tests/test_etree.py
parent11589fcf5b28101ec7b8de286ad0133a4894f83c (diff)
downloadpython-lxml-beab69f059d24b7cdc03d7df4a70c551f6835192.tar.gz
prevent tree cycle creation when adding siblings
Diffstat (limited to 'src/lxml/tests/test_etree.py')
-rw-r--r--src/lxml/tests/test_etree.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/lxml/tests/test_etree.py b/src/lxml/tests/test_etree.py
index 132e2ce9..86aa176b 100644
--- a/src/lxml/tests/test_etree.py
+++ b/src/lxml/tests/test_etree.py
@@ -1490,6 +1490,48 @@ class ETreeOnlyTestCase(HelperTestCase):
self.assertEqual(['b', 'a'],
[c.tag for c in root])
+ def test_addnext_cycle(self):
+ Element = self.etree.Element
+ SubElement = self.etree.SubElement
+ root = Element('root')
+ a = SubElement(root, 'a')
+ b = SubElement(a, 'b')
+ # appending parent as sibling is forbidden
+ self.assertRaises(ValueError, b.addnext, a)
+ self.assertEqual(['a'], [c.tag for c in root])
+ self.assertEqual(['b'], [c.tag for c in a])
+
+ def test_addprevious_cycle(self):
+ Element = self.etree.Element
+ SubElement = self.etree.SubElement
+ root = Element('root')
+ a = SubElement(root, 'a')
+ b = SubElement(a, 'b')
+ # appending parent as sibling is forbidden
+ self.assertRaises(ValueError, b.addprevious, a)
+ self.assertEqual(['a'], [c.tag for c in root])
+ self.assertEqual(['b'], [c.tag for c in a])
+
+ def test_addnext_cycle_long(self):
+ Element = self.etree.Element
+ SubElement = self.etree.SubElement
+ root = Element('root')
+ a = SubElement(root, 'a')
+ b = SubElement(a, 'b')
+ c = SubElement(b, 'c')
+ # appending parent as sibling is forbidden
+ self.assertRaises(ValueError, c.addnext, a)
+
+ def test_addprevious_cycle_long(self):
+ Element = self.etree.Element
+ SubElement = self.etree.SubElement
+ root = Element('root')
+ a = SubElement(root, 'a')
+ b = SubElement(a, 'b')
+ c = SubElement(b, 'c')
+ # appending parent as sibling is forbidden
+ self.assertRaises(ValueError, c.addprevious, a)
+
def test_addprevious_noops(self):
Element = self.etree.Element
SubElement = self.etree.SubElement