示例#1
0
def test_build_image(mocker):
    '''
    Simple test for build_image
    '''
    mocker.patch('os.getuid', return_value=1234)
    mocker.patch('os.getgid', return_value=5678)

    #CUDA build
    cuda_version = "11.0"
    intended_image_name = docker_build.REPO_NAME + ":" + docker_build.IMAGE_NAME + "-cuda" + cuda_version + "-1234"

    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x, expect=["docker build", "-t " + intended_image_name])))

    assert docker_build.build_image("test", "test",
                                    cuda_version) == intended_image_name

    #CPU build
    intended_image_name = docker_build.REPO_NAME + ":" + docker_build.IMAGE_NAME + "-cpu" + "-1234"

    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x, expect=["docker build", "-t " + intended_image_name])))
    assert docker_build.build_image("test", "test") == intended_image_name
示例#2
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)
示例#3
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)
示例#4
0
def test_channel_update_in_conda_env(mocker):
    '''
    Test to see if channel is being updated in the conda env file before passing to build_runtime_image
    '''

    intended_image_name = build_image.REPO_NAME + ":" + build_image.IMAGE_NAME

    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x, expect=["docker build", "-t " + intended_image_name])))

    channel_index_before, _ = get_channel_being_modified(
        "tests/test-conda-env.yaml")

    arg_strings = [
        "build", build_image.COMMAND, "--local_conda_channel",
        os.path.join(test_dir, "testcondabuild"), "--conda_env_file",
        "tests/test-conda-env.yaml"
    ]
    opence._main(arg_strings)

    # We copy conda environment file to the passed local conda channel before updating it
    channel_index_after, channel_modified = get_channel_being_modified(
        "tests/testcondabuild/test-conda-env.yaml")

    assert channel_modified == "file:/{}".format(build_image.TARGET_DIR)
    assert channel_index_before == channel_index_after

    # Cleanup
    os.remove("tests/testcondabuild/test-conda-env.yaml")
def test_build_feedstock_default_config_file(mocker, capsys):
    """
    Tests that the default config file is loaded when no argument is specified.
    """
    mocker.patch('os.getcwd', return_value="/test/test_recipe")
    mocker.patch(
        'os.path.exists',
        return_value=True  #True for default config file.
    )
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(
                x, expect=["conda-build", "variants_from_default_config"])
        )  #Checks that the value from the default config file is used.
    )

    test_recipe_config = b"""recipes:
    - name : my_variant
      path: variants_from_default_config"""

    mocker.patch('builtins.open',
                 mocker.mock_open(read_data=test_recipe_config))

    arg_input = []
    assert build_feedstock.build_feedstock(arg_input) == 0
示例#6
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)
示例#7
0
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)
def test_build_image_positive_case(mocker):
    '''
    Simple test for build_runtime_image
    '''
    open_ce_version = "open-ce-1.1.0"

    mocker.patch('open_ce.utils.get_open_ce_version',
                 return_value=open_ce_version)

    intended_image_name = build_image.REPO_NAME + ":" + open_ce_version + TEST_IMAGE_NAME_SUFFIX
    container_tool = utils.DEFAULT_CONTAINER_TOOL

    mocker.patch(
        'os.system',
        return_value=0,
        side_effect=(lambda x: helpers.validate_cli(
            x,
            expect=
            ["{} build".format(container_tool), "-t " + intended_image_name])))

    arg_strings = [
        "build", build_image.COMMAND, "--local_conda_channel",
        TEST_LOCAL_CONDA_CHANNEL_DIR, "--conda_env_file", TEST_CONDA_ENV_FILE
    ]
    opence._main(arg_strings)
def test_build_feedstock_config_file(mocker, capsys):
    """
    Tests that the 'recipe_config_file' argument is correctly handled..
    """
    mocker.patch('os.getcwd', return_value="/test/test_recipe")
    mocker.patch(
        'os.path.exists',
        return_value=
        True  # 'path.exists' is mocked as true so that the input file is found to exist.
    )
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(
                x, expect=["conda-build", "variants_from_config"])
        )  #Checks that the value from the input config file is used.
    )

    #This is the data that is read in when 'open()' is called.
    test_recipe_config = b"""recipes:
    - name : my_variant
      path: variants_from_config"""

    mocker.patch('builtins.open',
                 mocker.mock_open(read_data=test_recipe_config))

    arg_input = ["--recipe-config-file", "my_config.yml"]
    assert build_feedstock.build_feedstock(arg_input) == 0
