コード例 #1
0
ファイル: dependencies.py プロジェクト: klolos/kale
def dependencies_detection(nb_graph: nx.DiGraph,
                           pipeline_parameters: dict = None):
    """Analyze the code blocks in the graph and detect the missing names.

    in each code block, annotating the nodes with `in` and `out` dependencies
    based in the topology of the graph.

    Args:
        nb_graph: nx DiGraph with pipeline code blocks
        pipeline_parameters: Pipeline parameters dict

    Returns: annotated graph
    """
    # First get all the names of each code block
    for block in nb_graph:
        block_data = nb_graph.nodes(data=True)[block]
        all_names = get_all_names('\n'.join(block_data['source']))
        nx.set_node_attributes(nb_graph, {block: {'all_names': all_names}})

    # annotate the graph inplace with all the variables dependencies between
    # graph nodes
    detect_in_dependencies(nb_graph, pipeline_parameters)
    detect_out_dependencies(nb_graph)

    return nb_graph
コード例 #2
0
def test_get_all_names_exc():
    """Tests exception when passing a wrong code snippet to get_all_names."""
    with pytest.raises(SyntaxError):
        kale_ast.get_all_names(_wrong_code_snippet)
コード例 #3
0
def test_get_all_names(code, target):
    """Tests get_all_names function."""
    res = kale_ast.get_all_names(code)
    assert sorted(res) == sorted(target)