Пример #1
0
def test_env_sandboxing():
    r = Recipes(
        """
        one:
          meta.yaml: |
            package:
              name: one
              version: 0.1
          build.sh: |
            #!/bin/bash
            if [[ -z $GITHUB_TOKEN ]]
            then
                exit 0
            else
                echo "\$GITHUB_TOKEN has leaked into the build environment!"
                exit 1
            fi
    """, from_string=True)
    r.write_recipes()
    pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])

    with utils.temp_env({'GITHUB_TOKEN': 'token_here'}):
        build.build(
            recipe=r.recipe_dirs['one'],
            recipe_folder='.',
            pkg_paths=pkg_paths,
            mulled_test=False
        )

    for pkg in pkg_paths:
        assert os.path.exists(pkg)
        ensure_missing(pkg)
Пример #2
0
def test_env_sandboxing():
    r = Recipes(
        """
        one:
          meta.yaml: |
            package:
              name: one
              version: 0.1
          build.sh: |
            #!/bin/bash
            if [[ -z $GITHUB_TOKEN ]]
            then
                exit 0
            else
                echo "\$GITHUB_TOKEN has leaked into the build environment!"
                exit 1
            fi
    """, from_string=True)
    r.write_recipes()
    pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])

    with utils.temp_env({'GITHUB_TOKEN': 'token_here'}):
        build.build(
            recipe=r.recipe_dirs['one'],
            recipe_folder='.',
            pkg_paths=pkg_paths,
            mulled_test=False
        )

    for pkg in pkg_paths:
        assert os.path.exists(pkg)
        ensure_missing(pkg)
Пример #3
0
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])

    with utils.temp_env(
            dict(TRAVIS_BRANCH='master', TRAVIS_PULL_REQUEST='false')):
        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)
Пример #4
0
 def test_subdags_more_than_recipes(self, caplog, recipes_fixture, config_fixture):
     with caplog.at_level(logging.INFO):
         with utils.temp_env({'SUBDAGS': '5', 'SUBDAG': '4'}):
                 self._build(recipes_fixture, config_fixture)
         assert 'Nothing to be done' in caplog.records[-1].getMessage()
Пример #5
0
 def test_subdags_out_of_range(self, recipes_fixture, config_fixture):
     with pytest.raises(ValueError):
         with utils.temp_env({'SUBDAGS': '1', 'SUBDAG': '5'}):
             self._build(recipes_fixture, config_fixture)
Пример #6
0
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:
            pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])
            build.build(
                recipe=r.recipe_dirs['one'],
                recipe_folder='.',
                pkg_paths=pkg_paths,
                mulled_test=False,
                _raise_error=True,
            )
        assert ("'GITHUB_TOKEN' is undefined" 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:
            pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])
            build.build(
                recipe=r.recipe_dirs['one'],
                recipe_folder='.',
                pkg_paths=pkg_paths,
                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()

    with utils.temp_env(env):
        pkg_paths = utils.built_package_paths(r.recipe_dirs['two'])
        for pkg in pkg_paths:
            ensure_missing(pkg)

        build.build(
            recipe=r.recipe_dirs['two'],
            recipe_folder='.',
            pkg_paths=pkg_paths,
            mulled_test=False,
        )

        for pkg in pkg_paths:
            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
Пример #7
0
 def test_subdags_more_than_recipes(self, caplog, recipes_fixture, config_fixture):
     with caplog.at_level(logging.INFO):
         with utils.temp_env({'SUBDAGS': '5', 'SUBDAG': '4'}):
                 self._build(recipes_fixture, config_fixture)
         assert 'Nothing to be done' in caplog.records[-1].getMessage()
Пример #8
0
 def test_subdags_out_of_range(self, recipes_fixture, config_fixture):
     with pytest.raises(ValueError):
         with utils.temp_env({'SUBDAGS': '1', 'SUBDAG': '5'}):
             self._build(recipes_fixture, config_fixture)