Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move other regression tests to test_regression #444

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
[mypy]
plugins = pydantic.mypy
disallow_untyped_defs = true
# disallow_untyped_calls = true
# disallow_untyped_decorators = false
disallow_incomplete_defs = true
disallow_untyped_defs = false
disallow_untyped_calls = false
disallow_untyped_decorators = false
disallow_incomplete_defs = false
check_untyped_defs = true
exclude = (?x)(
tests/test-local-pip/setup.py
)

[mypy-conda_lock.*]
disallow_untyped_defs = true
# disallow_untyped_calls = true
# disallow_untyped_decorators = true
disallow_incomplete_defs = true

[pydantic-mypy]
init_forbid_extra = True
init_typed = True
Expand Down Expand Up @@ -36,8 +44,4 @@ ignore_missing_imports = True
[mypy-click_default_group.*]
ignore_missing_imports = True

[mypy-test_conda_lock]
disallow_untyped_defs = false
disallow_untyped_calls = false
disallow_untyped_decorators = false
disallow_incomplete_defs = false
[mypy-tests.*]
40 changes: 38 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import pathlib
import platform
import re
import typing

from typing import Iterable, NamedTuple, NoReturn
from typing import Any, Iterable, NamedTuple, NoReturn

import docker
import pytest
Expand All @@ -11,7 +13,41 @@
from docker.models.containers import Container
from ensureconda.resolve import platform_subdir

from conda_lock.invoke_conda import _ensureconda
from conda_lock.invoke_conda import PathLike, _ensureconda


@pytest.fixture(
scope="session",
params=[
pytest.param("conda", marks=pytest.mark.skip(reason="slow")),
pytest.param("mamba"),
pytest.param("micromamba"),
],
)
def _conda_exe_type(request: Any) -> str:
"Internal fixture to iterate over"
return request.param


@pytest.fixture(scope="session")
@typing.no_type_check
def conda_exe(_conda_exe_type: str) -> PathLike:
kwargs = dict(
mamba=False,
micromamba=False,
conda=False,
conda_exe=False,
)
if platform.system().lower() == "windows":
if _conda_exe_type == "micromamba":
pytest.skip(reason="micromamba tests are failing on windows")

kwargs[_conda_exe_type] = True
_conda_exe = _ensureconda(**kwargs)

if _conda_exe is not None:
return _conda_exe
pytest.skip(f"{_conda_exe_type} is not installed")


@pytest.fixture(scope="session")
Expand Down
81 changes: 1 addition & 80 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@
MissingEnvVarError,
PlatformValidationError,
)
from conda_lock.invoke_conda import (
PathLike,
_ensureconda,
is_micromamba,
reset_conda_pkgs_dir,
)
from conda_lock.invoke_conda import is_micromamba, reset_conda_pkgs_dir
from conda_lock.lockfile import parse_conda_lock_file
from conda_lock.lockfile.v2prelim.models import (
HashModel,
Expand Down Expand Up @@ -157,13 +152,6 @@ def pip_environment_different_names_same_deps(tmp_path: Path):
)


@pytest.fixture
def pip_environment_regression_gh155(tmp_path: Path):
return clone_test_dir("test-pypi-resolve-gh155", tmp_path).joinpath(
"environment.yml"
)


@pytest.fixture
def pip_local_package_environment(tmp_path: Path):
return clone_test_dir("test-local-pip", tmp_path).joinpath("environment.yml")
Expand Down Expand Up @@ -306,41 +294,6 @@ def include_dev_dependencies(request: Any) -> bool:
return request.param


@pytest.fixture(
scope="session",
params=[
pytest.param("conda", marks=pytest.mark.skip(reason="slow")),
pytest.param("mamba"),
pytest.param("micromamba"),
],
)
def _conda_exe_type(request: Any) -> str:
"Internal fixture to iterate over"

return request.param


@pytest.fixture(scope="session")
@typing.no_type_check
def conda_exe(_conda_exe_type: str) -> PathLike:
kwargs = dict(
mamba=False,
micromamba=False,
conda=False,
conda_exe=False,
)
if platform.system().lower() == "windows":
if _conda_exe_type == "micromamba":
pytest.skip(reason="micromamba tests are failing on windows")

kwargs[_conda_exe_type] = True
_conda_exe = _ensureconda(**kwargs)

if _conda_exe is not None:
return _conda_exe
pytest.skip(f"{_conda_exe_type} is not installed")


JSON_FIELDS: Dict[str, str] = {"json_unique_field": "test1", "common_field": "test2"}

