コード例 #1
0
def test_clone_repo(mocker):
    '''
    Simple positive test for `_clone_repo`.
    '''
    git_location = utils.DEFAULT_GIT_LOCATION

    mock_build_tree = TestBuildTree([],
                                    "3.6",
                                    "cpu",
                                    "openmpi",
                                    "10.2",
                                    git_tag_for_env="main")

    dir_tracker = helpers.DirTracker()
    mocker.patch('os.getcwd', side_effect=dir_tracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dir_tracker.validate_chdir)
    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x,
                     possible_expect=[
                         "git clone", git_location + "/my_repo.git",
                         "/test/my_repo", "git checkout main"
                     ])))

    mock_build_tree._clone_repo(git_location + "/my_repo.git", "/test/my_repo",
                                None, None)
コード例 #2
0
ファイル: build_env_test.py プロジェクト: dllehr81/open-ce
def test_env_validate(mocker, capsys):
    '''
    This is a negative test of `build_env`, which passes an invalid env file.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["git clone"], retval=0)
        )  #At this point all system calls are git clones. If that changes this should be updated.
    )
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), [])))
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    buildTracker = PackageBuildTracker()
    mocker.patch('build_feedstock.build_feedstock',
                 side_effect=buildTracker.validate_build_feedstock)
    env_file = os.path.join(test_dir, 'test-env-invalid1.yaml')
    assert build_env.build_env([env_file]) == 1
    captured = capsys.readouterr()
    assert "Unexpected key chnnels was found in " in captured.err
コード例 #3
0
def test_get_repo_with_patches(mocker, caplog):
    '''
    Test for `_get_repo` that verifies `patches` field
    '''
    env_file = os.path.join(test_dir, 'test-env3.yaml')
    mock_build_tree = TestBuildTree([env_file], "3.6", "cpu", "openmpi",
                                    "10.2")

    dir_tracker = helpers.DirTracker()
    mocker.patch('os.getcwd', side_effect=dir_tracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dir_tracker.validate_chdir)

    mocker.patch(
        'os.system',
        return_value=0,
        side_effect=(lambda x: helpers.validate_cli(
            x, expect=["git apply"], ignore=["git clone", "git checkout"])))

    possible_variants = utils.make_variants("3.6", "cpu", "openmpi", "10.2")
    for variant in possible_variants:
        # test-env3.yaml has specified "patches".
        env_config_data_list = env_config.load_env_config_files([env_file],
                                                                [variant])
        for env_config_data in env_config_data_list:
            packages = env_config_data.get(env_config.Key.packages.name, [])
            for package in packages:

                if package.get(env_config.Key.feedstock.name) == "package22":
                    _ = mock_build_tree._get_repo(env_config_data, package)
                    assert "Patch apply command: git apply" in caplog.text
                    break
コード例 #4
0
def test_validate_bad_env(mocker):
    '''
    This is a negative test of `validate_config` where the env file is bad.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch('os.system', return_value=0)
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    env_file = os.path.join(test_dir, 'test-env-invalid1.yaml')
    with pytest.raises(OpenCEError) as err:
        opence._main([
            "validate", validate_config.COMMAND, "--conda_build_config",
            "./conda_build_config.yaml", env_file, "--python_versions", "3.6",
            "--build_types", "cuda"
        ])
    assert "Error validating \"" in str(err.value)
    assert "conda_build_config.yaml\" for " in str(err.value)
    assert "Unexpected key chnnels was found in " in str(err.value)
コード例 #5
0
def test_get_repo_for_nonexisting_patch(mocker):
    '''
    Test for `_get_repo` that verifies exception is thrown when patch application fails
    '''
    env_file = os.path.join(test_dir, 'test-env3.yaml')
    mock_build_tree = TestBuildTree([env_file], "3.6", "cpu", "openmpi",
                                    "10.2")

    dir_tracker = helpers.DirTracker()
    mocker.patch('os.getcwd', side_effect=dir_tracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dir_tracker.validate_chdir)
    mocker.patch('os.system',
                 side_effect=(lambda x: helpers.validate_cli(
                     x,
                     expect=["git apply"],
                     ignore=["git clone", "git checkout"],
                     retval=1)))
    mocker.patch('shutil.rmtree', return_value=None)

    possible_variants = utils.make_variants("3.6", "cpu", "openmpi", "10.2")
    for variant in possible_variants:
        # test-env3.yaml has defined "patches".
        env_config_data_list = env_config.load_env_config_files([env_file],
                                                                [variant])
        for env_config_data in env_config_data_list:
            packages = env_config_data.get(env_config.Key.packages.name, [])
            for package in packages:

                # "package211" has specified a non-existing patch
                if package.get(env_config.Key.feedstock.name) == "package211":
                    with pytest.raises(OpenCEError) as exc:
                        _ = mock_build_tree._get_repo(env_config_data, package)
                    assert "Failed to apply patch " in str(exc.value)
