Ejemplo n.º 1
0
def test_build_tree_cycle_fail():
    '''
    Tests that a cycle is detected in a build_tree.
    '''
    cycle_build_commands = [
        build_tree.BuildCommand("recipe1",
                                "repo1", ["package1a", "package1b"],
                                python="2.6",
                                build_type="cuda",
                                mpi_type="openmpi",
                                build_command_dependencies=[1, 2]),
        build_tree.BuildCommand("recipe2",
                                "repo2", ["package2a"],
                                python="2.6",
                                build_type="cpu",
                                mpi_type="openmpi",
                                build_command_dependencies=[0]),
        build_tree.BuildCommand("recipe3",
                                "repo3", ["package3a", "package3b"],
                                build_command_dependencies=[1])
    ]

    mock_build_tree = TestBuildTree([], "3.6", "cpu", "openmpi")
    mock_build_tree.build_commands = sample_build_commands

    mock_build_tree._detect_cycle()  #Make sure there isn't a false positive.

    mock_build_tree.build_commands = cycle_build_commands

    with pytest.raises(OpenCEError) as exc:
        mock_build_tree._detect_cycle()

    assert "Build dependencies should form a Directed Acyclic Graph." in str(
        exc.value)
    assert "recipe1 -> recipe2 -> recipe1" in str(exc.value)
    assert "recipe1 -> recipe3 -> recipe2 -> recipe1" in str(exc.value)
    assert "recipe2 -> recipe1 -> recipe3 -> recipe2" in str(exc.value)
    assert "recipe3 -> recipe2 -> recipe1 -> recipe2" in str(exc.value)
Ejemplo n.º 2
0
def test_feedstock_args():
    '''
    Tests that feedstock_args creates the correct arguments.
    '''

    build_commands = [
        build_tree.BuildCommand("recipe", "repo", {"pkg1", "pkg2"}),
        build_tree.BuildCommand("recipe2",
                                "repo2", {"pkg1", "pkg2"},
                                python="3.2",
                                mpi_type="system",
                                build_type="cuda",
                                cudatoolkit="10.0")
    ]

    for build_command in build_commands:
        build_string = " ".join(build_command.feedstock_args())
        assert "--working_directory {}".format(
            build_command.repository) in build_string
        if build_command.recipe:
            assert "--recipes {}".format(build_command.recipe) in build_string
        if build_command.channels:
            for channel in build_command.channels:
                assert "--channels {}".format(channel) in build_string
        if build_command.python:
            assert "--python_versions {}".format(
                build_command.python) in build_string
        if build_command.build_type:
            assert "--build_types {}".format(
                build_command.build_type) in build_string
        if build_command.mpi_type:
            assert "--mpi_types {}".format(
                build_command.mpi_type) in build_string
        if build_command.cudatoolkit:
            assert "--cuda_versions {}".format(
                build_command.cudatoolkit) in build_string
def test_conda_env_file_for_inapplicable_conf():
    '''
    Tests that the conda env file is not generated if build is triggered for
    inapplicable configurations. For e.g. cpu variant build is selected for cuda only
    packages like TensorRT
    '''
    python_versions = "3.7"
    build_types = "cuda"
    mpi_types = "openmpi"
    mock_build_tree = TestBuildTree([], python_versions, build_types,
                                    mpi_types)

    mock_build_tree.build_commands = [
        build_tree.BuildCommand(
            "recipe1",
            "repo1",
            [],  # packages is intentionally kept empty
            python=python_versions,
            build_type=build_types,
            mpi_type=mpi_types,
            run_dependencies=None)
    ]

    output_dir = os.path.join(test_dir, '../condabuild')
    mock_conda_env_file_generator = TestCondaEnvFileGenerator(
        python_versions, build_types, mpi_types, [], output_dir)

    expected_keys = ["py3.7-cuda-openmpi"]
    actual_keys = list(mock_conda_env_file_generator.dependency_dict.keys())
    assert actual_keys == expected_keys

    for build_command in mock_build_tree:
        mock_conda_env_file_generator.update_conda_env_file_content(
            build_command, mock_build_tree)

    mock_conda_env_file_generator.write_conda_env_files(TMP_OPENCE_DIR)

    # Check that no conda env file is created
    for (root, _, _) in os.walk(TMP_OPENCE_DIR, topdown=True):
        assert len(root) == 0

    cleanup()
    assert not os.path.exists(TMP_OPENCE_DIR)
Ejemplo n.º 4
0
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["git clone"], retval=1)))

    with pytest.raises(OpenCEError) as exc:
        mock_build_tree._clone_repo("https://bad_url", "/test/my_repo", None,
                                    "master")
    assert "Unable to clone repository" in str(exc.value)