示例#10
0
def test_env_validate(mocker, capsys):
    '''
    This is a negative test of `build_env`, which passes an invalid env file.
    '''
    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=helpers.mocked_getcwd
    )
    mocker.patch(
        'conda_build.api.render',
        side_effect=(lambda path, *args, **kwargs: helpers.mock_renderer(os.getcwd(), package_deps))
    )
    mocker.patch(
        'os.chdir',
        side_effect=helpers.validate_chdir
    )
    mocker.patch(
        'build_feedstock.build_feedstock',
        side_effect=(lambda x: validate_build_feedstock(x))
    )
    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
示例#11
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
def test_channel_update_in_conda_env(mocker):
    '''
    Test to see if channel is being updated in the conda env file before passing to build_runtime_image
    '''

    open_ce_version = utils.get_open_ce_version(TEST_CONDA_ENV_FILE)
    intended_image_name = build_image.REPO_NAME + ":" + open_ce_version + TEST_IMAGE_NAME_SUFFIX
    container_tool = utils.DEFAULT_CONTAINER_TOOL
    mocker.patch(
        'os.system',
        return_value=0,
        side_effect=(lambda x: helpers.validate_cli(
            x,
            expect=
            ["{} build".format(container_tool), "-t " + intended_image_name])))
    mocker.patch('os.remove', return_value=0)
    mocker.patch('shutil.rmtree', return_value=1)
    channel_index_before, _ = get_channel_being_modified(TEST_CONDA_ENV_FILE)

    arg_strings = [
        "build", build_image.COMMAND, "--local_conda_channel",
        TEST_LOCAL_CONDA_CHANNEL_DIR, "--conda_env_file", TEST_CONDA_ENV_FILE
    ]
    opence._main(arg_strings)

    # We copy conda environment file to the passed local conda channel before updating it
    channel_index_after, channel_modified = get_channel_being_modified(
        os.path.join(TEST_LOCAL_CONDA_CHANNEL_DIR, build_image.TEMP_FILES,
                     "test-conda-env-runtime.yaml"))

    assert channel_modified == "file:/{}".format(build_image.TARGET_DIR)
    assert channel_index_before == channel_index_after
示例#13
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)
示例#14
0
def test_create_container(mocker):
    '''
    Simple test for _create_container
    '''
    mocker.patch('os.getcwd', return_value='/my_dir')
    mocker.patch('os.path.isdir', return_value=False)
    mocker.patch('os.mkdir')

    container_name = "my_container"
    image_name = "my_image"
    output_folder = "condabuild"
    env_folders = ["/test/my_envs"]

    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x,
                     expect=[
                         docker_build.DOCKER_TOOL + " create", "--name " +
                         container_name, "-v /my_dir/" + output_folder,
                         "-v /test/my_envs", image_name
                     ])))

    docker_build._create_container(container_name, image_name, output_folder,
                                   env_folders)
示例#15
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)
示例#16
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"
    ])
示例#17
0
def test_clone_repo_failure(mocker, capsys):
    '''
    Simple negative test for `_clone_repo`.
    '''
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["git clone"], retval=1)))

    assert build_env._clone_repo(build_env.DEFAULT_GIT_LOCATION,
                                 "/test/my_repo", None, "master", None) == 1
    captured = capsys.readouterr()
    assert "Unable to clone repository" in captured.out
示例#18
0
def test_execute_in_container(mocker):
    '''
    Simple test for _execute_in_container
    '''
    container = "my_container"
    command = "my_script.py arg1 arg2"

    mocker.patch(
        'os.system',
        return_value=0,
        side_effect=(lambda x: helpers.validate_cli(x, expect=[docker_build.DOCKER_TOOL + " exec " + container,
                                                               "my_script.py arg1 arg2"])))

    assert docker_build._execute_in_container(container, command) == 0
示例#19
0
def test_clone_repo_failure(mocker):
    '''
    Simple negative test for `_clone_repo`.
    '''
    mock_build_tree = TestBuildTree([], "3.6", "cpu", "openmpi")

    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)
示例#20
0
def test_copy_to_container(mocker):
    '''
    Simple test for _copy_to_container
    '''
    src = "my_src"
    dest = "my_dest"
    container = "my_container"

    mocker.patch(
        'os.system',
        return_value=0,
        side_effect=(lambda x: helpers.validate_cli(
            x, expect=[docker_build.DOCKER_TOOL + " cp", container + ":"])))

    docker_build._copy_to_container(src, dest, container)