コード例 #6
0
ファイル: build_env_test.py プロジェクト: npanpaliya/open-ce
def test_env_validate(mocker):
    '''
    This is a negative test of `build_env`, which passes an invalid env file.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["git clone"], retval=0)
        )  #At this point all system calls are git clones. If that changes this should be updated.
    )
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), [])))
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    buildTracker = PackageBuildTracker()
    mocker.patch('build_feedstock.build_feedstock',
                 side_effect=buildTracker.validate_build_feedstock)
    env_file = os.path.join(test_dir, 'test-env-invalid1.yaml')
    with pytest.raises(OpenCEError) as exc:
        open_ce._main(["build", build_env.COMMAND, env_file])
    assert "Unexpected key chnnels was found in " in str(exc.value)
コード例 #7
0
def test_build_feedstock_working_dir(mocker):
    """
    Tests that the 'working_dir' argument is correctly handled and the original working directory is restored after execution.
    """
    dirTracker = helpers.DirTracker("/test/starting_dir")
    mocker.patch(
        'os.getcwd',
        side_effect=dirTracker.mocked_getcwd
    )
    mocker.patch(
        'os.path.exists',
        return_value=False
    )
    mocker.patch(
        'conda_build.api.build',
        return_value=[]
    )
    mocker.patch(
        'os.chdir',
        side_effect=(lambda x: dirTracker.validate_chdir(x, expected_dirs=["/test/my_work_dir", # First the working directory should be changed to the arg.
                                                                           "/test/starting_dir"])) # And then changed back to the starting directory.
    )

    arg_input = ["--working_directory", "/test/my_work_dir"]
    assert build_feedstock.build_feedstock(arg_input) == 0
コード例 #8
0
def test_build_env_url(mocker):
    '''
    This tests that if a URL is passed in for an env file that it is downloaded.
    I mock urlretrieve to return the test-env-invalid1.yaml file so that I can check
    for the invalid channels identifier, ensuring that the download function was called.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["git clone"], retval=0)
        )  #At this point all system calls are git clones. If that changes this should be updated.
    )
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), [])))
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    buildTracker = PackageBuildTracker()
    mocker.patch('open_ce.build_feedstock.build_feedstock',
                 side_effect=buildTracker.validate_build_feedstock)
    mocker.patch(
        'urllib.request.urlretrieve',
        side_effect=(lambda x, filename=None:
                     (os.path.join(test_dir, os.path.basename(x)), None)))

    env_file = 'https://test.com/test-env-invalid1.yaml'
    with pytest.raises(OpenCEError) as exc:
        opence._main(["build", build_env.COMMAND, env_file])
    assert "Unexpected key chnnels was found in " in str(exc.value)
コード例 #9
0
def test_run_tests(mocker):
    '''
    Test that the _run_tests function works properly.
    '''
    dirTracker = helpers.DirTracker()
    mock_build_tree = TestBuildTree([], "3.6", "cpu,cuda", "openmpi", "10.2")
    mock_test_commands = [
        test_feedstock.TestCommand("Test1",
                                   conda_env="test-conda-env2.yaml",
                                   bash_command="echo Test1"),
        test_feedstock.TestCommand("Test2",
                                   conda_env="test-conda-env2.yaml",
                                   bash_command="[ 1 -eq 2 ]")
    ]

    mocker.patch("open_ce.test_feedstock.gen_test_commands",
                 return_value=mock_test_commands)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    conda_env_files = dict()
    mock_build_tree._test_commands = dict()

    for variant in mock_build_tree._possible_variants:
        conda_env_files[str(variant)] = "tests/test-conda-env2.yaml"
        mock_build_tree._test_feedstocks[str(variant)] = ["feedstock1"]

    # Note: All of the tests should fail, since there isn't a real conda environment to activate
    with pytest.raises(OpenCEError) as exc:
        build_env._run_tests(mock_build_tree, [], conda_env_files)
    assert "There were 4 test failures" in str(exc.value)
