def test_build_feedstock_default_config_file(mocker): """ 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. ) expect_recipe = os.path.join( os.getcwd(), 'variants_from_default_config' ) #Checks that the value from the default config file is used. mocker.patch( 'conda_build.api.build', side_effect=(lambda x, **kwargs: helpers.validate_conda_build_args( x, expect_recipe=expect_recipe, **kwargs))) test_recipe_config = { 'recipes': [{ 'name': 'my_variant', 'path': 'variants_from_default_config' }] } mocker.patch('open_ce.conda_utils.render_yaml', return_value=test_recipe_config) opence._main(["build", build_feedstock.COMMAND])
def test_build_feedstock_config_file(mocker): """ 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. ) expect_recipe = os.path.join(os.getcwd(),'variants_from_config') #Checks that the value from the input config file is used. mocker.patch( 'conda_build.api.build', side_effect=(lambda x, **kwargs: helpers.validate_conda_build_args(x, expect_recipe=expect_recipe, **kwargs)) ) #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
def test_build_feedstock_default_config_file(mocker): """ 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. ) expect_recipe = os.path.join(os.getcwd(),'variants_from_default_config')#Checks that the value from the default config file is used. mocker.patch( 'conda_build.api.build', side_effect=(lambda x, **kwargs: helpers.validate_conda_build_args(x, expect_recipe=expect_recipe, **kwargs)) ) 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
def test_build_feedstock_extra_args(mocker): """ Tests that additional arguments add the expected values to the 'conda_build.api.build' arguments. """ mocker.patch('os.getcwd', return_value="/test/test_recipe") mocker.patch('os.path.exists', return_value=True) expect_config = { 'channel_urls': [ '/test/test_recipe/condabuild', 'test_channel', 'test_channel_2', 'test_channel_from_config' ] } expect_variants = { 'python': '3.6', 'build_type': 'cpu', 'mpi_type': 'openmpi' } reject_recipe = os.path.join(os.getcwd(), 'test_recipe_extra') mocker.patch( 'conda_build.api.build', side_effect=(lambda x, **kwargs: helpers.validate_conda_build_args( x, expect_config=expect_config, expect_variants=expect_variants, reject_recipe=reject_recipe, **kwargs))) test_recipe_config = { 'recipes': [{ 'name': 'my_project', 'path': 'recipe' }, { 'name': 'my_variant', 'path': 'variants' }, { 'name': 'test_recipe_extra', 'path': 'extra' }], 'channels': ['test_channel_from_config'] } mocker.patch('open_ce.conda_utils.render_yaml', return_value=test_recipe_config) arg_input = [ "build", build_feedstock.COMMAND, "--channels", "test_channel", "--channels", "test_channel_2", "--recipes", "my_project,my_variant", "--python_versions", "3.6", "--build_types", "cpu", "--mpi_types", "openmpi", "--cuda_versions", "10.2" ] opence._main(arg_input)
def test_build_feedstock_config_file(mocker): """ Tests that the 'recipe_config_file' argument is correctly handled.. """ expect_recipe = os.path.join( os.getcwd(), 'cuda_recipe_path' ) #Checks that the value from the input config file is used. mocker.patch( 'conda_build.api.build', side_effect=(lambda x, **kwargs: helpers.validate_conda_build_args( x, expect_recipe=expect_recipe, **kwargs))) opence._main([ "build", build_feedstock.COMMAND, "--recipe-config-file", os.path.join(test_dir, "my_config.yaml"), "--build_type", "cuda" ])
def test_build_feedstock_extra_args(mocker): """ Tests that additional arguments add the expected values to the 'conda_build.api.build' arguments. """ mocker.patch( 'os.getcwd', return_value="/test/test_recipe" ) mocker.patch( 'os.path.exists', return_value=True ) expect_config = { 'channel_urls' : ['test_channel', 'test_channel_2', 'test_channel_from_config']} expect_variants = {'python': '3.6', 'build_type': 'cpu', 'mpi_type': 'openmpi'} reject_recipe = os.path.join(os.getcwd,'test_recipe_extra') mocker.patch( 'conda_build.api.build', side_effect=(lambda x, **kwargs: helpers.validate_conda_build_args(x, expect_config=expect_config, expect_variants=expect_variants, reject_recipe=reject_recipe, **kwargs)) ) test_recipe_config =b"""recipes: - name : my_project path : recipe - name : my_variant path: variants - name : test_recipe_extra path: extra channels: - test_channel_from_config""" mocker.patch( 'builtins.open', mocker.mock_open(read_data=test_recipe_config) ) arg_input = ["--channels", "test_channel", "--channels", "test_channel_2", "--recipes", "my_project,my_variant", "--python_versions", "3.6", "--build_types", "cpu", "--mpi_types", "openmpi"] assert build_feedstock.build_feedstock(arg_input) == 0
def test_recipe_config_file_for_inapplicable_configuration(mocker, capsys): """ Tests the case when build is triggered for a configuration for which no recipes are applicable. """ expect_recipe = os.path.join( os.getcwd(), 'cuda_recipe_path' ) #Checks that the value from the input config file is used. mocker.patch( 'conda_build.api.build', side_effect=(lambda x, **kwargs: helpers.validate_conda_build_args( x, expect_recipe=expect_recipe, **kwargs))) opence._main([ "build", build_feedstock.COMMAND, "--recipe-config-file", os.path.join(test_dir, "my_config.yaml"), "--python_versions", "4.1" ]) captured = capsys.readouterr() assert "INFO: No recipe to build for given configuration." in captured.out
def test_build_feedstock_default(mocker): """ Tests that the default arguments for 'build_feedstock' generate the correct 'conda_build.api.build' input args. """ mocker.patch('os.getcwd', return_value="/test/test_recipe") mocker.patch('os.path.exists', return_value=False) expect_recipe = os.path.join(os.getcwd(), 'recipe') expect_config = { 'variant_config_files': [], 'output_folder': utils.DEFAULT_OUTPUT_FOLDER } mocker.patch( 'conda_build.api.build', side_effect=(lambda x, **kwargs: helpers.validate_conda_build_args( x, expect_recipe=expect_recipe, expect_config=expect_config, **kwargs))) opence._main(["build", build_feedstock.COMMAND])