示例#1
0
def get_inherited_properties(cur, node):
    """
    Get the entire inherited property dictionary.

    To calculate this, the trees path from root node till ``node`` will
    be traversed. For each level, the property dictionary will be merged
    into the previous one. This is a simple merge, only the first level
    of keys will be combined.

    :param node:
    :type node: Node or uuid4
    :rtype: dict
    """
    ret = {}
    id = str(node)
    if isinstance(node, str):
        node = get_node(cur, id)

    ancestors = list(get_ancestors(cur, id))

    for ancestor in ancestors[::-1]:  # Go top down
        ret.update(ancestor.properties)

    ret.update(node.properties)

    return ret
示例#2
0
def get_inherited_properties(cur, node):
    """
    Get the entire inherited property dictionary.

    To calculate this, the trees path from root node till ``node`` will
    be traversed. For each level, the property dictionary will be merged
    into the previous one. This is a simple merge, only the first level
    of keys will be combined.

    :param node:
    :type node: Node or uuid4
    :rtype: dict
    """
    ret = {}
    id = str(node)
    if isinstance(node, str):
        node = get_node(cur, id)

    ancestors = list(get_ancestors(cur, id))

    for ancestor in ancestors[::-1]:  # Go top down
        ret.update(ancestor.properties)

    ret.update(node.properties)

    return ret
示例#3
0
def get_recursive_properties(cur, node):
    """
    Get the entire inherited and recursively merged property dictionary.

    To calculate this, the trees path from root node till ``node`` will
    be traversed. For each level, the property dictionary will be merged
    into the previous one. This is a recursive merge, so all dictionary
    levels will be combined.

    :param node:
    :type node: Node or uuid4
    :rtype: dict
    """
    ret = {}
    id = str(node)
    if isinstance(node, str):
        node = get_node(cur, id)

    ancestors = list(get_ancestors(cur, id))

    for ancestor in ancestors[::-1]:  # Go top down
        recursive_dict_merge(ret, ancestor.properties, create_copy=False)

    recursive_dict_merge(ret, node.properties, create_copy=False)

    return ret
示例#4
0
def get_recursive_properties(cur, node):
    """
    Get the entire inherited and recursively merged property dictionary.

    To calculate this, the trees path from root node till ``node`` will
    be traversed. For each level, the property dictionary will be merged
    into the previous one. This is a recursive merge, so all dictionary
    levels will be combined.

    :param node:
    :type node: Node or uuid4
    :rtype: dict
    """
    ret = {}
    id = str(node)
    if isinstance(node, str):
        node = get_node(cur, id)

    ancestors = list(get_ancestors(cur, id))

    for ancestor in ancestors[::-1]:  # Go top down
        recursive_dict_merge(ret, ancestor.properties, create_copy=False)

    recursive_dict_merge(ret, node.properties, create_copy=False)

    return ret
示例#5
0
def xtest_get_ancestors_calls_vectorize_nodes(cur, nd2_leaf):
    with patch.object(libtree.tree, 'vectorize_nodes') as func:
        get_ancestors(cur, nd2_leaf, sort=True)
        assert func.called
示例#6
0
def test_get_ancestor_ids(cur, root, nd2, nd2_1, nd2_1_1, nd2_leaf):
    expected = {root.id, nd2.id, nd2_1.id, nd2_1_1.id}
    ids = set(map(str, get_ancestors(cur, nd2_leaf, sort=False)))
    assert ids == expected
示例#7
0
def test_get_ancestors_returns_correct_order(cur, root, nd2, nd2_1,
                                             nd2_1_1, nd2_leaf):
    expected = [nd2_1_1.id, nd2_1.id, nd2.id, root.id]
    ids = list(map(str, get_ancestors(cur, nd2_leaf, sort=True)))
    assert ids == expected
示例#8
0
def test_get_ancestors(cur, root, nd2, nd2_1):
    ancestors = list(get_ancestors(cur, nd2_1))
    assert len(ancestors) == 2
    assert ancestors[0].id == nd2.id
    assert ancestors[1].id == root.id
示例#9
0
def xtest_get_ancestors_calls_vectorize_nodes(cur, nd2_leaf):
    with patch.object(libtree.tree, 'vectorize_nodes') as func:
        get_ancestors(cur, nd2_leaf, sort=True)
        assert func.called
示例#10
0
def test_get_ancestor_ids(cur, root, nd2, nd2_1, nd2_1_1, nd2_leaf):
    expected = {root.id, nd2.id, nd2_1.id, nd2_1_1.id}
    ids = set(map(str, get_ancestors(cur, nd2_leaf, sort=False)))
    assert ids == expected
示例#11
0
def test_get_ancestors_returns_correct_order(cur, root, nd2, nd2_1, nd2_1_1,
                                             nd2_leaf):
    expected = [nd2_1_1.id, nd2_1.id, nd2.id, root.id]
    ids = list(map(str, get_ancestors(cur, nd2_leaf, sort=True)))
    assert ids == expected
示例#12
0
def test_get_ancestors(cur, root, nd2, nd2_1):
    ancestors = list(get_ancestors(cur, nd2_1))
    assert len(ancestors) == 2
    assert ancestors[0].id == nd2.id
    assert ancestors[1].id == root.id