예제 #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_detect_external_dependencies_for_packages(
    package_a: Requirement,
    external_dependency_a: ExternalDependency,
    dependency_graph: DependencyGraph,
):
    dependency_graph.set_external_dependency(dependent=package_a,
                                             dependency=external_dependency_a)
    assert dependency_graph.get_all_external_dependencies(package_a) == {
        external_dependency_a,
    }
def test_external_dependencies_from_graph_are_retrieved(
    requirement_parser: RequirementParser, ) -> None:
    dependency_graph = DependencyGraph()
    requirement = requirement_parser.parse("testpackage")
    external_dependency = ExternalDependency("external")
    dependency_graph.set_external_dependency(dependent=requirement,
                                             dependency=external_dependency)
    retriever = RequirementDependencyRetriever(dependency_graph)
    assert external_dependency in retriever.get_external_dependency_for_requirement(
        requirement)
def test_can_retrieve_external_dependencies_from_runtime_dependencies(
    package_a: Requirement,
    package_b: Requirement,
    external_dependency_a: ExternalDependency,
    dependency_graph: DependencyGraph,
):
    dependency_graph.set_runtime_dependency(dependent=package_a,
                                            dependency=package_b)
    dependency_graph.set_external_dependency(dependent=package_b,
                                             dependency=external_dependency_a)
    assert dependency_graph.get_all_external_dependencies(
        package=package_a) == {
            external_dependency_a,
        }
def test_can_retrieve_external_dependencies_after_adding_graphs(
    package_a: Requirement,
    package_b: Requirement,
    external_dependency_a: ExternalDependency,
    external_dependency_b: ExternalDependency,
    dependency_graph: DependencyGraph,
):
    other_dependency_graph = copy(dependency_graph)
    dependency_graph.set_external_dependency(dependent=package_a,
                                             dependency=external_dependency_a)
    dependency_graph.set_runtime_dependency(dependent=package_a,
                                            dependency=package_b)
    other_dependency_graph.set_external_dependency(
        dependent=package_b, dependency=external_dependency_b)
    sum_graph = dependency_graph + other_dependency_graph
    assert sum_graph.get_all_external_dependencies(package=package_a) == {
        external_dependency_a,
        external_dependency_b,
    }