Skip to content

Commit a15082d

Browse files
committed
make sure node.children are always sorted
even after calling shift_* methods
1 parent 404af3d commit a15082d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

udapi/core/node.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ def _shift_before_ord(self, reference_ord, without_children=False):
590590
all_nodes[i_ord - 1]._ord = i_ord
591591
all_nodes[reference_ord - 1] = self
592592
self._ord = reference_ord
593+
self._parent._children.sort()
593594
return
594595

595596
nodes_to_move = self.descendants(add_self=True)
@@ -615,6 +616,7 @@ def _shift_before_ord(self, reference_ord, without_children=False):
615616
for node in nodes_to_move:
616617
all_nodes[trg_ord - 1], node._ord = node, trg_ord
617618
trg_ord += 1
619+
self._parent._children.sort()
618620
return
619621

620622
# First, move a node from position src_ord to position trg_ord RIGHT-ward.
@@ -648,6 +650,7 @@ def _shift_before_ord(self, reference_ord, without_children=False):
648650
for node in nodes_to_move:
649651
all_nodes[trg_ord - 1], node._ord = node, trg_ord
650652
trg_ord += 1
653+
self._parent._children.sort()
651654

652655
def shift_after_node(self, reference_node, without_children=False, skip_if_descendant=False):
653656
"""Shift this node after the reference_node."""

udapi/core/tests/test_node.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def test_topology(self):
6161
nodes[0].shift_after_node(nodes[1])
6262
self.assertEqual([node.ord for node in nodes], [2, 1, 3, 4, 5, 6])
6363
self.assertEqual([node.ord for node in root.descendants()], [1, 2, 3, 4, 5, 6])
64+
self.assertEqual([node.ord for node in nodes[1].children], [2, 3, 4])
65+
nodes[3].shift_before_node(nodes[2])
66+
self.assertEqual([node.ord for node in nodes[1].children], [2, 3, 6])
6467

6568
def test_draw(self):
6669
"""Test the draw() method, which uses udapi.block.write.textmodetrees."""

0 commit comments

Comments
 (0)