def test_no_item_iterator(): it = iter([b"root/", b"root/o"]) result = visitors.children_visitor("root/", it, factory) assert (result) assert result.containers == set(["root/"]) assert result.leafs["root/o"] == None
def test_single_node(): input_dict = { b"root/": "", } it = fake_iterator.build_fake_iterator(input_dict) result = visitors.children_visitor("root/", it, factory) assert result assert result.containers == set(["root/"]) assert result.leafs == {}
def test_overlap_with_children(): input_dict = { b"root/": "", b"root/o": "o", b"root/o/": "o/", b"root/o/o": "o/o", b"root/oo": "oo", b"root/oo/": "oo/", b"root/oo/o": "oo/o" } it = fake_iterator.build_fake_iterator(input_dict) result = visitors.children_visitor("root/", it, factory) assert result assert result.containers == set(["root/", "root/o/", "root/oo/"]) assert result.leafs == { "root/o": "o", "root/o/o": "o/o", "root/oo": "oo", "root/oo/o": "oo/o" }
def delete_children(self, key, it): class KeyBuilder: def __init__(self): # Delete ourself too! self.result = [] def add_child(self, name, child): self.result.extend(child.get_result()) def visit(self, name, next_value): self.result.append(name) def visit_container(self, name, next_value): print(f"Visting container:{name}") self.result.append(name) def get_result(self): return self.result def create_builder(): return KeyBuilder() return visitors.children_visitor(key, it, create_builder)
def test_overlap_no_children(): it = fake_iterator.build_fake_iterator({b"abc/": b"hello", b"foo": b"bar"}) result = visitors.children_visitor("ab", it, factory) assert not result
def test_no_match(): it = fake_iterator.build_fake_iterator({b"abc": b"hello", b"foo": b"bar"}) result = visitors.children_visitor("blah", it, factory) assert not result
def test_empty_children(): it = fake_iterator.build_fake_iterator({}) result = visitors.children_visitor("", it, factory) assert not result