Esempio n. 1
0
def test_tree():
    tree = Tree()
    assert len(tree) == 1
    tree.get('account:name:a:b:c')
    assert len(tree) == 1
    node = tree.get('account:name:a:b:c', insert=True)
    assert len(tree) == 6
    tree.get('account:name', insert=True)
    assert len(tree) == 6
    assert node is tree.get('account:name:a:b:c', insert=True)

    assert list(tree.ancestors('account:name:a:b:c')) == [
        tree.get('account:name:a:b'),
        tree.get('account:name:a'),
        tree.get('account:name'),
        tree.get('account'),
        tree.get(''),
    ]

    assert len(list(tree.ancestors('not:account:name:a:b:c'))) == 6
Esempio n. 2
0
def test_tree():
    tree = Tree()
    assert len(tree) == 1
    tree.get("account:name:a:b:c")
    assert len(tree) == 1
    node = tree.get("account:name:a:b:c", insert=True)
    assert len(tree) == 6
    tree.get("account:name", insert=True)
    assert len(tree) == 6
    assert node is tree.get("account:name:a:b:c", insert=True)

    assert list(tree.ancestors("account:name:a:b:c")) == [
        tree.get("account:name:a:b"),
        tree.get("account:name:a"),
        tree.get("account:name"),
        tree.get("account"),
        tree.get(""),
    ]

    assert len(list(tree.ancestors("not:account:name:a:b:c"))) == 6