YAML_FIELDS: Dict[str, str] = {"yaml_unique_field": "test3", "common_field": "test4"}
Expand Down Expand Up @@ -1265,17 +1218,6 @@ def test_run_lock_with_pip_environment_different_names_same_deps(
run_lock([pip_environment_different_names_same_deps], conda_exe=conda_exe)


def test_run_lock_regression_gh155(
monkeypatch: "pytest.MonkeyPatch",
pip_environment_regression_gh155: Path,
conda_exe: str,
):
monkeypatch.chdir(pip_environment_regression_gh155.parent)
if is_micromamba(conda_exe):
monkeypatch.setenv("CONDA_FLAGS", "-v")
run_lock([pip_environment_regression_gh155], conda_exe=conda_exe)


def test_run_lock_uppercase_pip(
monkeypatch: "pytest.MonkeyPatch",
env_with_uppercase_pip: Path,
Expand Down Expand Up @@ -1521,27 +1463,6 @@ def test_aggregate_lock_specs_invalid_channels():
)


@pytest.mark.parametrize(
["test_dir", "filename"],
[
(["test-pypi-resolve-gh290", "pyproject"], "pyproject.toml"),
(["test-pypi-resolve-gh290", "tzdata"], "environment.yaml"),
(["test-pypi-resolve-gh290", "wdl"], "environment.yaml"),
],
)
def test_conda_pip_regressions_gh290(
tmp_path: Path,
mamba_exe: str,
monkeypatch: "pytest.MonkeyPatch",
test_dir: List[str],
filename: str,
):
"""Simple test that asserts that these engieonments can be locked"""
spec = clone_test_dir(test_dir, tmp_path).joinpath(filename)
monkeypatch.chdir(spec.parent)
run_lock([spec], conda_exe=mamba_exe)


def _check_package_installed(package: str, prefix: str):
import glob

Expand Down
61 changes: 61 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
"""This is a test module to ensure that the various changes we've made over time don't
break the functionality of conda-lock. This is a regression test suite."""

import shutil
import sys
import textwrap

from pathlib import Path
from typing import List, Union

import pytest

from conda_lock.conda_lock import run_lock
from conda_lock.invoke_conda import is_micromamba


TEST_DIR = Path(__file__).parent


def clone_test_dir(name: Union[str, List[str]], tmp_path: Path) -> Path:
if isinstance(name, str):
name = [name]
test_dir = TEST_DIR.joinpath(*name)
assert test_dir.exists()
assert test_dir.is_dir()
if sys.version_info >= (3, 8):
shutil.copytree(test_dir, tmp_path, dirs_exist_ok=True)
else:
from distutils.dir_util import copy_tree

copy_tree(str(test_dir), str(tmp_path))
return tmp_path


@pytest.mark.parametrize("platform", ["linux-64", "osx-64", "osx-arm64"])
Expand All @@ -27,3 +49,42 @@ def test_pr_436(
(tmp_path / "environment.yml").write_text(spec)
monkeypatch.chdir(tmp_path)
run_lock([tmp_path / "environment.yml"], conda_exe=mamba_exe, platforms=[platform])


@pytest.mark.parametrize(
["test_dir", "filename"],
[
(["test-pypi-resolve-gh290", "pyproject"], "pyproject.toml"),
(["test-pypi-resolve-gh290", "tzdata"], "environment.yaml"),
(["test-pypi-resolve-gh290", "wdl"], "environment.yaml"),
],
)
def test_conda_pip_regressions_gh290(
tmp_path: Path,
mamba_exe: str,
monkeypatch: "pytest.MonkeyPatch",
test_dir: List[str],
filename: str,
):
"""Simple test that asserts that these engieonments can be locked"""
spec = clone_test_dir(test_dir, tmp_path).joinpath(filename)
monkeypatch.chdir(spec.parent)
run_lock([spec], conda_exe=mamba_exe)


@pytest.fixture
def pip_environment_regression_gh155(tmp_path: Path):
return clone_test_dir("test-pypi-resolve-gh155", tmp_path).joinpath(
"environment.yml"
)


def test_run_lock_regression_gh155(
monkeypatch: "pytest.MonkeyPatch",
pip_environment_regression_gh155: Path,
conda_exe: str,
):
monkeypatch.chdir(pip_environment_regression_gh155.parent)
if is_micromamba(conda_exe):
monkeypatch.setenv("CONDA_FLAGS", "-v")
run_lock([pip_environment_regression_gh155], conda_exe=conda_exe)