sample_build_commands = [
    build_tree.BuildCommand("recipe1",
                            "repo1", ["package1a", "package1b"],
                            python="2.6",
                            build_type="cuda",
                            mpi_type="openmpi",
                            build_command_dependencies=[1, 2]),
    build_tree.BuildCommand("recipe2",
                            "repo2", ["package2a"],
                            python="2.6",
                            build_type="cpu",
                            mpi_type="openmpi",
                            build_command_dependencies=[]),
    build_tree.BuildCommand("recipe3",
                            "repo3", ["package3a", "package3b"],
                            build_command_dependencies=[1])
]


def test_get_dependency_names():
    '''
    Test class that inherits CondaEnvFileGenerator class
    '''
    __test__ = False

    def __init__(self, python_versions, build_types, mpi_types, channels,
                 output_folder):
        super().__init__(python_versions, build_types, mpi_types, channels,
                         output_folder)


sample_build_commands = [
    build_tree.BuildCommand(
        "recipe1",
        "repo1", ["package1a", "package1b"],
        python="3.6",
        build_type="cuda",
        mpi_type="openmpi",
        run_dependencies=["python     >=3.6", "pack1    1.0",
                          "pack2   >=2.0"]),
    build_tree.BuildCommand("recipe2",
                            "repo2", ["package2a"],
                            python="3.6",
                            build_type="cpu",
                            mpi_type="system",
                            run_dependencies=[
                                "python ==3.6", "pack1 >=1.0", "pack2   ==2.0",
                                "pack3 3.3 build"
                            ]),
    build_tree.BuildCommand("recipe3",
                            "repo3", ["package3a", "package3b"],
                            python="3.7",
Ejemplo n.º 6
0
def test_build_tree_duplicates():
    '''
    Tests that `build_tree._add_build_command_dependencies` removes duplicate build_commands
    and sets the `build_command_dependencies` accordingly.
    '''

    initial_build_commands = [
        build_tree.BuildCommand("recipe1",
                                "repo1", ["package1a"],
                                output_files=["linux/package1a.tar.gz"],
                                python="2.6",
                                build_type="cuda",
                                mpi_type="openmpi",
                                build_command_dependencies=[],
                                run_dependencies=[],
                                build_dependencies=[],
                                host_dependencies=[],
                                test_dependencies=[]),
        build_tree.BuildCommand("recipe2",
                                "repo2", ["package2a"],
                                output_files=["linux/package2a.tar.gz"],
                                python="2.6",
                                build_type="cuda",
                                mpi_type="openmpi",
                                build_command_dependencies=[0],
                                run_dependencies=[],
                                build_dependencies=[],
                                host_dependencies=[],
                                test_dependencies=[])
    ]

    duplicate_build_commands = [
        build_tree.BuildCommand("recipe2",
                                "repo2", ["package2a"],
                                output_files=["linux/package2a.tar.gz"],
                                python="2.6",
                                build_type="cuda",
                                mpi_type="openmpi",
                                build_command_dependencies=[],
                                run_dependencies=[],
                                build_dependencies=[],
                                host_dependencies=[],
                                test_dependencies=[]),
        build_tree.BuildCommand("recipe1",
                                "repo1", ["package1a"],
                                output_files=["linux/package1a.tar.gz"],
                                python="2.6",
                                build_type="cuda",
                                mpi_type="openmpi",
                                build_command_dependencies=[],
                                run_dependencies=[],
                                build_dependencies=[],
                                host_dependencies=[],
                                test_dependencies=[]),
        build_tree.BuildCommand("recipe3",
                                "repo3", ["package3a"],
                                output_files=["linux/package3a.tar.gz"],
                                python="2.6",
                                build_type="cpu",
                                mpi_type="openmpi",
                                build_command_dependencies=[1],
                                run_dependencies=[],
                                build_dependencies=["package1a"],
                                host_dependencies=[],
                                test_dependencies=[])
    ]
    additional_build_commands = [
        build_tree.BuildCommand("recipe4",
                                "repo4", ["package4a"],
                                output_files=["linux/package4a.tar.gz"],
                                python="2.6",
                                build_type="cpu",
                                mpi_type="openmpi",
                                build_command_dependencies=[],
                                run_dependencies=[],
                                build_dependencies=[],
                                host_dependencies=[],
                                test_dependencies=[])
    ]

    out_commands = build_tree._add_build_command_dependencies(
        additional_build_commands, initial_build_commands,
        len(initial_build_commands))
    assert len(
        out_commands) == 1  # Make sure the non-duplicates are not removed

    out_commands = build_tree._add_build_command_dependencies(
        duplicate_build_commands, initial_build_commands,
        len(initial_build_commands))
    assert len(out_commands) == 1

    for build_command in out_commands:
        assert build_command.build_command_dependencies == [0]