def test_traverse_only_dir_tree(self): node1 = DirectoryNode("", None) node2 = node1.get_or_insert_node("part1/part2/part3") node5 = node1.get_or_insert_node("part1/part6/part7") node6 = node1.get_or_insert_node("part8/part9") node8 = node1.get_or_insert_node("part11", only_directory=True) def collect(node): return isinstance(node, DirectoryNode) node_list = list(node1.traverse(collect=collect)) assert len(node_list) == 6 assert node1 in node_list assert node2.parent in node_list assert node2.parent.parent in node_list assert node5.parent in node_list assert node6.parent in node_list assert node8 in node_list
def test_traverse_various_node_tree(self): node1 = DirectoryNode("", None) node2 = node1.get_or_insert_node("part1/part2/part3") node3 = node1.get_or_insert_node("part1/part2/part4") node4 = node1.get_or_insert_node("part1/part2/part5") node5 = node1.get_or_insert_node("part1/part6/part7") node6 = node1.get_or_insert_node("part8/part9") node7 = node1.get_or_insert_node("part10") def collect(node): return isinstance(node, FileNode) node_list = list(node1.traverse(collect=collect)) assert len(node_list) == 6 assert node2 in node_list assert node3 in node_list assert node4 in node_list assert node5 in node_list assert node6 in node_list assert node7 in node_list
def test_traverse_do_not_explore_self(self): node = DirectoryNode("", None) node_list = list(node.traverse(explore=lambda x: False)) assert len(node_list) == 0
def test_traverse_empty_tree(self): node = DirectoryNode("", None) node_list = list(node.traverse()) assert len(node_list) == 1 assert node in node_list