Exemplo n.º 1
0
def test_migrator_recipe(recipe_migration_cfep9, jinja_env):
    cnfgr_fdstk.render_azure(
        jinja_env=jinja_env,
        forge_config=recipe_migration_cfep9.config,
        forge_dir=recipe_migration_cfep9.recipe,
    )

    with open(
        os.path.join(
            recipe_migration_cfep9.recipe,
            ".ci_support",
            "linux_python2.7.yaml",
        )
    ) as fo:
        variant = yaml.safe_load(fo)
        assert variant["zlib"] == ["1000"]
def test_secrets(py_recipe, jinja_env):
    cnfgr_fdstk.render_azure(
        jinja_env=jinja_env,
        forge_config=py_recipe.config,
        forge_dir=py_recipe.recipe,
    )

    run_docker_build = os.path.join(
        py_recipe.recipe, ".scripts", "run_docker_build.sh"
    )
    with open(run_docker_build, "rb") as run_docker_build_file:
        content = run_docker_build_file.read()
    assert b"-e BINSTAR_TOKEN" in content

    for config_yaml in os.listdir(
        os.path.join(py_recipe.recipe, ".azure-pipelines")
    ):
        if config_yaml.endswith(".yaml"):
            with open(config_yaml) as fo:
                config = yaml.safe_load(fo)
                if "jobs" in config:
                    assert any(
                        any(
                            step.get("env", {}).get("BINSTAR_TOKEN", None)
                            == "$(BINSTAR_TOKEN)"
                            for step in job["steps"]
                        )
                        for job in config["jobs"]
                    )

    py_recipe.config["provider"]["linux_aarch64"] = "drone"
    cnfgr_fdstk.render_drone(
        jinja_env=jinja_env,
        forge_config=py_recipe.config,
        forge_dir=py_recipe.recipe,
    )

    with open(os.path.join(py_recipe.recipe, ".drone.yml")) as fo:
        config = list(yaml.safe_load_all(fo))[-1]
        assert any(
            step.get("environment", {})
            .get("BINSTAR_TOKEN", {})
            .get("from_secret", None)
            == "BINSTAR_TOKEN"
            for step in config["steps"]
        )
def test_upload_on_branch_azure(upload_on_branch_recipe, jinja_env):
    cnfgr_fdstk.render_azure(
        jinja_env=jinja_env,
        forge_config=upload_on_branch_recipe.config,
        forge_dir=upload_on_branch_recipe.recipe,
    )
    # Check that the parameter is in the configuration.
    assert "upload_on_branch" in upload_on_branch_recipe.config
    assert upload_on_branch_recipe.config["upload_on_branch"] == "foo-branch"
    # Check that the parameter is in the generated file.
    with open(
            os.path.join(
                upload_on_branch_recipe.recipe,
                ".azure-pipelines",
                "azure-pipelines-osx.yml",
            )) as fp:
        content_osx = yaml.safe_load(fp)
    assert ('UPLOAD_ON_BRANCH="foo-branch"'
            in content_osx["jobs"][0]["steps"][0]["script"])
    assert ("BUILD_SOURCEBRANCHNAME"
            in content_osx["jobs"][0]["steps"][0]["script"])

    with open(
            os.path.join(
                upload_on_branch_recipe.recipe,
                ".azure-pipelines",
                "azure-pipelines-win.yml",
            )) as fp:
        content_win = yaml.safe_load(fp)
    assert ("UPLOAD_ON_BRANCH=foo-branch"
            in content_win["jobs"][0]["steps"][-1]["script"])
    assert ("BUILD_SOURCEBRANCHNAME"
            in content_win["jobs"][0]["steps"][-1]["script"])

    with open(
            os.path.join(
                upload_on_branch_recipe.recipe,
                ".azure-pipelines",
                "azure-pipelines-linux.yml",
            )) as fp:
        content_lin = yaml.safe_load(fp)
    assert ('UPLOAD_ON_BRANCH="foo-branch"'
            in content_lin["jobs"][0]["steps"][2]["script"])
    assert ("BUILD_SOURCEBRANCHNAME"
            in content_lin["jobs"][0]["steps"][2]["script"])
