Esempio n. 1
0
def dependency_graph(
        draw,
        python_packages=lists(requirement(), unique_by=lambda x: x.name()),
        external_dependencies=lists(external_dependency()),
        is_runtime_dependency=booleans(),
        selections=integers(),
):
    graph = DependencyGraph()
    packages = draw(python_packages)
    if not packages:
        return graph
    for package in packages:
        index = draw(selections) % len(packages)
        try:
            if draw(is_runtime_dependency):
                graph.set_runtime_dependency(dependent=package,
                                             dependency=packages[index])
            else:
                graph.set_buildtime_dependency(dependent=package,
                                               dependency=packages[index])
        except CyclicDependencyOccured:
            continue
    for dependency in draw(external_dependencies):
        graph.set_external_dependency(dependent=packages[draw(selections) %
                                                         len(packages)],
                                      dependency=dependency)
    return graph
def test_can_set_buildtime_dependency(package_a: Requirement,
                                      package_b: Requirement,
                                      dependency_graph: DependencyGraph):
    dependency_graph.set_buildtime_dependency(dependent=package_a,
                                              dependency=package_b)
    assert dependency_graph.is_buildtime_dependency(dependent=package_a,
                                                    dependency=package_b)
def test_cannot_add_circular_buildtime_dependencies(
    package_a: Requirement,
    package_b: Requirement,
    dependency_graph: DependencyGraph,
):
    dependency_graph.set_buildtime_dependency(dependent=package_a,
                                              dependency=package_b)
    with pytest.raises(CyclicDependencyOccured):
        dependency_graph.set_buildtime_dependency(dependent=package_b,
                                                  dependency=package_a)
def test_build_time_dependencies_dont_show_up_as_runtime_dependencies(
    package_a: Requirement,
    package_b: Requirement,
    package_c: Requirement,
    dependency_graph: DependencyGraph,
):
    dependency_graph.set_runtime_dependency(dependent=package_a,
                                            dependency=package_b)
    dependency_graph.set_buildtime_dependency(dependent=package_b,
                                              dependency=package_c)
    assert not dependency_graph.is_runtime_dependency(dependent=package_a,
                                                      dependency=package_c)
def test_can_add_two_dependencies_graphs_and_buildtime_dependencies_are_also_added(
    package_a: Requirement,
    package_b: Requirement,
    package_c: Requirement,
    dependency_graph: DependencyGraph,
):
    other_dependency_graph = copy(dependency_graph)
    dependency_graph.set_buildtime_dependency(dependent=package_a,
                                              dependency=package_b)
    other_dependency_graph.set_buildtime_dependency(dependent=package_b,
                                                    dependency=package_c)
    sum_graph = dependency_graph + other_dependency_graph
    assert not dependency_graph.is_buildtime_dependency(dependent=package_a,
                                                        dependency=package_c)
    assert not other_dependency_graph.is_buildtime_dependency(
        dependent=package_a, dependency=package_c)
    assert sum_graph.is_buildtime_dependency(dependent=package_a,
                                             dependency=package_c)