コード例 #10
0
def test_build_bad_env(mocker, capsys):
    '''
    This is a negative test of `validate_config` where the env file is bad.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch('os.system', return_value=0)
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    env_file = os.path.join(test_dir, 'test-env-invalid1.yaml')
    assert validate_config.validate_config([
        "--conda_build_config", "./conda_build_config.yaml", env_file,
        "--python_versions", "3.6", "--build_types", "cuda"
    ]) == 1
    captured = capsys.readouterr()
    assert "Error while validating ./conda_build_config.yaml for " in captured.out
    assert "Unexpected key chnnels was found in " in captured.err
コード例 #11
0
def test_get_repo_git_tag_options(mocker, caplog):
    '''
    Test for `_get_repo` that verifies `git_tag` and `git_tag_for_env` priorities.
    '''
    env_file1 = os.path.join(test_dir, 'test-env1.yaml')
    mock_build_tree = TestBuildTree([env_file1], "3.6", "cpu", "openmpi",
                                    "10.2")

    dir_tracker = helpers.DirTracker()
    mocker.patch('os.getcwd', side_effect=dir_tracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dir_tracker.validate_chdir)
    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x, possible_expect=["git clone", "git checkout"])))

    possible_variants = utils.make_variants("3.6", "cpu", "openmpi", "10.2")
    for variant in possible_variants:

        # test-env1.yaml has defined "git_tag" and "git_tag_for_env".
        env_config_data_list = env_config.load_env_config_files([env_file1],
                                                                [variant])
        for env_config_data in env_config_data_list:
            packages = env_config_data.get(env_config.Key.packages.name, [])
            for package in packages:
                _ = mock_build_tree._get_repo(env_config_data, package)
                validate_git_tags(mock_build_tree._git_tag_for_env,
                                  env_config_data, package, caplog)

        # Setting git_tag_for_env in BuildTree should override whatever is in the config file
        mock_build_tree._git_tag_for_env = "test_tag_for_all"
        env_config_data_list = env_config.load_env_config_files([env_file1],
                                                                [variant])
        for env_config_data in env_config_data_list:
            packages = env_config_data.get(env_config.Key.packages.name, [])
            for package in packages:
                _ = mock_build_tree._get_repo(env_config_data, package)
                validate_git_tags(mock_build_tree._git_tag_for_env,
                                  env_config_data, package, caplog)

        # Setting git_tag_for_env in BuildTree back to Default and no git tags
        # specified in the config file too.
        mocker.patch('os.system',
                     return_value=0,
                     side_effect=(lambda x: helpers.validate_cli(
                         x,
                         possible_expect=["git clone", "git apply"],
                         reject=["git checkout"])))

        mock_build_tree._git_tag_for_env = None
        env_file2 = os.path.join(test_dir, 'test-env3.yaml')
        env_config_data_list = env_config.load_env_config_files([env_file2],
                                                                [variant])
        for env_config_data in env_config_data_list:
            packages = env_config_data.get(env_config.Key.packages.name, [])
            for package in packages:
                _ = mock_build_tree._get_repo(env_config_data, package)
                validate_git_tags(mock_build_tree._git_tag_for_env,
                                  env_config_data, package, caplog)
コード例 #12
0
def test_validate_negative(mocker):
    '''
    This is a negative test of `validate_config` where the dry-run fails.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch('os.system', return_value=0)
    mocker.patch(
        'open_ce.utils.run_command_capture',
        side_effect=(
            lambda x: helpers.validate_cli(
                x,
                expect=[
                    "conda create --dry-run",
                    "upstreamdep1 2.3.*",  #Checks that the value from the default config file is used.
                    "external_dep1",  # Checks that the external dependencies were used.
                    "external_dep2 5.2.*",  # Checks that the external dependencies were used.
                    "external_dep3=5.6.*"
                ],  # Checks that the external dependencies were used.
                reject=["package"],
                retval=[False, "", ""])))
    mocker.patch(
        'conda.cli.python_api.run_command',
        side_effect=(
            lambda command, *arguments, **kwargs: conda_search_result()))
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    mocker.patch('conda_build.api.get_output_file_paths',
                 side_effect=(lambda meta, *args, **kwargs: helpers.
                              mock_get_output_file_paths(meta)))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    with pytest.raises(OpenCEError) as err:
        opence._main([
            "validate", validate_config.COMMAND, "--conda_build_config",
            "./conda_build_config.yaml", env_file, "--python_versions", "3.6",
            "--build_types", "cuda"
        ])
    assert "Error validating \"" in str(err.value)
    assert "conda_build_config.yaml\" for " in str(err.value)
    assert "Dependencies are not compatible.\nCommand:\nconda create" in str(
        err.value)