def test_migrator_compiler_version_recipe(
    recipe_migration_win_compiled, jinja_env
):
    """
    Assert that even when we have two migrations targeting the same file the correct one wins.
    """
    cnfgr_fdstk.render_azure(
        jinja_env=jinja_env,
        forge_config=recipe_migration_win_compiled.config,
        forge_dir=recipe_migration_win_compiled.recipe,
    )
    assert (
        len(
            os.listdir(
                os.path.join(
                    recipe_migration_win_compiled.recipe,
                    ".ci_support",
                    "migrations",
                )
            )
        )
        == 1
    )

    rendered_variants = os.listdir(
        os.path.join(recipe_migration_win_compiled.recipe, ".ci_support")
    )

    assert (
        "win_c_compilervs2008python2.7target_platformwin-32.yaml"
        in rendered_variants
    )
    assert (
        "win_c_compilervs2008python2.7target_platformwin-64.yaml"
        in rendered_variants
    )
    assert (
        "win_c_compilervs2017python3.5target_platformwin-32.yaml"
        in rendered_variants
    )
    assert (
        "win_c_compilervs2017python3.5target_platformwin-64.yaml"
        in rendered_variants
    )
Exemplo n.º 5
0
def test_migrator_downgrade_recipe(recipe_migration_cfep9_downgrade,
                                   jinja_env):
    """
    Assert that even when we have two migrations targeting the same file the correct one wins.
    """
    cnfgr_fdstk.render_azure(
        jinja_env=jinja_env,
        forge_config=recipe_migration_cfep9_downgrade.config,
        forge_dir=recipe_migration_cfep9_downgrade.recipe,
    )
    assert len(
        os.listdir(
            os.path.join(recipe_migration_cfep9_downgrade.recipe,
                         'migrations'))) == 2

    with open(
            os.path.join(recipe_migration_cfep9_downgrade.recipe,
                         ".ci_support", "linux_python2.7.yaml")) as fo:
        variant = yaml.safe_load(fo)
        assert variant["zlib"] == ["1000"]
def test_choco_install(choco_recipe, jinja_env):
    cnfgr_fdstk.render_azure(
        jinja_env=jinja_env,
        forge_config=choco_recipe.config,
        forge_dir=choco_recipe.recipe,
    )
    azure_file = os.path.join(
        os.path.join(choco_recipe.recipe, ".azure-pipelines",
                     "azure-pipelines-win.yml"))
    assert os.path.isfile(azure_file)
    with open(azure_file) as f:
        contents = f.read()
    exp = """
    - script: |
        choco install pkg0 -fdv -y --debug
      displayName: "Install Chocolatey Package: pkg0"

    - script: |
        choco install pkg1 --version=X.Y.Z -fdv -y --debug
      displayName: "Install Chocolatey Package: pkg1 --version=X.Y.Z"
""".strip()
    assert exp in contents
def test_migrator_delete_old(recipe_migration_cfep9, jinja_env):
    cfp_file = recipe_migration_cfep9.config["exclusive_config_file"]
    cfp_migration_dir = os.path.join(os.path.dirname(cfp_file), "share",
                                     "conda-forge", "migrations")
    assert os.path.exists(
        os.path.join(
            recipe_migration_cfep9.recipe,
            ".ci_support",
            "migrations",
            "zlib.yaml",
        ))
    os.makedirs(cfp_migration_dir, exist_ok=True)
    cnfgr_fdstk.render_azure(
        jinja_env=jinja_env,
        forge_config=recipe_migration_cfep9.config,
        forge_dir=recipe_migration_cfep9.recipe,
    )
    assert not os.path.exists(
        os.path.join(
            recipe_migration_cfep9.recipe,
            ".ci_support",
            "migrations",
            "zlib.yaml",
        ))