예제 #1
0
def test_create_recipes(mocker, capsys):
    '''
    Tests that `_create_recipes` correctly builds the recipe and extracts all
    of the dependencies from the conda_build render result.
    '''
    mocker.patch('os.getcwd', return_value="/test/starting_dir")
    render_result = 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: helpers.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_env._create_recipes("/test/my_repo", None,
                                                      "master", "master", [])
    assert create_recipes_result[0].get('packages') == {'horovod'}
    for dep in {'build_req1', 'build_req2            1.2'}:
        assert dep in create_recipes_result[0].get('build_dependencies')
    for dep in {'run_req1            1.3'}:
        assert dep in create_recipes_result[0].get('run_dependencies')
    for dep in {'host_req1            1.0', 'host_req2'}:
        assert dep in create_recipes_result[0].get('host_dependencies')
    for dep in {'test_req1'}:
        assert dep in create_recipes_result[0].get('test_dependencies')
def test_build_feedstock_working_dir(mocker, capsys):
    """
    Tests that the 'working_dir' argument is correctly handled and the original working directory is restored after execution.
    """
    mocker.patch('os.getcwd', side_effect=helpers.mocked_getcwd)
    mocker.patch('os.path.exists', return_value=False)
    mocker.patch(
        'os.system',
        side_effect=(
            lambda x: helpers.validate_cli(x, expect=["conda-build"])))
    mocker.patch(
        'os.chdir',
        side_effect=(
            lambda x: helpers.validate_chdir(
                x,
                expected_dirs=[
                    "/test/my_work_dir",  # First the working directory should be changed to the arg.
                    "/test/test_recipe"
                ]))  # And then changed back to the starting directory.
    )

    arg_input = ["--working_directory", "/test/my_work_dir"]
    assert build_feedstock.build_feedstock(arg_input) == 0