Ejemplo n.º 1
0
def test_parameter_inheritance_confidence(return_type):
    graph = build_inheritance_graph(
        _extract_classes_from_module(
            "tests.fixtures.cluster.overridden_inherited_methods"))
    nodes = list(graph._graph.nodes)
    nodes.sort(key=lambda n: n.name)
    ci_builtins, ci_bar, ci_foo = nodes
    return_type.add_element(ConcreteType(ci_bar), 1.0)
    return_type.include_inheritance(graph)

    elements = [element for element in return_type.elements]
    elements.sort(key=lambda n: n.signature_type.class_information.name)
    confidences = [element.confidence for element in elements]
    assert confidences == [0.25, 1.0, 0.5]
Ejemplo n.º 2
0
def test_inheritance_graph_get_distance():
    inheritance_graph = build_inheritance_graph(
        _extract_classes_from_module(
            "tests.fixtures.cluster.overridden_inherited_methods"))
    nodes = list(inheritance_graph._graph.nodes)
    nodes.sort(key=lambda n: n.name)
    ci_object, ci_bar, ci_foo = tuple(nodes)
    assert inheritance_graph.get_distance(ci_bar, ci_bar) == 0
    assert inheritance_graph.get_distance(ci_foo, ci_bar) == 1
    assert inheritance_graph.get_distance(ci_bar, ci_object) == -2
    with pytest.raises(ValueError):
        inheritance_graph.get_distance(ci_object, None)
    with pytest.raises(ValueError):
        inheritance_graph.get_distance(None, ci_bar)
Ejemplo n.º 3
0
def inheritance_graph():
    return build_inheritance_graph(
        _extract_classes_from_module(
            "tests.fixtures.cluster.typing_parameters"))
Ejemplo n.º 4
0
def test_build_inheritance_graph(module_name, number_of_nodes,
                                 number_of_edges):
    graph = build_inheritance_graph(_extract_classes_from_module(module_name))
    assert graph.number_of_nodes() == number_of_nodes
    assert graph.number_of_edges() == number_of_edges
Ejemplo n.º 5
0
def inheritance_graph():
    return build_inheritance_graph(
        _extract_classes_from_module(
            "tests.fixtures.cluster.complex_dependencies"))