示例#21
0
def test_clone_repo_failure(mocker, capsys):
    '''
    Simple negative test for `_clone_repo`.
    '''
    mock_build_tree = TestBuildTree([], "3.6", "cpu", "openmpi")

    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["git clone"], retval=1)))

    assert mock_build_tree._clone_repo("https://bad_url", "/test/my_repo",
                                       None, "master") == 1
    captured = capsys.readouterr()
    assert "Unable to clone repository" in captured.out
示例#22
0
def test_build_image(mocker):
    '''
    Simple test for build_image
    '''
    mocker.patch('os.getuid', return_value=1234)
    mocker.patch('os.getgid', return_value=5678)

    intended_image_name = docker_build.REPO_NAME + ":" + docker_build.IMAGE_NAME + "-1234"

    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x, expect=["docker build", "-t " + intended_image_name])))

    assert docker_build._build_image() == intended_image_name
示例#23
0
def test_clone_repo(mocker):
    '''
    Simple positive test for `_clone_repo`.
    '''
    git_location = build_env.DEFAULT_GIT_LOCATION

    mocker.patch('os.system',
                 side_effect=(lambda x: helpers.validate_cli(
                     x,
                     expect=[
                         "git clone", "-b master", "--single-branch",
                         git_location + "/my_repo.git", "/test/my_repo"
                     ])))

    assert build_env._clone_repo(git_location, "/test/my_repo", None, "master",
                                 "master") == 0
def test_build_feedstock_default(mocker):
    """
    Tests that the default arguments for 'build_feedstock' generate the correct 'conda-build' command.
    """
    mocker.patch('os.getcwd', return_value="/test/test_recipe")
    mocker.patch('os.path.exists', return_value=False)
    mocker.patch('os.system',
                 side_effect=(lambda x: helpers.validate_cli(
                     x,
                     expect=[
                         "conda-build", "--output-folder condabuild",
                         "conda_build_config.yaml", "recipe"
                     ])))

    arg_input = []
    assert build_feedstock.build_feedstock(arg_input) == 0
示例#25
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)
示例#26
0
def test_build_image_positive_case(mocker):
    '''
    Simple test for build_runtime_image
    '''
    intended_image_name = build_image.REPO_NAME + ":" + build_image.IMAGE_NAME

    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x, expect=["docker build", "-t " + intended_image_name])))

    arg_strings = [
        "build", build_image.COMMAND, "--local_conda_channel",
        "tests/testcondabuild", "--conda_env_file", "tests/test-conda-env.yaml"
    ]
    opence._main(arg_strings)
    os.remove("tests/testcondabuild/test-conda-env.yaml")
def test_build_feedstock_failure(mocker, capsys):
    """
    Tests that a 'conda-build' failure is handled correctly.
    """
    mocker.patch('os.getcwd', return_value="/test/test_recipe")
    mocker.patch('os.path.exists', return_value=False)
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["conda-build"], retval=1)
        )  # Retval is 1 to simulate a failure.
    )

    arg_input = ""
    assert build_feedstock.build_feedstock(arg_input) == 1
    captured = capsys.readouterr()
    assert "Failure building recipe: test_recipe" in captured.out
示例#28
0
def test_local_conda_channel_with_absolute_path(mocker):
    '''
    Test for build_runtime_image with local conda channel with its absolute path
    '''
    intended_image_name = build_image.REPO_NAME + ":" + build_image.IMAGE_NAME

    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x, expect=["docker build", "-t " + intended_image_name])))

    arg_strings = [
        "build", build_image.COMMAND, "--local_conda_channel",
        os.path.join(test_dir, "testcondabuild"), "--conda_env_file",
        "tests/test-conda-env.yaml"
    ]
    opence._main(arg_strings)
    os.remove("tests/testcondabuild/test-conda-env.yaml")
示例#29
0
def test_clone_repo(mocker):
    '''
    Simple positive test for `_clone_repo`.
    '''
    git_location = build_tree.DEFAULT_GIT_LOCATION

    mock_build_tree = TestBuildTree([], "3.6", "cpu")

    mocker.patch('os.system',
                 return_value=0,
                 side_effect=(lambda x: helpers.validate_cli(
                     x,
                     expect=[
                         "git clone", "-b master", "--single-branch",
                         git_location + "/my_repo.git", "/test/my_repo"
                     ])))

    assert mock_build_tree._clone_repo("/test/my_repo", None, "master") == 0
示例#30
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