Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/dendropy/datamodel/treemodel/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,11 +979,6 @@ def _set_edge(self, new_edge):
# raise ValueError("A Node cannot have 'None' for an edge")
if new_edge is self._edge:
return
if self._parent_node is not None:
try:
self._parent_node._child_nodes.remove(self)
except ValueError:
pass

## Minimal management
self._edge = new_edge
Expand Down
19 changes: 19 additions & 0 deletions tests/unittests/test_datamodel_tree_node_fundamentals.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,25 @@ def test_edge_head_node_setting(self):
self.assertIs(node.edge, edge2)
self.assertIs(node.edge.head_node, node)

def test_edge_setting_does_not_corrupt_parent_child_bookkeeping(self):
# Reassigning a node's ``edge`` is unrelated to the node's position
# in the tree, and should not affect the parent's list of children
# or the node's own parent reference.
parent = dendropy.Node(label="parent")
child1 = dendropy.Node(label="child1")
child2 = dendropy.Node(label="child2")
parent.set_child_nodes([child1, child2])
self.assertEqual(len(parent.child_nodes()), 2)
self.assertIn(child1, parent.child_nodes())
self.assertIs(child1.parent_node, parent)

child1.edge = dendropy.Edge(length=5.0)

self.assertEqual(len(parent.child_nodes()), 2)
self.assertIn(child1, parent.child_nodes())
self.assertIs(child1.parent_node, parent)


class TestNodeDistanceFromRoot(unittest.TestCase):

def test_none_edge_length_with_parent_also_none(self):
Expand Down
Loading