Exemple #1
0
def test_tox_deps_not_pinned():
    """Dependencies of tox environments should not have versions."""
    for _env, deps in helpers.tox_info("deps"):
        deps = deps.splitlines()
        deps = [d.split(":")[-1].strip().split("==") for d in deps]
        versions = collections.defaultdict(list)
        for d in deps:
            versions[d[0]].append(d[-1] if d[1:] else "*")
        for _package, v in versions.items():
            assert v == ["*"] or len(v) >= 2
Exemple #2
0
def test_tox_environments_use_max_base_python():
    """Verify base Python version specified for Tox environments.

    Every Tox environment with base Python version specified should
    use max Python version.

    Max Python version is assumed from the .python-versions file.
    """
    pyenv_version = max(
        sorted("python{}.{}".format(*v.split(".")[0:2])
               for v in open(".python-version").read().splitlines()))
    for _env, basepython in helpers.tox_info("basepython"):
        assert basepython == pyenv_version
Exemple #3
0
def test_tox_environment_base_python_equal_azure_task_python_version():
    """If tox environment has `basepython` setting, the corresponding Azure
    Pipeline task should has the same value in the `python.version` setting."""

    azure_pipelines = yaml.safe_load(open("azure-pipelines.yml").read())
    azure_tasks = {
        k: v["python.version"]
        for k, v in azure_pipelines["jobs"][0]["strategy"]["matrix"].items()
    }

    for env, basepython in helpers.tox_info("basepython"):
        env = re.sub(r"^testenv:", "", env)
        basepython = re.sub(r"^python", "", basepython)
        assert basepython == azure_tasks[env]
Exemple #4
0
def test_tox_deps_are_ordered():
    """Dependencies of tox environments should be in order."""
    for _env, deps in helpers.tox_info("deps"):
        deps = [d.split("==")[0] for d in deps.splitlines()]
        ordered = [
            deps[l[1]] for l in sorted(
                ([
                    list(
                        map(lambda x: x.strip().lower(), reversed(d.split(
                            ":")))), i
                ] for i, d in enumerate(deps)),
                key=lambda key: key[0],
            )
        ]
        assert deps == ordered
def test_tox_environment_base_python_equal_azure_task_python_version():
    """Python version should present in the Azure Pipeline task list.

    Python version of the Tox environment should be equal to the version
    of the corresponding Azure Pipeline task.  Python version of the
    environment should be specified in the base python option.
    """
    azure_pipelines = yaml.safe_load(open("azure-pipelines.yml").read())
    azure_tasks = {
        k: v["python.version"]
        for k, v in azure_pipelines["jobs"][0]["strategy"]["matrix"].items()
    }

    for env, basepython in helpers.tox_info("basepython"):
        env = re.sub(r"^testenv:", "", env)
        basepython = re.sub(r"^python", "", basepython)
        assert basepython == azure_tasks[env]
def test_azure_nodejs_installed_for_necessary_tox_environments():
    """Azure pipelines should have nodejs installed.

    This is a hard requirement for all tox environmets running npm and
    npx commands.
    """
    azure_pipelines = yaml.safe_load(open("azure-pipelines.yml").read())
    nodejs = [
        step
        for step in azure_pipelines["jobs"][0]["steps"]
        if step.get("task") == "NodeTool@0"
    ][0]
    tox_environments = ", ".join(
        "'" + re.sub(r"^testenv:", "", env) + "'"
        for env, commands in helpers.tox_info("commands")
        if "npm install" in commands
    )
    assert tox_environments in nodejs["condition"]