コード例 #13
0
def test_validate_config(mocker):
    '''
    This is a complete test of `validate_config`.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch('os.system', return_value=0)
    mocker.patch(
        'open_ce.utils.run_command_capture',
        side_effect=(
            lambda x: helpers.validate_cli(
                x,
                expect=[
                    "conda create --dry-run", "upstreamdep1 2.3.*",
                    "upstreamdep2 2.*"
                ],
                reject=[
                    "package"
                ],  #No packages from the env files should show up in the create command.
                retval=[True, "", ""])))
    mocker.patch(
        'conda.cli.python_api.run_command',
        side_effect=(
            lambda command, *arguments, **kwargs: conda_search_result()))
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    mocker.patch('conda_build.api.get_output_file_paths',
                 side_effect=(lambda meta, *args, **kwargs: helpers.
                              mock_get_output_file_paths(meta)))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    opence._main([
        "validate", validate_config.COMMAND, "--conda_build_config",
        "./conda_build_config.yaml", env_file, "--python_versions", "3.6",
        "--build_types", "cuda"
    ])
コード例 #14
0
def test_build_env_docker_build_with_build_args(mocker):
    '''
    Tests that passing --docker_build_args argument with docker_build argument works correctly.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('open_ce.docker_build.build_with_docker', return_value=0)

    arg_strings = [
        "build", build_env.COMMAND, "--docker_build", "--docker_build_args",
        "--build-args ENV1=test1 some_setting=1", "my-env.yaml"
    ]
    opence._main(arg_strings)
コード例 #15
0
def test_build_env_docker_build_cuda_versions(mocker):
    '''
    Tests that passing --cuda_versions argument with docker_build argument works correctly.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('open_ce.docker_build.build_with_docker', return_value=0)

    cuda_version = "10.2"
    arg_strings = [
        "build", build_env.COMMAND, "--docker_build", "--cuda_versions",
        cuda_version, "my-env.yaml"
    ]
    opence._main(arg_strings)
    validate_conda_env_files(cuda_versions=cuda_version)
コード例 #16
0
def test_validate_negative(mocker):
    '''
    This is a negative test of `validate_config` where the dry-run fails.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(
                x,
                expect=[
                    "conda create --dry-run",
                    "upstreamdep1 2.3.*",  #Checks that the value from the default config file is used.
                    "external_dep1",  # Checks that the external dependencies were used.
                    "external_dep2 5.2.*",  # Checks that the external dependencies were used.
                    "external_dep3=5.6.*"
                ],  # Checks that the external dependencies were used.
                reject=["package"],
                retval=1,
                ignore=["git clone"])))
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    env_file = os.path.join(test_dir, 'test-env2.yaml')
    with pytest.raises(OpenCEError) as err:
        validate_config.validate_config([
            "--conda_build_config", "./conda_build_config.yaml", env_file,
            "--python_versions", "3.6", "--build_types", "cuda"
        ])
    assert "Error validating \"./conda_build_config.yaml\" for " in str(
        err.value)
