-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix channel args cli #10735
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
Fix channel args cli #10735
Conversation
tests/base/test_context.py
Outdated
def test_channels_defaults(self): | ||
# no channels provided in cli | ||
reset_context(()) | ||
assert context.channels == ('defaults', ) | ||
|
||
def test_channels_defaults_condarc(self): | ||
# no channels provided in cli | ||
reset_context(()) | ||
string = dals(""" | ||
channels: ['defaults', 'conda-forge'] | ||
""") | ||
rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) | ||
context._set_raw_data(rd) | ||
assert context.channels == ('defaults', 'conda-forge') | ||
|
||
def test_specify_channels_cli_adding_defaults_no_condarc(self): | ||
# When the channel haven't been specified in condarc, 'defaults' | ||
# should be present when specifying channel in the cli | ||
reset_context((), argparse_args=AttrDict(channel=['conda-forge'])) | ||
assert context.channels == ('conda-forge', 'defaults') | ||
|
||
def test_specify_channels_cli_condarc(self): | ||
# When the channel have been specified in condarc, these channels | ||
# should be used along with the one specified | ||
reset_context((), argparse_args=AttrDict(channel=['conda-forge'])) | ||
string = dals(""" | ||
channels: ['defaults', 'conda-forge'] | ||
""") | ||
rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) | ||
context._set_raw_data(rd) | ||
assert context.channels == ('defaults', 'conda-forge') | ||
|
||
def test_specify_different_channels_cli_condarc(self): | ||
# When the channel have been specified in condarc, these channels | ||
# should be used along with the one specified | ||
# In this test, the given channel in cli is different from condarc | ||
# 'defaults' should not be added | ||
reset_context((), argparse_args=AttrDict(channel=['other'])) | ||
string = dals(""" | ||
channels: ['conda-forge'] | ||
""") | ||
rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) | ||
context._set_raw_data(rd) | ||
assert context.channels == ('conda-forge', 'other') |
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.
These tests check the current behaviour and pass without this PR.
At first, it was not clear to me when the |
@@ -720,11 +720,23 @@ def channels(self): | |||
if self._argparse_args and 'channel' in self._argparse_args: |
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.
This if
block is necessary to cover the case in test_specify_channels_cli_adding_defaults_no_condarc
.
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.
This looks good to me in general, here are just some suggestions around using docstrings in the test functions so the pytest traceback has the full context. Minor fixes around tuple syntax and docstring content as well.
Co-authored-by: Jannis Leidel <jannis@leidel.info>
Thanks @jezdez for the review, I have applied your suggestions! |
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.
Thanks @ericpre!
* Don't add 'defaults' channels when not necessary * Add config_files property to Context class to avoid duplicating code * Apply suggestions from code review: improve docstring and formatting Co-authored-by: Jannis Leidel <jannis@leidel.info>
Fix #10732.