Skip to content

Commit

Permalink
Add Test Case with Conda-Lock Install
Browse files Browse the repository at this point in the history
  • Loading branch information
srilman committed Jan 4, 2024
1 parent 77807e1 commit 1f31cd1
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,6 @@ def test_install_with_pip_deps(
tmp_path: Path,
conda_exe: str,
install_with_pip_deps_lockfile: Path,
monkeypatch: "pytest.MonkeyPatch",
caplog,
):
root_prefix = tmp_path / "root_prefix"
Expand Down Expand Up @@ -1997,6 +1996,55 @@ def test_install_with_pip_deps(
subprocess.check_call([str(python), "-c", "import requests"])


@pytest.fixture
def install_multiple_categories_lockfile(tmp_path: Path):
return clone_test_dir("test-multiple-categories", tmp_path).joinpath(
"conda-lock.yml"
)


@pytest.mark.parametrize("categories", [[], ["dev"], ["test"], ["dev", "test"]])
def test_install_multiple_subcategories(
tmp_path: Path,
conda_exe: str,
install_multiple_categories_lockfile: Path,
categories: List[str],
):
root_prefix = tmp_path / "root_prefix"
root_prefix.mkdir(exist_ok=True)
prefix = root_prefix / "test_env"

context: ContextManager
if sys.platform.lower().startswith("linux"):
context = contextlib.nullcontext()
else:
# since by default we do platform validation we would expect this to fail
context = pytest.raises(PlatformValidationError)

with context, install_lock():
install(
conda=str(conda_exe),
prefix=str(prefix),
lock_file=install_multiple_categories_lockfile,
extras=categories,
)

if sys.platform.lower().startswith("linux"):
packages_to_check = ["python"]
if "dev" in categories or "test" in categories:
packages_to_check += ["numpy", "pandas"]
if "dev" in categories:
packages_to_check.append("astropy")
if "test" in categories:
packages_to_check.append("pyspark")

for package in packages_to_check:
assert _check_package_installed(
package=package,
prefix=str(prefix),
), f"Package {package} does not exist in {prefix} environment"


@pytest.mark.parametrize("kind", ["explicit", "env"])
def test_warn_on_explicit_lock_with_pip_deps(
kind: Literal["explicit", "env"],
Expand Down

0 comments on commit 1f31cd1

Please sign in to comment.