コード例 #17
0
def test_create_commands(mocker):
    '''
    Tests that `_create_commands` correctly builds the recipe and extracts all
    of the dependencies from the conda_build render result.
    '''
    dir_tracker = helpers.DirTracker()
    mocker.patch('os.getcwd', return_value="/test/starting_dir")
    render_result = helpers.make_render_result(
        "horovod", ['build_req1', 'build_req2            1.2'],
        ['run_req1            1.3'], ['Host_req1            1.0', 'host_req2'],
        ['test_req1'], ['string1_1'])
    mocker.patch('conda_build.api.render', return_value=render_result)
    mocker.patch('conda_build.api.get_output_file_paths',
                 return_value=['/output/path/linux/horovod.tar.gz'])
    mocker.patch(
        'os.chdir',
        side_effect=(
            lambda x: dir_tracker.validate_chdir(
                x,
                expected_dirs=[
                    "/test/my_repo",  # First the working directory should be changed to the arg.
                    "/test/starting_dir"
                ]))  # And then changed back to the starting directory.
    )

    build_commands = [
        x.build_command for x in build_tree._create_commands(
            "/test/my_repo", "True", "my_recipe_path", None, "main", {
                'python': '3.6',
                'build_type': 'cuda',
                'mpi_type': 'openmpi',
                'cudatoolkit': '10.2'
            }, []).nodes()
    ]
    assert build_commands[0].packages == ['horovod']
    assert build_commands[0].recipe_path == "my_recipe_path"
    for dep in {'build_req1', 'build_req2            1.2'}:
        assert dep in build_commands[0].build_dependencies
    for dep in {'run_req1            1.3'}:
        assert dep in build_commands[0].run_dependencies
    for dep in {'host_req1            1.0', 'host_req2'}:
        assert dep in build_commands[0].host_dependencies
    for dep in {'test_req1'}:
        assert dep in build_commands[0].test_dependencies
コード例 #18
0
def test_validate_config(mocker):
    '''
    This is a complete test of `validate_config`.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(
                x,
                expect=[
                    "conda create --dry-run", "upstreamdep1   2.3.*",
                    "upstreamdep2   2.*"
                ],
                reject=[
                    "package"
                ],  #No packages from the env files should show up in the create command.
                ignore=["git clone"])))
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    env_file = os.path.join(test_dir, 'test-env2.yaml')
    assert validate_config.validate_config([
        "--conda_build_config", "./conda_build_config.yaml", env_file,
        "--python_versions", "3.6", "--build_types", "cuda"
    ]) == 0
コード例 #19
0
def test_create_recipes(mocker):
    '''
    Tests that `_create_recipes` correctly builds the recipe and extracts all
    of the dependencies from the conda_build render result.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch('os.getcwd', return_value="/test/starting_dir")
    render_result = helpers.make_render_result(
        "horovod", ['build_req1', 'build_req2            1.2'],
        ['run_req1            1.3'], ['host_req1            1.0', 'host_req2'],
        ['test_req1'])
    mocker.patch('conda_build.api.render', return_value=render_result)
    mocker.patch(
        'os.chdir',
        side_effect=(
            lambda x: dirTracker.validate_chdir(
                x,
                expected_dirs=[
                    "/test/my_repo",  # First the working directory should be changed to the arg.
                    "/test/starting_dir"
                ]))  # And then changed back to the starting directory.
    )

    create_recipes_result = build_tree._create_recipes(
        "/test/my_repo", None, "master", {
            'python': '3.6',
            'build_type': 'cuda',
            'mpi_type': 'openmpi'
        }, [])
    assert create_recipes_result[0].packages == {'horovod'}
    for dep in {'build_req1', 'build_req2            1.2'}:
        assert dep in create_recipes_result[0].build_dependencies
    for dep in {'run_req1            1.3'}:
        assert dep in create_recipes_result[0].run_dependencies
    for dep in {'host_req1            1.0', 'host_req2'}:
        assert dep in create_recipes_result[0].host_dependencies
    for dep in {'test_req1'}:
        assert dep in create_recipes_result[0].test_dependencies
