[Python-checkins] r54723 - in sandbox/trunk/2to3: pytree.py tests/test_pytree.py
collin.winter
python-checkins at python.org
Mon Apr 9 06:43:59 CEST 2007
Author: collin.winter
Date: Mon Apr 9 06:43:55 2007
New Revision: 54723
Modified:
sandbox/trunk/2to3/pytree.py
sandbox/trunk/2to3/tests/test_pytree.py
Log:
Make pytree.Base.remove() return the old node index.
Modified: sandbox/trunk/2to3/pytree.py
==============================================================================
--- sandbox/trunk/2to3/pytree.py (original)
+++ sandbox/trunk/2to3/pytree.py Mon Apr 9 06:43:55 2007
@@ -133,16 +133,15 @@
self.was_changed = True
def remove(self):
- """Remove the node from the tree."""
+ """Remove the node from the tree. Returns the position of the node
+ in its parent's children before it was removed."""
if self.parent:
- children = list(self.parent.children)
for i, node in enumerate(self.parent.children):
if node is self:
self.parent.changed()
- del children[i]
- self.parent.children = tuple(children)
+ del self.parent.children[i]
self.parent = None
- break
+ return i
class Node(Base):
Modified: sandbox/trunk/2to3/tests/test_pytree.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_pytree.py (original)
+++ sandbox/trunk/2to3/tests/test_pytree.py Mon Apr 9 06:43:55 2007
@@ -180,18 +180,20 @@
def testRemove(self):
l1 = pytree.Leaf(100, "foo")
- n1 = pytree.Node(1000, [l1])
+ l2 = pytree.Leaf(100, "foo")
+ n1 = pytree.Node(1000, [l1, l2])
n2 = pytree.Node(1000, [n1])
-
- n1.remove()
- self.failIf(n2 in n2.children)
+
+ self.assertEqual(n1.remove(), 0)
+ self.failIf(n1 in n2.children)
self.assertEqual(l1.parent, n1)
self.assertEqual(n1.parent, None)
self.assertEqual(n2.parent, None)
self.failIf(n1.was_changed)
self.failUnless(n2.was_changed)
-
- l1.remove()
+
+ self.assertEqual(l2.remove(), 1)
+ self.assertEqual(l1.remove(), 0)
self.failIf(l1 in n1.children)
self.assertEqual(l1.parent, None)
self.assertEqual(n1.parent, None)
More information about the Python-checkins
mailing list