Beispiel #1
0
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
Beispiel #2
0
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 == {}
Beispiel #3
0
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"
    }
Beispiel #4
0
    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)
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
def test_empty_children():
    it = fake_iterator.build_fake_iterator({})

    result = visitors.children_visitor("", it, factory)

    assert not result