From 1818753f3d560297a6e47932d2fae02b6184afbb Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Thu, 18 Jan 2024 17:47:37 +0100 Subject: [PATCH] Test to make sure virtual packages aren't included in lockfiles Closes #559 --- tests/test_conda_lock.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index e6997a6ba..3f7dea4bf 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -174,6 +174,20 @@ def zlib_environment(tmp_path: Path): return clone_test_dir("zlib", tmp_path).joinpath("environment.yml") +@pytest.fixture +def tzcode_environment(tmp_path: Path): + contents = """ + channels: + - conda-forge + - nodefaults + dependencies: + - tzcode + """ + env = tmp_path / "environment.yml" + env.write_text(contents) + return env + + @pytest.fixture def input_hash_zlib_environment(tmp_path: Path): return clone_test_dir("test-input-hash-zlib", tmp_path).joinpath("environment.yml") @@ -1812,7 +1826,9 @@ def test_install( kind: str, tmp_path: Path, conda_exe: str, - zlib_environment: Path, + # We choose tzcode since it depends on glibc on linux-64, and this induces a + # virtual package, and we test to make sure it's filtered out from the lockfile. + tzcode_environment: Path, monkeypatch: "pytest.MonkeyPatch", capsys: "pytest.CaptureFixture[str]", ): @@ -1830,7 +1846,7 @@ def test_install( generated_lockfile_path.mkdir(exist_ok=True) monkeypatch.chdir(generated_lockfile_path) - package = "zlib" + package = "tzcode" platform = "linux-64" lock_filename_template = ( @@ -1852,7 +1868,7 @@ def test_install( "-p", platform, "-f", - str(zlib_environment), + str(tzcode_environment), "-k", kind, "--filename-template", @@ -1866,6 +1882,17 @@ def test_install( print(result.stderr, file=sys.stderr) assert result.exit_code == 0 + lockfile_content = Path(lock_filename).read_text() + if kind == "lock": + might_contain_virtual_package = "name: __" in lockfile_content + else: + might_contain_virtual_package = "__" in lockfile_content + assert not might_contain_virtual_package, ( + f"Lockfile may contain a virtual package (e.g. __glibc). " + f"These should never appear in the lockfile. " + f"{lockfile_content}" + ) + prefix = root_prefix / "test_env" context: ContextManager