diff --git a/micromamba/tests/channel_a/linux-64/repodata.json b/micromamba/tests/channel_a/linux-64/repodata.json new file mode 100644 index 0000000000..7766241e09 --- /dev/null +++ b/micromamba/tests/channel_a/linux-64/repodata.json @@ -0,0 +1,53 @@ +{ + "info": { + "subdir": "linux-64" + }, + "packages": { + "A_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "linux-64", + "timestamp": 1578950023135, + "version": "0.1.0" + }, + "A_0.2.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "linux-64", + "timestamp": 1578950023135, + "version": "0.2.0" + }, + "B_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [ + "a" + ], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "b", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "linux-64", + "timestamp": 1578950023135, + "version": "0.1.0" + } + }, + "removed": [], + "repodata_version": 1 +} diff --git a/micromamba/tests/channel_a/linux-64/repodata.tar.bz2 b/micromamba/tests/channel_a/linux-64/repodata.tar.bz2 new file mode 100644 index 0000000000..573cf8494d Binary files /dev/null and b/micromamba/tests/channel_a/linux-64/repodata.tar.bz2 differ diff --git a/micromamba/tests/channel_a/linux-64/repodata.tpl b/micromamba/tests/channel_a/linux-64/repodata.tpl new file mode 100644 index 0000000000..3358560093 --- /dev/null +++ b/micromamba/tests/channel_a/linux-64/repodata.tpl @@ -0,0 +1,55 @@ +{ + "info": { + "subdir": "linux-64" + }, + "packages": { + "A_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [ + ], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "linux-64", + "timestamp": 1578950023135, + "version": "0.1.0" + }, + "A_0.2.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [ + ], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "linux-64", + "timestamp": 1578950023135, + "version": "0.2.0" + }, + "B_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [ + "a"GLIBC_PLACEHOLDER + ], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "b", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "linux-64", + "timestamp": 1578950023135, + "version": "0.1.0" + } + }, + "removed": [], + "repodata_version": 1 +} diff --git a/micromamba/tests/channel_a/noarch/_r-mutex-1.0.1-anacondar_1.tar.bz2 b/micromamba/tests/channel_a/noarch/_r-mutex-1.0.1-anacondar_1.tar.bz2 new file mode 100644 index 0000000000..1da51e0c52 Binary files /dev/null and b/micromamba/tests/channel_a/noarch/_r-mutex-1.0.1-anacondar_1.tar.bz2 differ diff --git a/micromamba/tests/channel_a/noarch/repodata.json b/micromamba/tests/channel_a/noarch/repodata.json new file mode 100644 index 0000000000..2e652b7ab7 --- /dev/null +++ b/micromamba/tests/channel_a/noarch/repodata.json @@ -0,0 +1,40 @@ +{ + "info": { + "subdir": "noarch" + }, + "packages": { + "_r-mutex-1.0.1-anacondar_1.tar.bz2": { + "build": "anacondar_1", + "build_number": 1, + "constrains": [], + "depends": [], + "license": "BSD", + "md5": "19f9db5f4f1b7f5ef5f6d67207f25f38", + "name": "_r-mutex", + "noarch": "generic", + "platform": null, + "sha256": "e58f9eeb416b92b550e824bcb1b9fb1958dee69abfe3089dfd1a9173e3a0528a", + "size": 3566, + "subdir": "noarch", + "timestamp": 1562343890778, + "track_features": "", + "version": "1.0.1" + }, + "testpkg_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "testpkg", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "noarch", + "timestamp": 1578950023135, + "version": "0.1.0" + } + }, + "removed": [], + "repodata_version": 1 +} diff --git a/micromamba/tests/channel_a/win-64/repodata.json b/micromamba/tests/channel_a/win-64/repodata.json new file mode 100644 index 0000000000..30adbde806 --- /dev/null +++ b/micromamba/tests/channel_a/win-64/repodata.json @@ -0,0 +1,53 @@ +{ + "info": { + "subdir": "win-64" + }, + "packages": { + "A_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "win-64", + "timestamp": 1578950023135, + "version": "0.1.0" + }, + "A_0.2.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "win-64", + "timestamp": 1578950023135, + "version": "0.2.0" + }, + "B_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [ + "a" + ], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "b", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "win-64", + "timestamp": 1578950023135, + "version": "0.1.0" + } + }, + "removed": [], + "repodata_version": 1 +} diff --git a/micromamba/tests/channel_a/win-64/repodata.tar.bz2 b/micromamba/tests/channel_a/win-64/repodata.tar.bz2 new file mode 100644 index 0000000000..f3f0ce1c38 Binary files /dev/null and b/micromamba/tests/channel_a/win-64/repodata.tar.bz2 differ diff --git a/micromamba/tests/channel_a/win-64/repodata.tpl b/micromamba/tests/channel_a/win-64/repodata.tpl new file mode 100644 index 0000000000..f51e3e8d13 --- /dev/null +++ b/micromamba/tests/channel_a/win-64/repodata.tpl @@ -0,0 +1,55 @@ +{ + "info": { + "subdir": "win-64" + }, + "packages": { + "A_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [ + ], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "win-64", + "timestamp": 1578950023135, + "version": "0.1.0" + }, + "A_0.2.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [ + ], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "win-64", + "timestamp": 1578950023135, + "version": "0.2.0" + }, + "B_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [ + "a"GLIBC_PLACEHOLDER + ], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "b", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "win-64", + "timestamp": 1578950023135, + "version": "0.1.0" + } + }, + "removed": [], + "repodata_version": 1 +} diff --git a/micromamba/tests/channel_b/linux-64/repodata.json b/micromamba/tests/channel_b/linux-64/repodata.json new file mode 100644 index 0000000000..c28d1f38c8 --- /dev/null +++ b/micromamba/tests/channel_b/linux-64/repodata.json @@ -0,0 +1,23 @@ +{ + "info": { + "subdir": "linux-64" + }, + "packages": { + "A_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "linux-64", + "timestamp": 1578950023135, + "version": "0.1.0" + } + }, + "removed": [], + "repodata_version": 1 +} diff --git a/micromamba/tests/channel_b/noarch/repodata.json b/micromamba/tests/channel_b/noarch/repodata.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/micromamba/tests/channel_b/noarch/repodata.json @@ -0,0 +1 @@ +{} diff --git a/micromamba/tests/channel_b/win-64/repodata.json b/micromamba/tests/channel_b/win-64/repodata.json new file mode 100644 index 0000000000..ee93a3ac35 --- /dev/null +++ b/micromamba/tests/channel_b/win-64/repodata.json @@ -0,0 +1,23 @@ +{ + "info": { + "subdir": "win-64" + }, + "packages": { + "A_0.1.0.tar.bz2": { + "build": "abc", + "build_number": 0, + "depends": [], + "license": "BSD", + "license_family": "BSD", + "md5": "85107fc10154734ef34a5a75685be684", + "name": "a", + "sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1", + "size": 222503, + "subdir": "win-64", + "timestamp": 1578950023135, + "version": "0.1.0" + } + }, + "removed": [], + "repodata_version": 1 +} diff --git a/micromamba/tests/conftest.py b/micromamba/tests/conftest.py index 3a30ffca12..9195e5640a 100644 --- a/micromamba/tests/conftest.py +++ b/micromamba/tests/conftest.py @@ -229,3 +229,50 @@ def user_cache_dir(tmp_home: pathlib.Path) -> Generator[pathlib.Path, None, None yield pathlib.Path(os.environ["LOCALAPPDATA"]) / "mamba" else: raise RuntimeError(f"Unsupported system {system}") + + +def get_glibc_version(): + try: + output = subprocess.check_output(["ldd", "--version"]) + except: + return + output.splitlines() + version = output.splitlines()[0].split()[-1] + return version.decode("ascii") + + +@pytest.fixture +def add_glibc_virtual_package(): + version = get_glibc_version() + here = os.path.dirname(os.path.abspath(__file__)) + with open(os.path.join(here, "channel_a/linux-64/repodata.tpl")) as f: + repodata = f.read() + with open(os.path.join(here, "channel_a/linux-64/repodata.json"), "w") as f: + if version is not None: + glibc_placeholder = ', "__glibc=' + version + '"' + else: + glibc_placeholder = "" + repodata = repodata.replace("GLIBC_PLACEHOLDER", glibc_placeholder) + f.write(repodata) + + +@pytest.fixture +def copy_channels_osx(): + import shutil + + here = os.path.dirname(os.path.abspath(__file__)) + for channel in ["a", "b"]: + if not os.path.exists(os.path.join(here, f"channel_{channel}/osx-64")): + shutil.copytree( + os.path.join(here, f"channel_{channel}/linux-64"), + os.path.join(here, f"channel_{channel}/osx-64"), + ) + with open( + os.path.join(here, f"channel_{channel}/osx-64/repodata.json") + ) as f: + repodata = f.read() + with open( + os.path.join(here, f"channel_{channel}/osx-64/repodata.json"), "w" + ) as f: + repodata = repodata.replace("linux", "osx") + f.write(repodata) diff --git a/micromamba/tests/helpers.py b/micromamba/tests/helpers.py index a77c975fd6..9ef2169f25 100644 --- a/micromamba/tests/helpers.py +++ b/micromamba/tests/helpers.py @@ -505,3 +505,19 @@ def get_fake_activate(prefix): env["PATH"] = os.pathsep.join([str(x) for x in addpath + curpath]) env["CONDA_PREFIX"] = str(prefix) return env + + +def create_with_chan_pkg(env_name, channels, package): + cmd = [ + "-n", + env_name, + "--override-channels", + "--strict-channel-priority", + "--dry-run", + "--json", + ] + for channel in channels: + cmd += ["-c", os.path.abspath(os.path.join(*channel))] + cmd.append(package) + + return create(*cmd, default_channel=False, no_rc=False) diff --git a/micromamba/tests/test_create.py b/micromamba/tests/test_create.py index f6ac1cb95d..b6f12ace83 100644 --- a/micromamba/tests/test_create.py +++ b/micromamba/tests/test_create.py @@ -797,6 +797,22 @@ def test_pyc_compilation(tmp_home, tmp_root_prefix, version, build, cache_tag): assert pyc_fn.name in six_meta +def test_create_check_dirs(tmp_home, tmp_root_prefix): + env_name = "myenv" + env_prefix = tmp_root_prefix / "envs" / env_name + cmd = ["-n", env_name, "python=3.8", "traitlets"] + helpers.create(*cmd) + + assert os.path.isdir(env_prefix) + + if platform.system() == "Windows": + assert os.path.isdir(env_prefix / "lib" / "site-packages" / "traitlets") + else: + assert os.path.isdir( + env_prefix / "lib" / "python3.8" / "site-packages" / "traitlets" + ) + + @pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) @pytest.mark.parametrize("env_file", env_files) def test_requires_pip_install(tmp_home, tmp_root_prefix, env_file): @@ -921,3 +937,154 @@ def test_long_path_support(tmp_home, tmp_root_prefix): """Create an environment with a long name.""" res = helpers.create("-n", "long_prefix_" * 20, "--json") assert res["success"] + + +def test_dummy_create( + add_glibc_virtual_package, copy_channels_osx, tmp_home, tmp_root_prefix +): + env_name = "myenv" + + channels = [ + (".", "micromamba", "tests", "channel_b"), + (".", "micromamba", "tests", "channel_a"), + ] + package = "a" + res = helpers.create_with_chan_pkg(env_name, channels, package) + + for link in res["actions"]["LINK"]: + assert link["name"] == "a" + assert link["build"] == "abc" + assert "channel_b" in link["channel"] + + package = "b" + res = helpers.create_with_chan_pkg(env_name, channels, package) + + assert any( + link["name"] == "b" and "channel_a" in link["channel"] + for link in res["actions"]["LINK"] + ) + + channels = channels[::-1] + res = helpers.create_with_chan_pkg(env_name, channels, package) + + +@pytest.mark.parametrize("use_json", [True, False]) +def test_create_dry_run(tmp_home, tmp_root_prefix, use_json): + env_name = "myenv" + env_prefix = tmp_root_prefix / "envs" / env_name + + cmd = ["-n", env_name, "--dry-run", "python=3.8"] + + if use_json: + cmd += ["--json"] + + res = helpers.create(*cmd) + + if not use_json: + # Assert the non-JSON output is in the terminal. + assert "Total download" in res + + # dry-run, shouldn't create an environment + assert not os.path.isdir(env_prefix) + + +def test_create_with_non_existing_subdir(tmp_home, tmp_root_prefix, tmp_path): + env_prefix = tmp_path / "myprefix" + with pytest.raises(subprocess.CalledProcessError) as e: + helpers.create( + "-p", env_prefix, "--dry-run", "--json", f"conda-forge/noarch::xtensor" + ) + + +def test_create_with_multiple_files(tmp_home, tmp_root_prefix, tmpdir): + env_name = "myenv" + env_prefix = tmp_root_prefix / "envs" / env_name + + # Check that multiple --file arguments are considered + (tmpdir / "file_a.txt").write(b"a") + (tmpdir / "file_b.txt").write(b"b") + + res = helpers.create( + "-n", + env_name, + "--json", + "--override-channels", + "--strict-channel-priority", + "--dry-run", + "-c", + "./micromamba/tests/channel_b", + "-c", + "./micromamba/tests/channel_a", + "--file", + str(tmpdir / "file_a.txt"), + "--file", + str(tmpdir / "file_b.txt"), + default_channel=False, + no_rc=False, + ) + + names = {x["name"] for x in res["actions"]["FETCH"]} + assert names == {"a", "b"} + + +multichannel_config = { + "channels": ["conda-forge"], + "custom_multichannels": {"conda-forge2": ["conda-forge"]}, +} + + +def test_create_with_multi_channels(tmp_home, tmp_root_prefix, tmp_path): + env_name = "myenv" + env_prefix = tmp_root_prefix / "envs" / env_name + + rc_file = tmp_path / "config.yaml" + rc_file.write_text(yaml.dump(multichannel_config)) + + res = helpers.create( + "-n", + env_name, + "conda-forge2::xtensor", + "--dry-run", + "--json", + f"--rc-file={rc_file}", + default_channel=False, + no_rc=False, + ) + + for pkg in res["actions"]["FETCH"]: + assert pkg["channel"].startswith("https://conda.anaconda.org/conda-forge/") + for pkg in res["actions"]["LINK"]: + assert pkg["url"].startswith("https://conda.anaconda.org/conda-forge/") + + +def test_create_with_multi_channels_and_non_existing_subdir( + tmp_home, tmp_root_prefix, tmp_path +): + env_name = "myenv" + env_prefix = tmp_root_prefix / "envs" / env_name + + rc_file = tmp_path / "config.yaml" + rc_file.write_text(yaml.dump(multichannel_config)) + + with pytest.raises(subprocess.CalledProcessError) as e: + res = helpers.create( + "-n", + env_name, + "conda-forge2/noarch::xtensor", + "--dry-run", + "--json", + f"--rc-file={rc_file}", + default_channel=False, + no_rc=False, + ) + + +def test_create_with_unicode(tmp_home, tmp_root_prefix): + env_name = "320 áγђß家固êôōçñ한" + env_prefix = tmp_root_prefix / "envs" / env_name + + res = helpers.create("-n", env_name, "--json", "xtensor", no_rc=False) + + assert res["actions"]["PREFIX"] == str(env_prefix) + assert any(pkg["name"] == "xtensor" for pkg in res["actions"]["FETCH"]) + assert any(pkg["name"] == "xtl" for pkg in res["actions"]["FETCH"]) diff --git a/micromamba/tests/test_install.py b/micromamba/tests/test_install.py index e707540f75..870c447cad 100644 --- a/micromamba/tests/test_install.py +++ b/micromamba/tests/test_install.py @@ -569,3 +569,105 @@ def test_force_reinstall_not_installed(self, existing_cache): """Force reinstall on non-installed packages is valid.""" reinstall_res = install("xtensor", "--force-reinstall", "--json") assert "xtensor" in {pkg["name"] for pkg in reinstall_res["actions"]["LINK"]} + + +def test_install_check_dirs(tmp_home, tmp_root_prefix): + env_name = "myenv" + env_prefix = tmp_root_prefix / "envs" / env_name + + create("-n", env_name, "python=3.8") + res = install("-n", env_name, "nodejs", "--json") + + assert os.path.isdir(env_prefix) + assert "nodejs" in {pkg["name"] for pkg in res["actions"]["LINK"]} + + if platform.system() == "Windows": + assert os.path.isdir(env_prefix / "lib" / "site-packages") + else: + assert os.path.isdir(env_prefix / "lib" / "python3.8" / "site-packages") + + +def test_track_features(tmp_home, tmp_root_prefix): + env_name = "myenv" + env_prefix = tmp_root_prefix / "envs" / env_name + + # should install CPython since PyPy has track features + version = "3.7.9" + create("-n", env_name, default_channel=False, no_rc=False) + install( + "-n", + env_name, + "-q", + f"python={version}", + "--strict-channel-priority", + no_rc=False, + ) + res = umamba_run("-n", env_name, "python", "-c", "import sys; print(sys.version)") + if platform.system() == "Windows": + assert res.strip().startswith(version) + assert "[MSC v." in res.strip() + elif platform.system() == "Linux": + assert res.strip().startswith(version) + assert "[GCC" in res.strip() + else: + assert res.strip().startswith(version) + assert "[Clang" in res.strip() + + if platform.system() == "Linux": + # now force PyPy install + install( + "-n", + env_name, + "-q", + f"python={version}=*pypy", + "--strict-channel-priority", + no_rc=False, + ) + res = umamba_run( + "-n", env_name, "python", "-c", "import sys; print(sys.version)" + ) + + assert res.strip().startswith(version) + assert "[PyPy" in res.strip() + + +def test_reinstall_with_new_version(tmp_home, tmp_root_prefix): + env_name = "myenv" + env_prefix = tmp_root_prefix / "envs" / env_name + + version = "3.8" + create("-n", env_name, default_channel=False, no_rc=False) + install( + "-n", + env_name, + "-q", + f"python={version}", + "pip", + no_rc=False, + ) + + res = umamba_run("-n", env_name, "python", "-c", "import sys; print(sys.version)") + assert version in res + + res = umamba_run( + "-n", env_name, "python", "-c", "import pip; print(pip.__version__)" + ) + assert len(res) + + # Update python version + version = "3.9" + install( + "-n", + env_name, + "-q", + f"python={version}", + no_rc=False, + ) + + res = umamba_run("-n", env_name, "python", "-c", "import sys; print(sys.version)") + assert version in res + + res = umamba_run( + "-n", env_name, "python", "-c", "import pip; print(pip.__version__)" + ) + assert len(res) diff --git a/micromamba/tests/test_repoquery.py b/micromamba/tests/test_repoquery.py index 775a3dfa72..f923cbd4b7 100644 --- a/micromamba/tests/test_repoquery.py +++ b/micromamba/tests/test_repoquery.py @@ -49,10 +49,23 @@ def test_depends_not_installed(yaml_env: Path): @pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) -def test_depends_not_installed_with_channel(yaml_env: Path): - res = helpers.umamba_repoquery( - "depends", "-c", "conda-forge", "xtensor=0.24.5", "--json" - ) +@pytest.mark.parametrize("with_platform", (False, True)) +def test_depends_not_installed_with_channel(yaml_env: Path, with_platform): + if with_platform: + res = helpers.umamba_repoquery( + "depends", + "-c", + "conda-forge", + "xtensor=0.24.5", + "--platform", + "win-64", + "--json", + ) + assert res["result"]["pkgs"][0]["subdir"] == "win-64" + else: + res = helpers.umamba_repoquery( + "depends", "-c", "conda-forge", "xtensor=0.24.5", "--json" + ) assert res["query"]["query"] == "xtensor =0.24.5*" assert res["query"]["type"] == "depends" @@ -65,7 +78,7 @@ def test_depends_not_installed_with_channel(yaml_env: Path): assert any(x["name"] == "xtensor" for x in pkgs) assert any(x["name"] == "xtl" for x in pkgs) - if platform.system() == "Linux": + if not with_platform and platform.system() == "Linux": assert any(x["name"] == "libgcc-ng" for x in pkgs) assert any(x["name"] == "libstdcxx-ng" for x in pkgs) @@ -124,10 +137,23 @@ def test_whoneeds_not_installed(yaml_env: Path): @pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) -def test_whoneeds_not_installed_with_channel(yaml_env: Path): - res = helpers.umamba_repoquery( - "whoneeds", "-c", "conda-forge", "xtensor=0.24.5", "--json" - ) +@pytest.mark.parametrize("with_platform", (False, True)) +def test_whoneeds_not_installed_with_channel(yaml_env: Path, with_platform): + if with_platform: + res = helpers.umamba_repoquery( + "whoneeds", + "-c", + "conda-forge", + "xtensor=0.24.5", + "--platform", + "osx-64", + "--json", + ) + assert res["result"]["pkgs"][0]["subdir"] == "osx-64" + else: + res = helpers.umamba_repoquery( + "whoneeds", "-c", "conda-forge", "xtensor=0.24.5", "--json" + ) assert res["query"]["query"] == "xtensor =0.24.5*" assert res["query"]["type"] == "whoneeds" @@ -150,6 +176,35 @@ def test_whoneeds_tree(yaml_env: Path): assert "qpot" in res +@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) +@pytest.mark.parametrize("with_platform", (False, True)) +def test_search(yaml_env: Path, with_platform): + if with_platform: + res = helpers.umamba_repoquery( + "search", + "-c", + "conda-forge", + "xtensor*", + "--platform", + "linux-64", + "--json", + ) + assert res["result"]["pkgs"][0]["subdir"] == "linux-64" + else: + res = helpers.umamba_repoquery( + "search", "-c", "conda-forge", "xtensor*", "--json" + ) + + assert res["query"]["query"] == "xtensor*" + assert res["query"]["type"] == "search" + + pkgs = res["result"]["pkgs"] + assert all("conda-forge" in x["channel"] for x in pkgs) + assert any(x["name"] == "xtensor-blas" for x in pkgs) + assert any(x["name"] == "xtensor" for x in pkgs) + assert any(x["name"] == "xtensor-io" for x in pkgs) + + @pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) def test_remote_search_installed_pkg(yaml_env: Path): res = helpers.umamba_repoquery("search", "yaml")