From 0d08a374be27f01d43212369a1e8d9360cfc722c Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Wed, 18 Oct 2023 13:10:07 +0200 Subject: [PATCH] Precompute for test_run_lock_with_update_filter_platform --- .../conda-lock.yml | 48 +++++++++++++++++++ tests/test_conda_lock.py | 39 ++++++++++----- 2 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 tests/test-update-filter-platform/conda-lock.yml diff --git a/tests/test-update-filter-platform/conda-lock.yml b/tests/test-update-filter-platform/conda-lock.yml new file mode 100644 index 00000000..3c94a692 --- /dev/null +++ b/tests/test-update-filter-platform/conda-lock.yml @@ -0,0 +1,48 @@ +# This lock file was generated by conda-lock (https://github.com/conda/conda-lock). DO NOT EDIT! +# +# A "lock file" contains a concrete list of package versions (with checksums) to be installed. Unlike +# e.g. `conda env create`, the resulting environment will not change as new package versions become +# available, unless you explicitly update the lock file. +# +# Install this environment as "YOURENV" with: +# conda-lock install -n YOURENV --file conda-lock.yml +# To update a single package to the latest version compatible with the version constraints in the source: +# conda-lock lock --lockfile conda-lock.yml --update PACKAGE +# To re-solve the entire environment, e.g. after changing a version constraint in the source file: +# conda-lock -f environment-preupdate.yml --lockfile conda-lock.yml +version: 1 +metadata: + content_hash: + linux-64: 74b9b82333bad461da874bac86ac55f9ac26d57510234e36571d0a0f43fb9c2d + osx-64: 3374c9a110308beb184dfdf37a58250fecb0b6e79ef06a55858a955ba7668ad9 + channels: + - url: conda-forge + used_env_vars: [] + platforms: + - linux-64 + - osx-64 + sources: + - environment-preupdate.yml +package: +- name: zlib + version: 1.2.8 + manager: conda + platform: linux-64 + dependencies: {} + url: https://conda.anaconda.org/conda-forge/linux-64/zlib-1.2.8-3.tar.bz2 + hash: + md5: 6b3dbbf50432b3e2a271b5e46877bcfc + sha256: 85fcb6906b8686fe6341db89b4e6fc2631ad69ee6eab2f4823bfd64ae0b20ac8 + category: main + optional: false +- name: zlib + version: 1.2.8 + manager: conda + platform: osx-64 + dependencies: {} + url: https://conda.anaconda.org/conda-forge/osx-64/zlib-1.2.8-3.tar.bz2 + hash: + md5: 03b6fcc7a5e1a471e74049665e1c06b0 + sha256: d175728c3972c4baf2bdbdd9d7580ba3349b8861e7150d41034319496f99a804 + category: main + optional: false diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index adab0dad..4a30f1ef 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -1173,13 +1173,16 @@ def update_environment(tmp_path: Path) -> Path: @pytest.fixture -def update_environment_filter_platform(tmp_path: Path) -> Tuple[Path, Path]: +def update_environment_filter_platform(tmp_path: Path) -> Tuple[Path, Path, Path]: test_dir = clone_test_dir("test-update-filter-platform", tmp_path) - - return ( + files = ( + test_dir / "conda-lock.yml", test_dir / "environment-preupdate.yml", test_dir / "environment-postupdate.yml", ) + for file in files: + assert file.exists() + return files @pytest.fixture @@ -1250,22 +1253,36 @@ def test_run_lock_with_update( @pytest.mark.timeout(120) def test_run_lock_with_update_filter_platform( monkeypatch: "pytest.MonkeyPatch", - update_environment_filter_platform: Tuple[Path, Path], + update_environment_filter_platform: Tuple[Path, Path, Path], conda_exe: str, ): """Test that when updating for one platform, other platforms are not updated.""" - pre_env = update_environment_filter_platform[0] - post_env = update_environment_filter_platform[1] - environment_dir = pre_env.parent + lockfile_path, pre_env, post_env = update_environment_filter_platform + environment_dir = lockfile_path.parent monkeypatch.chdir(environment_dir) - run_lock([pre_env], conda_exe=conda_exe) - run_lock([post_env], conda_exe=conda_exe, update=["zlib"], platforms=["linux-64"]) + # # We have pre-generated the lockfile for the pre_env file to save time. + # # Run 'conda-lock -f environment-preupdate.yml' or + # run_lock([pre_env], lockfile_path=lockfile_path, conda_exe=conda_exe) + + pre_lock = { + (p.name, p.platform): p for p in parse_conda_lock_file(lockfile_path).package + } + # The pre_env file has zlib 1.2.8 for all platforms. + assert pre_lock[("zlib", "linux-64")].version == "1.2.8" + assert pre_lock[("zlib", "osx-64")].version == "1.2.8" + run_lock( + [post_env], + lockfile_path=lockfile_path, + conda_exe=conda_exe, + update=["zlib"], + platforms=["linux-64"], + ) post_lock = { - (p.name, p.platform): p - for p in parse_conda_lock_file(environment_dir / DEFAULT_LOCKFILE_NAME).package + (p.name, p.platform): p for p in parse_conda_lock_file(lockfile_path).package } + # The post_env file updates zlib to 1.2.13, but we only ran the update for linux-64. assert post_lock[("zlib", "linux-64")].version == "1.2.13" assert post_lock[("zlib", "osx-64")].version == "1.2.8"