コード例 #20
0
def test_build_env_container_build_with_container_tool(mocker):
    '''
    Tests that passing --container_tool argument works correctly.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('open_ce.container_build.build_with_container_tool',
                 return_value=0)
    mocker.patch('os.path.exists', return_value=1)

    #with docker_build argument
    arg_strings = [
        "build", build_env.COMMAND, "--docker_build", "--container_tool",
        "podman", "my-env.yaml"
    ]
    opence._main(arg_strings)

    #with container_build argument
    arg_strings = [
        "build", build_env.COMMAND, "--container_build", "--container_tool",
        "podman", "my-env.yaml"
    ]
    opence._main(arg_strings)
コード例 #21
0
def test_build_env(mocker, capsys):
    '''
    This is a complete test of `build_env`.
    It uses `test-env2.yaml` which has a dependency on `test-env1.yaml`, and specifies a chain of package dependencies.
    That chain of package dependencies is used by the mocked build_feedstock to ensure that the order of builds is correct.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(
                x, possible_expect=["git clone", "git checkout"], retval=0)
        )  #At this point all system calls are git clones. If that changes this should be updated.
    )
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    mocker.patch('open_ce.validate_config.validate_build_tree')
    #            +-------+
    #     +------+   15  +-----+
    #     |      +---+---+     |     +-------+
    # +---v---+      |         +----->  16   |
    # |   11  |      |               +---+---+
    # +----+--+      |                   |
    #      |         |     +-------+     |
    #      |         +----->   14  <-----+
    #      |               +-+-----+
    #  +---v---+             |
    #  |  12   |             |
    #  +--+----+             |
    #     |            +-----v--+
    #     +------------>   13   |
    #                  +---+----+
    #                      |
    #                 +----v----+
    #                 |   21    |
    #                 +---------+
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package15"]
    }
    #---The first test specifies a python version that isn't supported in the env file by package21.
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    mocker.patch('conda_build.api.get_output_file_paths',
                 side_effect=(lambda meta, *args, **kwargs: helpers.
                              mock_get_output_file_paths(meta)))

    py_version = "2.0"
    buildTracker = PackageBuildTracker()
    mocker.patch(  # This ensures that 'package21' is not built when the python version is 2.0.
        'open_ce.build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: command.python == py_version),
                            (lambda command: command.recipe !=
                             "package21-feedstock")])))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    opence._main([
        "build", build_env.COMMAND, env_file, "--python_versions", py_version,
        "--run_tests"
    ])
    validate_conda_env_files(py_version)

    #---The second test specifies a python version that is supported in the env file by package21.
    py_version = "2.1"
    channel = "my_channel"
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    buildTracker = PackageBuildTracker()
    mocker.patch(
        'open_ce.build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: command.python == py_version and
                             channel in command.channels)])))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    opence._main([
        "build", build_env.COMMAND, env_file, "--python_versions", py_version,
        "--channels", channel
    ])
    validate_conda_env_files(py_version)

    #---The third test verifies that the repository_folder argument is working properly.
    buildTracker = PackageBuildTracker()
    mocker.patch(
        'open_ce.build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: command.repository.startswith(
                    "repo_folder"))])))
    py_version = "2.1"
    env_file = os.path.join(test_dir, 'test-env2.yaml')
    opence._main([
        "build", build_env.COMMAND, env_file, "--repository_folder",
        "repo_folder", "--python_versions", py_version
    ])
    validate_conda_env_files(py_version)

    #---The fourth test verifies that builds are skipped properly if they already exist.
    mocker.patch('open_ce.build_env._all_outputs_exist', return_value=True)

    captured = capsys.readouterr()
    opence._main(["build", build_env.COMMAND, env_file])
    captured = capsys.readouterr()
    assert "Skipping build of" in captured.out
    mocker.patch('open_ce.build_env._all_outputs_exist', return_value=False)

    #---The fifth test specifies a cuda version that isn't supported in the env file by package21.
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    mocker.patch('conda_build.api.get_output_file_paths',
                 side_effect=(lambda meta, *args, **kwargs: helpers.
                              mock_get_output_file_paths(meta)))

    cuda_version = "9.1"
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package15"]
    }
    buildTracker = PackageBuildTracker()
    mocker.patch(  # This ensures that 'package21' is not built when the cuda version is 9.1
        'open_ce.build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: command.recipe !=
                             "package21-feedstock")])))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    opence._main([
        "build", build_env.COMMAND, env_file, "--cuda_versions", cuda_version,
        "--run_tests"
    ])
    validate_conda_env_files(cuda_versions=cuda_version)

    #---The sixth test specifies a cuda version that is supported in the env file by package21.
    cuda_version = "9.2"
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    buildTracker = PackageBuildTracker()
    mocker.patch(
        'open_ce.build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: command.cudatoolkit ==
                             cuda_version)])))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    opence._main([
        "build", build_env.COMMAND, env_file, "--cuda_versions", cuda_version
    ])
    validate_conda_env_files(cuda_versions=cuda_version)

    #---The seventh test specifies specific packages that should be built (plus their dependencies)
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    buildTracker = PackageBuildTracker()
    mocker.patch(
        'open_ce.build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: not command.recipe in [
                    "package11-feedstock", "package12-feedstock",
                    "package13-feedstock", "package21-feedstock",
                    "package22-feedstock"
                ])])))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    captured = capsys.readouterr()
    opence._main([
        "build", build_env.COMMAND, env_file, "--python_versions", py_version,
        "--packages", "package14,package35"
    ])
    captured = capsys.readouterr()
    assert "No recipes were found for package35" in captured.out

    #---The eighth test makes sure that relative URL paths work.
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package15"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    buildTracker = PackageBuildTracker()
    mocker.patch('open_ce.build_feedstock.build_feedstock_from_command',
                 side_effect=(lambda x, *args, **kwargs: buildTracker.
                              validate_build_feedstock(x, package_deps)))
    mocker.patch(
        'urllib.request.urlretrieve',
        side_effect=(lambda x, filename=None:
                     (os.path.join(test_dir, os.path.basename(x)), None)))

    env_file = 'https://test.com/test-env2.yaml'
    opence._main(["build", build_env.COMMAND, env_file])
