def test_treediff_noop(sample_tree): assert len(sample_tree['children']) == 3 unchanged_tree = copy.deepcopy(sample_tree) raw_diff = treediff(sample_tree, unchanged_tree, format="raw") diff_keys = [ 'nodes_deleted', 'nodes_added', 'nodes_modified', 'nodes_moved' ] for diff_key in diff_keys: assert raw_diff[diff_key] == []
def test_treediff_noop_simplified(sample_tree): assert len(sample_tree['children']) == 3 unchanged_tree = copy.deepcopy(sample_tree) simplified_diff = treediff(sample_tree, unchanged_tree, format="simplified") # pprint.pprint(simplified_diff) diff_keys = [ 'nodes_deleted', 'nodes_added', 'nodes_modified', 'nodes_moved' ] for diff_key in diff_keys: assert simplified_diff[diff_key] == []
def test_treediff_large_kolibri_tree_modify(large_kolibri_tree): modified_tree = copy.deepcopy(large_kolibri_tree) modified_tree['children'][3]['children'][1]['title'] = 'Modified title' raw_diff = treediff(large_kolibri_tree, modified_tree, preset="kolibri", format="raw") diff_keys = ['nodes_deleted', 'nodes_added', 'nodes_moved'] for diff_key in diff_keys: assert raw_diff[diff_key] == [] nodes_modified = raw_diff['nodes_modified'] assert (len(nodes_modified)) == 1
def test_treediff_with_moves_and_reorder_restructured( sample_tree, sample_tree_with_moves_and_reorder): assert len(sample_tree['children']) == 3 assert len(sample_tree_with_moves_and_reorder['children']) == 3 restructured_diff = treediff(sample_tree, sample_tree_with_moves_and_reorder, format="restructured") # pprint.pprint(restructured_diff) assert len(restructured_diff['nodes_added']) == 0 assert len(restructured_diff['nodes_modified']) == 0 assert len(restructured_diff['nodes_deleted']) == 0 nodes_moved = restructured_diff['nodes_moved'] assert len(nodes_moved) == 2
def test_treediff_with_moves_simplified(sample_tree, sample_tree_with_moves): assert len(sample_tree['children']) == 3 assert len(sample_tree_with_moves['children']) == 3 simplified_diff = treediff(sample_tree, sample_tree_with_moves, format="simplified") # pprint.pprint(simplified_diff) # print_diff(simplified_diff) assert len(simplified_diff['nodes_added']) == 0 assert len(simplified_diff['nodes_modified']) == 0 assert len(simplified_diff['nodes_deleted']) == 0 nodes_moved = simplified_diff['nodes_moved'] assert len(nodes_moved) == 5
def test_difftree_add_and_rm_restructured(sample_tree, sample_tree_add_and_rm): assert len(sample_tree['children']) == 3 assert len(sample_tree_add_and_rm['children']) == 3 restructured_diff = treediff(sample_tree, sample_tree_add_and_rm, format="restructured") # pprint.pprint(diff, width=120) # print_diff(restructured_diff) nodes_deleted = restructured_diff['nodes_deleted'] assert len(nodes_deleted) == 3 nodes_added = restructured_diff['nodes_added'] assert len(nodes_added) == 9 assert len(restructured_diff['nodes_moved']) == 0 assert len(restructured_diff['nodes_modified']) == 0
def test_difftree_removal_restructured(sample_tree, sample_tree_with_removals): assert len(sample_tree['children']) == 3 assert len(sample_tree_with_removals['children']) == 2 simplified_diff = treediff(sample_tree, sample_tree_with_removals, format="restructured") assert len(simplified_diff['nodes_added']) == 0 assert len(simplified_diff['nodes_modified']) == 0 assert len(simplified_diff['nodes_moved']) == 0 nodes_deleted = simplified_diff['nodes_deleted'] assert len(nodes_deleted) == 1 # T3 subtree t3 = findby(nodes_deleted, {"old_node_id": 'T3'}, by="old_node_id") assert len(t3['children']) == 1 t31 = findby(t3['children'], {"old_node_id": 'T31'}, by="old_node_id") assert len(t31['children']) == 1 t311 = findby(t31['children'], {"old_node_id": 'T311'}, by="old_node_id") assert len(t311['children']) == 3
def test_difftree_added_restructured(sample_tree, sample_tree_added): assert len(sample_tree['children']) == 3 assert len(sample_tree_added['children']) == 5 assert len(sample_tree_added['children'][4]['children']) == 3 restructured_diff = treediff(sample_tree, sample_tree_added, format="restructured") # pprint.pprint(restructured_diff) assert len(restructured_diff['nodes_deleted']) == 0 assert len(restructured_diff['nodes_modified']) == 0 assert len(restructured_diff['nodes_moved']) == 0 nodes_added = restructured_diff['nodes_added'] assert len(nodes_added) == 2 n4 = findby(nodes_added, {"node_id": 'nid4'}, by="node_id") assert n4 t4 = findby(nodes_added, {"node_id": 'T4'}, by="node_id") assert len(t4['children']) == 3
def test_treediff_large_kolibri_tree_noop(large_kolibri_tree): # import tracemalloc # tracemalloc.start() # assert len(large_kolibri_tree['children']) == 22 unchanged_tree = copy.deepcopy(large_kolibri_tree) raw_diff = treediff(large_kolibri_tree, unchanged_tree, preset="kolibri", format="raw") # current, peak = tracemalloc.get_traced_memory() # print("::::MEM:::: Current memory usage is {}MB; Peak was {}MB".format(current/10**6, peak/10**6)) # tracemalloc.stop() diff_keys = [ 'nodes_deleted', 'nodes_added', 'nodes_modified', 'nodes_moved' ] for diff_key in diff_keys: assert raw_diff[diff_key] == []