def ensure_free_position(cur, node, position): """ Move siblings away to have a free slot at ``position`` in the children of ``node``. :param node: :type node: Node or int :param int position: """ try: get_node_at_position(cur, node, position) node_exists_at_position = True except ValueError: node_exists_at_position = False if node_exists_at_position: shift_positions(cur, node, position, +1)
def test_get_node_at_position_non_existing(cur, root, nd3): with pytest.raises(ValueError): get_node_at_position(cur, root, -1) with pytest.raises(ValueError): get_node_at_position(cur, str(uuid.uuid4()), 1)
def test_get_node_at_position(cur, root, nd3): node = get_node_at_position(cur, root, nd3.position) assert node.position == nd3.position
def test_get_node_at_position_non_existing(cur, root, nd3): with pytest.raises(ValueError): get_node_at_position(cur, root, -1) with pytest.raises(ValueError): get_node_at_position(cur, -1, 1)