Skip to content

Commit

Permalink
Merge pull request conda#3306 from HugoTian/priority
Browse files Browse the repository at this point in the history
fix update idempotency; add tests for channel priority
  • Loading branch information
kalefranz authored Aug 18, 2016
2 parents f9d386e + ae15fb9 commit 5cfefba
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ tmpfile.rc
.coverage*
*.bz2
tempfile.rc
*.ipynb
7 changes: 5 additions & 2 deletions conda/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,12 @@ def install(args, parser, command='install'):
for name in orig_packages:
vers_inst = [m['version'] for m in installed_metadata if m['name'] == name]
build_inst = [m['build_number'] for m in installed_metadata if m['name'] == name]
channel_inst = [m['channel'] for m in installed_metadata if m['name'] == name]

try:
assert len(vers_inst) == 1, name
assert len(build_inst) == 1, name
assert len(channel_inst) == 1, name
except AssertionError as e:
raise CondaAssertionError(text_type(e))

Expand All @@ -260,8 +262,9 @@ def install(args, parser, command='install'):
continue
latest = pkgs[-1]

if (latest.version == vers_inst[0] and
latest.build_number == build_inst[0]):
if all([latest.version == vers_inst[0],
latest.build_number == build_inst[0],
latest.channel == channel_inst[0]]):
args.packages.remove(name)
if not args.packages:
from .main_list import print_packages
Expand Down
2 changes: 1 addition & 1 deletion tests/conda_env/support/notebook.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"worksheets": [{"cells": []}], "metadata": {"name": "", "signature": ""}, "nbformat": 3, "nbformat_minor": 0}
{"worksheets": [{"cells": []}], "metadata": {"name": "", "signature": ""}, "nbformat": 3, "nbformat_minor": 0}
25 changes: 14 additions & 11 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,24 @@ class Commands:


def run_command(command, prefix, *arguments):
arguments = list(arguments)
p, sub_parsers = generate_parser()
parser_config[command](sub_parsers)

prefix = escape_for_winpath(prefix)
arguments = list(map(escape_for_winpath, arguments))
if command is Commands.CONFIG:
command_line = "{0} --file {1} {2}".format(command, join(prefix, 'condarc'), " ".join(arguments))
elif command is Commands.SEARCH:
command_line = "{0} {1}".format(command, " ".join(arguments))
elif command is Commands.LIST:
command_line = "{0} -p {1} {2}".format(command, prefix, " ".join(arguments))
else: # CREATE, INSTALL, REMOVE, UPDATE
command_line = "{0} -y -q -p {1} {2}".format(command, prefix, " ".join(arguments))
arguments.append("--file {0}".format(join(prefix, 'condarc')))
if command in (Commands.LIST, Commands.CREATE, Commands.INSTALL,
Commands.REMOVE, Commands.UPDATE):
arguments.append("-p {0}".format(prefix))
if command in (Commands.CREATE, Commands.INSTALL, Commands.REMOVE, Commands.UPDATE):
arguments.extend(["-y", "-q"])

arguments = list(map(escape_for_winpath, arguments))
command_line = "{0} {1}".format(command, " ".join(arguments))

args = p.parse_args(split(command_line))
context._add_argparse_args(args)
print("executing command >>>", command_line)
with captured() as c:
args.func(args, p)
print(c.stderr, file=sys.stderr)
Expand All @@ -104,19 +106,20 @@ def run_command(command, prefix, *arguments):
@contextmanager
def make_temp_env(*packages, **kwargs):
prefix = kwargs.pop('prefix', None) or make_temp_prefix()
assert isdir(prefix), prefix
with stderr_log_level(DEBUG, 'conda'), stderr_log_level(DEBUG, 'requests'):
with disable_logger('fetch'), disable_logger('dotupdate'):
try:
# try to clear any config that's been set by other tests
reset_context([join(prefix, 'condarc')])
reset_context([os.path.join(prefix+os.sep, 'condarc')])
run_command(Commands.CREATE, prefix, *packages)
yield prefix
finally:
rmtree(prefix, ignore_errors=True)


def reload_config(prefix):
prefix_condarc = join(prefix, 'condarc')
prefix_condarc = join(prefix+os.sep, 'condarc')
reset_context([prefix_condarc])


Expand Down
57 changes: 57 additions & 0 deletions tests/test_priority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from unittest import TestCase
import pytest
from .test_create import (make_temp_env, assert_package_is_installed
, run_command, Commands, get_conda_list_tuple)
from conda.base.context import context

class PriorityTest(TestCase):

@pytest.mark.timeout(300)
def test_channel_order_channel_priority_true(self):
with make_temp_env("python=3 pycosat==0.6.1") as prefix:
assert_package_is_installed(prefix, 'python')
assert_package_is_installed(prefix, 'pycosat')

# 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')

# pycosat should be in the SUPERCEDED list
superceded_split = update_stdout.split('SUPERCEDED')
assert len(superceded_split) == 2
assert 'pycosat' in superceded_split[1]

# python sys.version should show conda-forge python
python_tuple = get_conda_list_tuple(prefix, "python")
assert python_tuple[3] == 'conda-forge'
# conda list should show pycosat coming from conda-forge
pycosat_tuple = get_conda_list_tuple(prefix, "pycosat")
assert pycosat_tuple[3] == 'conda-forge'


@pytest.mark.timeout(300)
def test_channel_priority_update(self):
"""
This case will fail now
"""
with make_temp_env("python=3 ") as prefix:
assert_package_is_installed(prefix, 'python')

# 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 python
update_stdout, _ = run_command(Commands.UPDATE, prefix, 'python')

# pycosat should be in the SUPERCEDED 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
python_tuple = get_conda_list_tuple(prefix, "python")
assert python_tuple[3] == 'conda-forge'

0 comments on commit 5cfefba

Please sign in to comment.