-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parametrize test_priority.py
#12895
Merged
Merged
Parametrize test_priority.py
#12895
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad02720
Parametrize test_priority
kenodegard 4b72f35
Update channel preference
kenodegard 8b393fd
Remove unnecessary set_active_prefix
kenodegard 562aaf2
Merge branch 'main' into refactor-test_priority
kenodegard 05e7724
Use CLI args instead of envvars
kenodegard File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,56 @@ | ||
# Copyright (C) 2012 Anaconda, Inc | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
import json | ||
import re | ||
|
||
import pytest | ||
from pytest import MonkeyPatch | ||
|
||
from conda.base.context import conda_tests_ctxt_mgmt_def_pol, context | ||
from conda.common.io import env_var | ||
from conda.base.context import context, reset_context | ||
from conda.core.prefix_data import PrefixData | ||
from conda.testing.integration import ( | ||
Commands, | ||
make_temp_env, | ||
package_is_installed, | ||
run_command, | ||
) | ||
from conda.testing import CondaCLIFixture, TmpEnvFixture | ||
|
||
|
||
@pytest.mark.integration | ||
def test_channel_order_channel_priority_true(): | ||
# This is broken, make_temp_env will reset the context. We get away with it, but really | ||
# we need a function that does both these at the same time. | ||
with env_var( | ||
"CONDA_PINNED_PACKAGES", | ||
"python=3.8", | ||
stack_callback=conda_tests_ctxt_mgmt_def_pol, | ||
): | ||
with make_temp_env("pycosat=0.6.3") as prefix: | ||
assert package_is_installed(prefix, "python=3.8") | ||
assert package_is_installed(prefix, "pycosat") | ||
|
||
payload, _, _ = run_command( | ||
Commands.CONFIG, prefix, "--get", "channels", "--json" | ||
) | ||
default_channels = json.loads(payload)["get"].get("channels") | ||
if default_channels: | ||
run_command(Commands.CONFIG, prefix, "--remove-key", "channels") | ||
|
||
# add conda-forge channel | ||
o, e, _ = run_command( | ||
Commands.CONFIG, | ||
prefix, | ||
"--prepend", | ||
"channels", | ||
"conda-forge", | ||
"--json", | ||
) | ||
assert context.channels == ("conda-forge", "defaults"), o + e | ||
# update --all | ||
update_stdout, _, _ = run_command(Commands.UPDATE, prefix, "--all") | ||
|
||
# this assertion works with the pinned_packages config to make sure | ||
# conda update --all still respects the pinned python version | ||
assert package_is_installed(prefix, "python=3.8") | ||
|
||
# pycosat should be in the SUPERSEDED list | ||
# after the 4.4 solver work, looks like it's in the DOWNGRADED list | ||
# This language needs changed anyway here. | ||
# For packages that CHANGE because they're being moved to a higher-priority channel | ||
# the message should be | ||
# | ||
# The following packages will be UPDATED to a higher-priority channel: | ||
# | ||
installed_str, x = update_stdout.split("UPDATED") | ||
assert re.search( | ||
r"pkgs/main::pycosat-0.6.3-py38h[^\s]+ --> conda-forge::pycosat", x | ||
) | ||
|
||
# python sys.version should show conda-forge python | ||
assert PrefixData(prefix).get("python").channel.name == "conda-forge" | ||
|
||
# conda list should show pycosat coming from conda-forge | ||
assert PrefixData(prefix).get("pycosat").channel.name == "conda-forge" | ||
|
||
|
||
@pytest.mark.integration | ||
def test_channel_priority_update(): | ||
"""This case will fail now.""" | ||
with make_temp_env("python=3.8", "pycosat") as prefix: | ||
assert package_is_installed(prefix, "python") | ||
|
||
# clear channels config first to not assume default is defaults | ||
payload, _, _ = run_command( | ||
Commands.CONFIG, prefix, "--get", "channels", "--json" | ||
) | ||
default_channels = json.loads(payload)["get"].get("channels") | ||
if default_channels: | ||
run_command(Commands.CONFIG, prefix, "--remove-key", "channels") | ||
|
||
# add conda-forge channel | ||
o, e, _ = run_command( | ||
Commands.CONFIG, | ||
prefix, | ||
"--prepend", | ||
"channels", | ||
"conda-forge", | ||
"--json", | ||
@pytest.mark.parametrize( | ||
"pinned_package", | ||
[ | ||
pytest.param(True, id="with pinned_package"), | ||
pytest.param(False, id="without pinned_package"), | ||
], | ||
) | ||
def test_reorder_channel_priority( | ||
tmp_env: TmpEnvFixture, | ||
monkeypatch: MonkeyPatch, | ||
conda_cli: CondaCLIFixture, | ||
pinned_package: bool, | ||
): | ||
# use "cheap" packages with no dependencies | ||
package1 = "zlib" | ||
package2 = "ca-certificates" | ||
|
||
# set pinned package | ||
if pinned_package: | ||
monkeypatch.setenv("CONDA_PINNED_PACKAGES", package1) | ||
|
||
# create environment with package1 and package2 | ||
with tmp_env( | ||
"--override-channels", "--channel=defaults", package1, package2 | ||
) as prefix: | ||
# check both packages are installed from defaults | ||
PrefixData._cache_.clear() | ||
assert PrefixData(prefix).get(package1).channel.name == "pkgs/main" | ||
assert PrefixData(prefix).get(package2).channel.name == "pkgs/main" | ||
|
||
# update --all | ||
conda_cli( | ||
"update", | ||
f"--prefix={prefix}", | ||
"--override-channels", | ||
"--channel=conda-forge", | ||
"--all", | ||
"--yes", | ||
) | ||
assert context.channels == ("conda-forge", "defaults"), o + e | ||
|
||
# update python | ||
update_stdout, _, _ = run_command(Commands.UPDATE, prefix, "python") | ||
|
||
# pycosat should be in the SUPERSEDED list | ||
superceded_split = update_stdout.split("UPDATED") | ||
assert len(superceded_split) == 2 | ||
assert "conda-forge" in superceded_split[1] | ||
|
||
# python sys.version should show conda-forge python | ||
assert PrefixData(prefix).get("python").channel.name == "conda-forge" | ||
# check pinned package is unchanged but unpinned packages are updated from conda-forge | ||
PrefixData._cache_.clear() | ||
expected_channel = "pkgs/main" if pinned_package else "conda-forge" | ||
assert PrefixData(prefix).get(package1).channel.name == expected_channel | ||
assert PrefixData(prefix).get(package2).channel.name == "conda-forge" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea!