<s> from libtree . core . tree import change_parent , delete_node , insert_node <EOL> from libtree . core . query import ( get_ancestor_ids , get_child_ids , get_children , <EOL> get_descendant_ids , get_node ) <EOL> from pdb import set_trace as trace <EOL> import pytest <EOL> def test_insert_root_node_with_auto_position ( cur ) : <EOL> root = insert_node ( cur , None , '<STR_LIT>' , auto_position = True ) <EOL> delete_node ( cur , root ) <EOL> def test_insert_node ( cur , root , nd1 , nd2 , nd2_1 , nd2_1_1 , nd3 ) : <EOL> assert root . parent is None <EOL> assert nd1 . parent == root . id <EOL> assert nd2 . parent == root . id <EOL> assert nd2_1 . parent == nd2 . id <EOL> assert nd2_1_1 . parent == nd2_1 . id <EOL> assert nd3 . parent == root . id <EOL> def test_insert_node_sets_properties ( root ) : <EOL> assert root . properties == { <EOL> '<STR_LIT:type>' : '<STR_LIT:root>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> def test_insert_node_sets_position ( nd1 ) : <EOL> assert nd1 . position == <NUM_LIT:4> <EOL> def test_change_parent ( cur , root , nd1 , nd2 , nd2_1 , nd2_1_1 , <EOL> nd2_leaf ) : <EOL> """<STR_LIT>""" <EOL> _temp_node = change_parent ( cur , nd2_1 . id , nd1 , auto_position = False ) <EOL> assert _temp_node . parent == nd1 . id <EOL> node = get_node ( cur , nd2_1 . id ) <EOL> assert node . parent == nd1 . id <EOL> child_node = get_node ( cur , nd2_1_1 . id ) <EOL> assert child_node . parent == nd2_1 . id <EOL> child_node = get_node ( cur , nd2_leaf . id ) <EOL> assert child_node . parent == nd2_1_1 . id <EOL> assert set ( get_ancestor_ids ( cur , nd2_1 ) ) == { root . id , nd1 . id } <EOL> expected = { root . id , nd1 . id , nd2_1 . id } <EOL> assert set ( get_ancestor_ids ( cur , nd2_1_1 ) ) == expected <EOL> expected = { root . id , nd1 . id , nd2_1 . id , nd2_1_1 . id } <EOL> assert set ( get_ancestor_ids ( cur , nd2_leaf ) ) == expected <EOL> assert set ( get_ancestor_ids ( cur , nd2 ) ) == { root . id } <EOL> expected = { nd2_1 . id , nd2_1_1 . id , nd2_leaf . id } <EOL> assert set ( get_descendant_ids ( cur , nd1 ) ) == expected <EOL> assert set ( get_descendant_ids ( cur , nd2 ) ) == set ( ) <EOL> assert len ( set ( get_children ( cur , nd1 ) ) ) == <NUM_LIT:1> <EOL> assert len ( set ( get_children ( cur , nd2 ) ) ) == <NUM_LIT:0> <EOL> def test_change_parent_dont_move_into_own_subtree ( cur , nd1 , nd2_1 ) : <EOL> with pytest . raises ( ValueError ) : <EOL> change_parent ( cur , nd1 , nd2_1 ) <EOL> def test_delete_node ( cur , nd1 , nd2_1 , nd2_1_1 , nd2_leaf ) : <EOL> """<STR_LIT>""" <EOL> delete_node ( cur , nd2_1_1 , auto_position = False ) <EOL> with pytest . raises ( ValueError ) : <EOL> get_node ( cur , nd2_1_1 . id ) <EOL> assert set ( get_child_ids ( cur , nd2_1 ) ) == set ( ) <EOL> assert set ( get_child_ids ( cur , nd2_1_1 ) ) == set ( ) <EOL> assert set ( get_descendant_ids ( cur , nd2_1 ) ) == set ( ) <EOL> assert set ( get_child_ids ( cur , nd1 ) ) == { nd2_1 . id } <EOL> assert set ( get_descendant_ids ( cur , nd1 ) ) == { nd2_1 . id } <EOL> assert set ( get_ancestor_ids ( cur , nd2_1_1 ) ) == set ( ) <EOL> assert set ( get_ancestor_ids ( cur , nd2_leaf ) ) == set ( ) <EOL> assert set ( get_descendant_ids ( cur , nd2_1_1 ) ) == set ( ) <EOL> assert set ( get_descendant_ids ( cur , nd2_leaf ) ) == set ( ) <EOL> def test_delete_node_by_id ( cur , nd1 , nd2_1 ) : <EOL> delete_node ( cur , nd2_1 . id , auto_position = True ) <EOL> assert set ( get_child_ids ( cur , nd1 ) ) == set ( ) </s>
