From 83c5ad5ae6c77428527f635a70e32ce6d357529a Mon Sep 17 00:00:00 2001 From: Marius van Niekerk Date: Wed, 28 Jun 2023 14:16:55 -0400 Subject: [PATCH] Move other regression tests to test_regression --- mypy.ini | 18 +++++---- tests/conftest.py | 40 +++++++++++++++++++- tests/test_conda_lock.py | 81 +--------------------------------------- tests/test_regression.py | 61 ++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 89 deletions(-) diff --git a/mypy.ini b/mypy.ini index 17800388..cef8d3b0 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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 @@ -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 \ No newline at end of file +[mypy-tests.*] diff --git a/tests/conftest.py b/tests/conftest.py index 16929733..32064f2e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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") diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 09008682..ecdff783 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -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, @@ -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") @@ -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"} @@ -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, @@ -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 diff --git a/tests/test_regression.py b/tests/test_regression.py index 7b678ebc..ba400d97 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -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"]) @@ -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)