def single_upload(): """ Creates a randomly-named recipe and uploads it using a label so that it doesn't affect the main bioconda channel. Tests that depend on this fixture get a tuple of name, pakage, recipe dir. Cleans up when it's done. """ name = 'upload-test-' + str(uuid.uuid4()).split('-')[0] r = Recipes(''' {0}: meta.yaml: | package: name: {0} version: "0.1" '''.format(name), from_string=True) r.write_recipes() env_matrix = list(utils.EnvMatrix(tmp_env_matrix()))[0] build.build( recipe=r.recipe_dirs[name], recipe_folder='.', docker_builder=None, mulled_test=False, env=env_matrix, ) pkg = utils.built_package_path(r.recipe_dirs[name]) upload.anaconda_upload(pkg, label=TEST_LABEL) yield (name, pkg, r.recipe_dirs[name]) p = sp.run([ 'anaconda', '-t', os.environ.get('ANACONDA_TOKEN'), 'remove', 'bioconda/{0}'.format(name), '--force' ], stdout=sp.PIPE, stderr=sp.STDOUT, check=True, universal_newlines=True)
def test_pkgname_with_numpy_x_x(): r = Recipes( """ one: meta.yaml: | package: name: one version: "0.1" requirements: run: - python - numpy x.x build: - python - numpy x.x """, from_string=True) r.write_recipes() os.environ['CONDA_NPY'] = '1.9' assert os.path.basename( utils.built_package_path(r.recipe_dirs['one'], env=os.environ) ) == 'one-0.1-np19py35_0.tar.bz2'
def test_build_empty_extra_container(): r = Recipes(""" one: meta.yaml: | package: name: one version: 0.1 extra: container: # empty """, from_string=True) r.write_recipes() build_result = build.build( recipe=r.recipe_dirs['one'], recipe_folder='.', env={}, mulled_test=True, ) assert build_result.success pkg = utils.built_package_path(r.recipe_dirs['one']) assert os.path.exists(pkg) ensure_missing(pkg)
def test_rendering_sandboxing(): r = Recipes(""" one: meta.yaml: | package: name: one version: 0.1 extra: var: {{ GITHUB_TOKEN }} """, from_string=True) r.write_recipes() env = { # First one is allowed, others are not 'CONDA_ARBITRARY_VAR': 'conda-val-here', 'TRAVIS_ARBITRARY_VAR': 'travis-val-here', 'GITHUB_TOKEN': 'asdf', 'BUILDKITE_TOKEN': 'asdf', } # If GITHUB_TOKEN is already set in the bash environment, then we get # a message on stdout+stderr (this is the case on travis-ci). # # However if GITHUB_TOKEN is not already set in the bash env (e.g., when # testing locally), then we get a SystemError. # # In both cases we're passing in the `env` dict, which does contain # GITHUB_TOKEN. if 'GITHUB_TOKEN' in os.environ: with pytest.raises(sp.CalledProcessError) as excinfo: res = build.build( recipe=r.recipe_dirs['one'], recipe_folder='.', env=env, mulled_test=False, _raise_error=True, ) assert ("Undefined Jinja2 variables remain (['GITHUB_TOKEN']). " "Please enable source downloading and try again.") in str( excinfo.value.stdout) else: # recipe for "one" should fail because GITHUB_TOKEN is not a jinja var. with pytest.raises(SystemExit) as excinfo: res = build.build(recipe=r.recipe_dirs['one'], recipe_folder='.', env=env, mulled_test=False) assert "'GITHUB_TOKEN' is undefined" in str(excinfo.value) r = Recipes(""" two: meta.yaml: | package: name: two version: 0.1 extra: var2: {{ CONDA_ARBITRARY_VAR }} """, from_string=True) r.write_recipes() pkg = utils.built_package_path(r.recipe_dirs['two'], env=env) ensure_missing(pkg) res = build.build(recipe=r.recipe_dirs['two'], recipe_folder='.', env=env, mulled_test=False) t = tarfile.open(pkg) tmp = tempfile.mkdtemp() target = 'info/recipe/meta.yaml' t.extract(target, path=tmp) contents = yaml.load(open(os.path.join(tmp, target)).read()) assert contents['extra']['var2'] == 'conda-val-here', contents