summaryrefslogtreecommitdiff
path: root/src/lxml/tests/test_etree.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2014-08-28 14:19:25 +0200
committerStefan Behnel <stefan_ml@behnel.de>2014-08-28 14:19:25 +0200
commit11589fcf5b28101ec7b8de286ad0133a4894f83c (patch)
tree5b337001a289ac7da00e633cba94521d76a04d3b /src/lxml/tests/test_etree.py
parentd4f06ac0703961cc4a88504369aff5a5465b7561 (diff)
downloadpython-lxml-11589fcf5b28101ec7b8de286ad0133a4894f83c.tar.gz
fix crash when deallocating sibling Element proxies that do not have a parent
Diffstat (limited to 'src/lxml/tests/test_etree.py')
-rw-r--r--src/lxml/tests/test_etree.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lxml/tests/test_etree.py b/src/lxml/tests/test_etree.py
index 41d6571f..132e2ce9 100644
--- a/src/lxml/tests/test_etree.py
+++ b/src/lxml/tests/test_etree.py
@@ -3557,6 +3557,37 @@ class ETreeOnlyTestCase(HelperTestCase):
gc.collect()
# not really testing anything here, but it shouldn't crash
+ def test_proxy_collect_siblings(self):
+ root = etree.Element('parent')
+ c1 = etree.SubElement(root, 'child1')
+ c2 = etree.SubElement(root, 'child2')
+
+ root.remove(c1)
+ root.remove(c2)
+ c1.addnext(c2)
+ del c1
+ # trigger deallocation attempt of c1
+ c2.getprevious()
+ # make sure it wasn't deallocated
+ self.assertEqual('child1', c2.getprevious().tag)
+
+ def test_proxy_collect_siblings_text(self):
+ root = etree.Element('parent')
+ c1 = etree.SubElement(root, 'child1')
+ c2 = etree.SubElement(root, 'child2')
+
+ root.remove(c1)
+ root.remove(c2)
+ c1.addnext(c2)
+ c1.tail = 'abc'
+ c2.tail = 'xyz'
+ del c1
+ # trigger deallocation attempt of c1
+ c2.getprevious()
+ # make sure it wasn't deallocated
+ self.assertEqual('child1', c2.getprevious().tag)
+ self.assertEqual('abc', c2.getprevious().tail)
+
# helper methods
def _writeElement(self, element, encoding='us-ascii', compression=0):