コード例 #22
0
ファイル: build_env_test.py プロジェクト: npanpaliya/open-ce
def test_build_env(mocker, capsys):
    '''
    This is a complete test of `build_env`.
    It uses `test-env2.yaml` which has a dependency on `test-env1.yaml`, and specifies a chain of package dependencies.
    That chain of package dependencies is used by the mocked build_feedstock to ensure that the order of builds is correct.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(
                x, possible_expect=["git clone", "git checkout"], retval=0)
        )  #At this point all system calls are git clones. If that changes this should be updated.
    )
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    mocker.patch('validate_config.validate_env_config')
    #            +-------+
    #     +------+   15  +-----+
    #     |      +---+---+     |     +-------+
    # +---v---+      |         +----->  16   |
    # |   11  |      |               +---+---+
    # +----+--+      |                   |
    #      |         |     +-------+     |
    #      |         +----->   14  <-----+
    #      |               +-+-----+
    #  +---v---+             |
    #  |  12   |             |
    #  +--+----+             |
    #     |            +-----v--+
    #     +------------>   13   |
    #                  +---+----+
    #                      |
    #                 +----v----+
    #                 |   21    |
    #                 +---------+
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package15"]
    }
    #---The first test specifies a python version that isn't supported in the env file by package21.
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    mocker.patch('conda_build.api.get_output_file_paths',
                 side_effect=(lambda meta, *args, **kwargs: helpers.
                              mock_get_output_file_paths(meta)))

    py_version = "2.0"
    buildTracker = PackageBuildTracker()
    mocker.patch(  # This ensures that 'package21' is not built when the python version is 2.0.
        'build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: command.python == py_version),
                            (lambda command: command.recipe !=
                             "package21-feedstock")])))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    open_ce._main([
        "build", build_env.COMMAND, env_file, "--python_versions", py_version,
        "--run_tests"
    ])
    validate_conda_env_files(py_version)

    #---The second test specifies a python version that is supported in the env file by package21.
    py_version = "2.1"
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    buildTracker = PackageBuildTracker()
    mocker.patch(
        'build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: command.python == py_version)])))

    env_file = os.path.join(test_dir, 'test-env2.yaml')
    open_ce._main([
        "build", build_env.COMMAND, env_file, "--python_versions", py_version
    ])
    validate_conda_env_files(py_version)

    #---The third test verifies that the repository_folder argument is working properly.
    buildTracker = PackageBuildTracker()
    mocker.patch(
        'build_feedstock.build_feedstock_from_command',
        side_effect=(
            lambda x, *args, **kwargs: buildTracker.validate_build_feedstock(
                x,
                package_deps,
                conditions=[(lambda command: command.repository.startswith(
                    "repo_folder"))])))
    py_version = "2.1"
    env_file = os.path.join(test_dir, 'test-env2.yaml')
    open_ce._main([
        "build", build_env.COMMAND, env_file, "--repository_folder",
        "repo_folder", "--python_versions", py_version
    ])
    validate_conda_env_files(py_version)

    #---The fourth test verifies that builds are skipped properly if they already exist.
    mocker.patch('build_env._all_outputs_exist', return_value=True)

    captured = capsys.readouterr()
    open_ce._main(["build", build_env.COMMAND, env_file])
    captured = capsys.readouterr()
    assert "Skipping build of" in captured.out
コード例 #23
0
ファイル: build_env_test.py プロジェクト: dllehr81/open-ce
def test_build_env(mocker):
    '''
    This is a complete test of `build_env`.
    It uses `test-env2.yaml` which has a dependency on `test-env1.yaml`, and specifies a chain of package dependencies.
    That chain of package dependencies is used by the mocked build_feedstock to ensure that the order of builds is correct.
    '''
    dirTracker = helpers.DirTracker()
    mocker.patch(
        'os.mkdir',
        return_value=0  #Don't worry about making directories.
    )
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["git clone"], retval=0)
        )  #At this point all system calls are git clones. If that changes this should be updated.
    )
    mocker.patch('os.getcwd', side_effect=dirTracker.mocked_getcwd)
    mocker.patch('os.chdir', side_effect=dirTracker.validate_chdir)
    #            +-------+
    #     +------+   15  +-----+
    #     |      +---+---+     |     +-------+
    # +---v---+      |         +----->  16   |
    # |   11  |      |               +---+---+
    # +----+--+      |                   |
    #      |         |     +-------+     |
    #      |         +----->   14  <-----+
    #      |               +-+-----+
    #  +---v---+             |
    #  |  12   |             |
    #  +--+----+             |
    #     |            +-----v--+
    #     +------------>   13   |
    #                  +---+----+
    #                      |
    #                 +----v----+
    #                 |   21    |
    #                 +---------+
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package15"]
    }
    #---The first test specifies a python version that isn't supported in the env file by package21.
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    buildTracker = PackageBuildTracker()
    mocker.patch(  # This ensures that 'package21' is not built when the python version is 2.0.
        'build_feedstock.build_feedstock',
        side_effect=(lambda x: buildTracker.validate_build_feedstock(
            x,
            package_deps,
            expect=["--python_versions 2.0"],
            reject=["package21-feedstock"])))
    env_file = os.path.join(test_dir, 'test-env2.yaml')
    assert build_env.build_env([env_file, "--python_versions", "2.0"]) == 0

    #---The second test specifies a python version that is supported in the env file by package21.
    package_deps = {
        "package11": ["package15"],
        "package12": ["package11"],
        "package13": ["package12", "package14"],
        "package14": ["package15", "package16"],
        "package15": [],
        "package16": ["package15"],
        "package21": ["package13"],
        "package22": ["package21"]
    }
    mocker.patch('conda_build.api.render',
                 side_effect=(lambda path, *args, **kwargs: helpers.
                              mock_renderer(os.getcwd(), package_deps)))
    buildTracker = PackageBuildTracker()
    mocker.patch('build_feedstock.build_feedstock',
                 side_effect=(lambda x: buildTracker.validate_build_feedstock(
                     x, package_deps, expect=["--python_versions 2.1"])))
    env_file = os.path.join(test_dir, 'test-env2.yaml')
    assert build_env.build_env([env_file, "--python_versions", "2.1"]) == 0

    #---The third test verifies that the repository_folder argument is working properly.
    buildTracker = PackageBuildTracker()
    mocker.patch(
        'build_feedstock.build_feedstock',
        side_effect=(lambda x: buildTracker.validate_build_feedstock(
            x, package_deps, expect=["--working_directory repo_folder/"])))
    env_file = os.path.join(test_dir, 'test-env2.yaml')
    assert build_env.build_env([
        env_file, "--repository_folder", "repo_folder", "--python_versions",
        "2.1"
    ]) == 0