Пример #1
0
    def test_normalize_urls(self):
        current_platform = config.subdir
        assert config.DEFAULT_CHANNEL_ALIAS == 'https://conda.anaconda.org/'
        assert config.rc.get('channel_alias') == 'https://your.repo/'

        for channel in config.normalize_urls([
                'defaults', 'system', 'https://anaconda.org/username',
                'file:///Users/username/repo', 'username'
        ]):
            assert (channel.endswith('/%s/' % current_platform)
                    or channel.endswith('/noarch/'))
        self.assertEqual(
            config.normalize_urls([
                'defaults', 'system', 'https://conda.anaconda.org/username',
                'file:///Users/username/repo', 'username'
            ], 'osx-64'), [
                'http://repo.continuum.io/pkgs/free/osx-64/',
                'http://repo.continuum.io/pkgs/free/noarch/',
                'http://repo.continuum.io/pkgs/pro/osx-64/',
                'http://repo.continuum.io/pkgs/pro/noarch/',
                'https://your.repo/binstar_username/osx-64/',
                'https://your.repo/binstar_username/noarch/',
                'http://some.custom/channel/osx-64/',
                'http://some.custom/channel/noarch/',
                'http://repo.continuum.io/pkgs/free/osx-64/',
                'http://repo.continuum.io/pkgs/free/noarch/',
                'http://repo.continuum.io/pkgs/pro/osx-64/',
                'http://repo.continuum.io/pkgs/pro/noarch/',
                'https://conda.anaconda.org/username/osx-64/',
                'https://conda.anaconda.org/username/noarch/',
                'file:///Users/username/repo/osx-64/',
                'file:///Users/username/repo/noarch/',
                'https://your.repo/username/osx-64/',
                'https://your.repo/username/noarch/',
            ])
Пример #2
0
    def test_normalize_urls(self):
        current_platform = config.subdir
        assert config.DEFAULT_CHANNEL_ALIAS == 'https://conda.anaconda.org/'
        assert config.rc.get('channel_alias') == 'https://your.repo/'

        for channel in config.normalize_urls(['defaults', 'system',
            'https://anaconda.org/username', 'file:///Users/username/repo',
            'username']):
            assert (channel.endswith('/%s/' % current_platform) or
                    channel.endswith('/noarch/'))
        self.assertEqual(config.normalize_urls([
            'defaults', 'system', 'https://conda.anaconda.org/username',
            'file:///Users/username/repo', 'username'
            ], 'osx-64'),
            [
                'http://repo.continuum.io/pkgs/free/osx-64/',
                'http://repo.continuum.io/pkgs/free/noarch/',
                'http://repo.continuum.io/pkgs/pro/osx-64/',
                'http://repo.continuum.io/pkgs/pro/noarch/',
                'https://your.repo/binstar_username/osx-64/',
                'https://your.repo/binstar_username/noarch/',
                'http://some.custom/channel/osx-64/',
                'http://some.custom/channel/noarch/',
                'http://repo.continuum.io/pkgs/free/osx-64/',
                'http://repo.continuum.io/pkgs/free/noarch/',
                'http://repo.continuum.io/pkgs/pro/osx-64/',
                'http://repo.continuum.io/pkgs/pro/noarch/',
                'https://conda.anaconda.org/username/osx-64/',
                'https://conda.anaconda.org/username/noarch/',
                'file:///Users/username/repo/osx-64/',
                'file:///Users/username/repo/noarch/',
                'https://your.repo/username/osx-64/',
                'https://your.repo/username/noarch/',
                ])
Пример #3
0
Файл: api.py Проект: 3kwa/conda
def get_index(channel_urls=(), prepend=True, platform=None,
              use_cache=False, unknown=False, offline=False,
              prefix=None):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    If prefix is supplied, then the packages installed in that prefix are added.
    """
    channel_urls = config.normalize_urls(channel_urls, platform=platform)
    if prepend:
        channel_urls += config.get_channel_urls(platform=platform)
    if offline:
        channel_urls = [url for url in channel_urls if url.startswith('file:')]
    index = fetch_index(tuple(channel_urls), use_cache=use_cache,
                        unknown=unknown)
    if prefix:
        for dist, info in iteritems(install.linked_data(prefix)):
            fn = dist + '.tar.bz2'
            if fn not in index:
                # only if the package in not in the repodata, use local
                # conda-meta (with 'depends' defaulting to [])
                info.setdefault('depends', [])
                index[fn] = info
    return index
Пример #4
0
def get_index(channel_urls=(), prepend=True, platform=None,
              use_cache=False, unknown=False, offline=False,
              prefix=None):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    If prefix is supplied, then the packages installed in that prefix are added.
    """
    channel_urls = config.normalize_urls(channel_urls, platform=platform)
    if prepend:
        channel_urls += config.get_channel_urls(platform=platform)
    if offline:
        channel_urls = [url for url in channel_urls if url.startswith('file:')]
    index = fetch_index(tuple(channel_urls), use_cache=use_cache,
                       unknown=unknown)
    if prefix:
        for fn, info in iteritems(install.linked_data(prefix)):
            fn = fn + '.tar.bz2'
            orec = index.get(fn)
            if orec is not None:
                if orec.get('md5',None) == info.get('md5',None):
                    continue
                info.setdefault('depends',orec.get('depends',[]))
            index[fn] = info
    return index
Пример #5
0
def get_index(channel_urls=(), prepend=True, platform=None,
              use_cache=False, unknown=False, offline=False,
              prefix=None):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    If prefix is supplied, then the packages installed in that prefix are added.
    """
    channel_urls = config.normalize_urls(channel_urls, platform, offline)
    if prepend:
        pri0 = max(itervalues(channel_urls)) if channel_urls else 0
        for url, rec in iteritems(config.get_channel_urls(platform, offline)):
            channel_urls[url] = (rec[0], rec[1] + pri0)
    index = fetch_index(channel_urls, use_cache=use_cache, unknown=unknown)
    if prefix:
        for dist, info in iteritems(install.linked_data(prefix)):
            fn = dist + '.tar.bz2'
            channel = info.get('channel', '')
            if channel not in channel_urls:
                channel_urls[channel] = (config.canonical_channel_name(channel, True, True), 0)
            url_s, priority = channel_urls[channel]
            key = url_s + '::' + fn if url_s else fn
            if key not in index:
                # only if the package in not in the repodata, use local
                # conda-meta (with 'depends' defaulting to [])
                info.setdefault('depends', [])
                info['fn'] = fn
                info['schannel'] = url_s
                info['channel'] = channel
                info['url'] = channel + fn
                info['priority'] = priority
                index[key] = info
    return index
Пример #6
0
def get_index(channel_urls=(), prepend=True, platform=None,
              use_local=False, use_cache=False, unknown=False,
              offline=False, prefix=None):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    If prefix is supplied, then the packages installed in that prefix are added.
    """
    if use_local:
        channel_urls = ['local'] + list(channel_urls)
    channel_urls = normalize_urls(channel_urls, platform, offline)
    if prepend:
        channel_urls.extend(get_channel_urls(platform, offline))
    channel_urls = prioritize_channels(channel_urls)
    index = fetch_index(channel_urls, use_cache=use_cache, unknown=unknown)
    if prefix:
        priorities = {c: p for c, p in itervalues(channel_urls)}
        for dist, info in iteritems(install.linked_data(prefix)):
            fn = info['fn']
            schannel = info['schannel']
            prefix = '' if schannel == 'defaults' else schannel + '::'
            priority = priorities.get(schannel, 0)
            key = prefix + fn
            if key in index:
                # Copy the link information so the resolver knows this is installed
                index[key]['link'] = info.get('link')
            else:
                # only if the package in not in the repodata, use local
                # conda-meta (with 'depends' defaulting to [])
                info.setdefault('depends', [])
                info['priority'] = priority
                index[key] = info
    return index
Пример #7
0
def get_index(channel_urls=(), prepend=True, platform=None,
              use_cache=False, unknown=False, offline=False,
              prefix=None):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    If prefix is supplied, then the packages installed in that prefix are added.
    """
    channel_urls = config.normalize_urls(channel_urls, platform=platform)
    if prepend:
        channel_urls += config.get_channel_urls(platform=platform)
    if offline:
        channel_urls = [url for url in channel_urls if url.startswith('file:')]
    index = fetch_index(tuple(channel_urls), use_cache=use_cache,
                        unknown=unknown)
    if prefix:
        for dist, info in iteritems(install.linked_data(prefix)):
            fn = dist + '.tar.bz2'
            if fn not in index:
                # only if the package in not in the repodata, use local
                # conda-meta (with 'depends' defaulting to [])
                info.setdefault('depends', [])
                index[fn] = info
    return index
Пример #8
0
def get_index(channel_urls=(), prepend=True):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    """
    channel_urls = config.normalize_urls(channel_urls)
    if prepend:
        channel_urls += config.get_channel_urls()
    return fetch_index(tuple(channel_urls))
Пример #9
0
    def test_normalize_urls(self):
        current_platform = config.subdir
        assert config.DEFAULT_CHANNEL_ALIAS == 'https://conda.anaconda.org/'
        assert config.rc.get('channel_alias') == 'https://your.repo/'
        assert config.channel_alias == 'https://your.repo/'

        normurls = config.normalize_urls([
            'defaults', 'system', 'https://conda.anaconda.org/username',
            'file:///Users/username/repo', 'username'
        ], 'osx-64')
        assert normurls == [
            'http://repo.continuum.io/pkgs/free/osx-64/',
            'http://repo.continuum.io/pkgs/free/noarch/',
            'http://repo.continuum.io/pkgs/pro/osx-64/',
            'http://repo.continuum.io/pkgs/pro/noarch/',
            'https://your.repo/binstar_username/osx-64/',
            'https://your.repo/binstar_username/noarch/',
            'http://some.custom/channel/osx-64/',
            'http://some.custom/channel/noarch/',
            'http://repo.continuum.io/pkgs/free/osx-64/',
            'http://repo.continuum.io/pkgs/free/noarch/',
            'http://repo.continuum.io/pkgs/pro/osx-64/',
            'http://repo.continuum.io/pkgs/pro/noarch/',
            'https://conda.anaconda.org/username/osx-64/',
            'https://conda.anaconda.org/username/noarch/',
            'file:///Users/username/repo/osx-64/',
            'file:///Users/username/repo/noarch/',
            'https://your.repo/username/osx-64/',
            'https://your.repo/username/noarch/'
        ]
        priurls = config.prioritize_channels(normurls)
        assert dict(priurls) == {
            'file:///Users/username/repo/noarch/':
            ('file:///Users/username/repo', 5),
            'file:///Users/username/repo/osx-64/':
            ('file:///Users/username/repo', 5),
            'http://repo.continuum.io/pkgs/free/noarch/': ('defaults', 1),
            'http://repo.continuum.io/pkgs/free/osx-64/': ('defaults', 1),
            'http://repo.continuum.io/pkgs/pro/noarch/': ('defaults', 1),
            'http://repo.continuum.io/pkgs/pro/osx-64/': ('defaults', 1),
            'http://some.custom/channel/noarch/':
            ('http://some.custom/channel', 3),
            'http://some.custom/channel/osx-64/':
            ('http://some.custom/channel', 3),
            'https://conda.anaconda.org/username/noarch/':
            ('https://conda.anaconda.org/username', 4),
            'https://conda.anaconda.org/username/osx-64/':
            ('https://conda.anaconda.org/username', 4),
            'https://your.repo/binstar_username/noarch/': ('binstar_username',
                                                           2),
            'https://your.repo/binstar_username/osx-64/': ('binstar_username',
                                                           2),
            'https://your.repo/username/noarch/': ('username', 6),
            'https://your.repo/username/osx-64/': ('username', 6)
        }
Пример #10
0
def test_installable(channel='defaults', verbose=True):
    if not verbose:
        sys.stdout = open(os.devnull, 'w')

    success = False
    has_py = re.compile(r'py(\d)(\d)')
    for platform in ['osx-64', 'linux-32', 'linux-64', 'win-32', 'win-64']:
        print("######## Testing platform %s ########" % platform)
        channels = [channel] + get_default_urls()
        index = get_index(channel_urls=channels,
                          prepend=False,
                          platform=platform)
        for package in sorted(index):
            if channel != 'defaults':
                # If we give channels at the command line, only look at
                # packages from those channels (not defaults).
                if index[package]['channel'] not in normalize_urls(
                    [channel], platform=platform):
                    continue
            name, version, build = package.rsplit('.tar.bz2',
                                                  1)[0].rsplit('-', 2)
            if name in {'conda', 'conda-build'}:
                # conda can only be installed in the root environment
                continue
            # Don't fail just because the package is a different version of Python
            # than the default.  We should probably check depends rather than the
            # build string.
            match = has_py.search(build)
            assert match if 'py' in build else True, build
            if match:
                additional_packages = [
                    'python=%s.%s' % (match.group(1), match.group(2))
                ]
            else:
                additional_packages = []

            print('Testing %s=%s' % (name, version))
            # if additional_packages:
            #     print("Including %s" % additional_packages[0])

            try:
                check_install([name + '=' + version] + additional_packages,
                              channel_urls=channels,
                              prepend=False,
                              platform=platform)
            except KeyboardInterrupt:
                raise
            # sys.exit raises an exception that doesn't subclass from Exception
            except BaseException as e:
                success = True
                print("FAIL: %s %s on %s with %s (%s)" %
                      (name, version, platform, additional_packages, e),
                      file=sys.stderr)

    return success
Пример #11
0
def get_index(channel_urls=(), prepend=True, platform=None):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    """
    channel_urls = config.normalize_urls(channel_urls, platform=platform)
    if prepend:
        channel_urls += config.get_channel_urls(platform=platform)
    return fetch_index(tuple(channel_urls))
Пример #12
0
def get_index(channel_urls=(), prepend=True, platform=None, use_cache=False):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    """
    channel_urls = config.normalize_urls(channel_urls, platform=platform)
    if prepend:
        channel_urls += config.get_channel_urls(platform=platform)
    return fetch_index(tuple(channel_urls), use_cache=use_cache)
Пример #13
0
def get_index(channel_urls=(), prepend=True, platform=None, use_cache=False, unknown=False, offline=False):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    """
    channel_urls = config.normalize_urls(channel_urls, platform=platform)
    if prepend:
        channel_urls += config.get_channel_urls(platform=platform)
    if offline:
        channel_urls = [url for url in channel_urls if url.startswith("file:")]
    return fetch_index(tuple(channel_urls), use_cache=use_cache, unknown=unknown)
Пример #14
0
def get_index(channel_urls=(), prepend=True, platform=None,
              use_cache=False, unknown=False, offline=False):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    """
    channel_urls = config.normalize_urls(channel_urls, platform=platform)
    if prepend:
        channel_urls += config.get_channel_urls(platform=platform)
    if offline:
        channel_urls = [url for url in channel_urls if url.startswith('file:')]
    return fetch_index(tuple(channel_urls), use_cache=use_cache,
                       unknown=unknown)
Пример #15
0
def test_installable(channel='defaults', verbose=True):
    if not verbose:
        sys.stdout = open(os.devnull, 'w')

    success = False
    has_py = re.compile(r'py(\d)(\d)')
    for platform in ['osx-64', 'linux-32', 'linux-64', 'win-32', 'win-64']:
        print("######## Testing platform %s ########" % platform)
        channels = [channel] + get_default_urls()
        index = get_index(channel_urls=channels, prepend=False, platform=platform)
        for package in sorted(index):
            if channel != 'defaults':
                # If we give channels at the command line, only look at
                # packages from those channels (not defaults).
                if index[package]['channel'] not in normalize_urls([channel], platform=platform):
                    continue
            name, version, build = package.rsplit('.tar.bz2', 1)[0].rsplit('-', 2)
            if name in {'conda', 'conda-build'}:
                # conda can only be installed in the root environment
                continue
            # Don't fail just because the package is a different version of Python
            # than the default.  We should probably check depends rather than the
            # build string.
            match = has_py.search(build)
            assert match if 'py' in build else True, build
            if match:
                additional_packages = ['python=%s.%s' % (match.group(1), match.group(2))]
            else:
                additional_packages = []

            print('Testing %s=%s' % (name, version))
            # if additional_packages:
            #     print("Including %s" % additional_packages[0])

            try:
                check_install([name + '=' + version] + additional_packages,
                    channel_urls=channels, prepend=False,
                    platform=platform)
            except KeyboardInterrupt:
                raise
            # sys.exit raises an exception that doesn't subclass from Exception
            except BaseException as e:
                success = True
                print("FAIL: %s %s on %s with %s (%s)" % (name, version,
                    platform, additional_packages, e), file=sys.stderr)

    return success
Пример #16
0
    def test_normalize_urls(self):
        current_platform = config.subdir
        assert config.DEFAULT_CHANNEL_ALIAS == 'https://conda.anaconda.org/'
        assert config.rc.get('channel_alias') == 'https://your.repo/'
        assert config.channel_alias == 'https://your.repo/'

        normurls = config.normalize_urls([
            'defaults', 'system', 'https://conda.anaconda.org/username',
            'file:///Users/username/repo', 'username'
            ], 'osx-64')
        assert normurls == [
             'http://repo.continuum.io/pkgs/free/osx-64/',
             'http://repo.continuum.io/pkgs/free/noarch/',
             'http://repo.continuum.io/pkgs/pro/osx-64/',
             'http://repo.continuum.io/pkgs/pro/noarch/',
             'https://your.repo/binstar_username/osx-64/',
             'https://your.repo/binstar_username/noarch/',
             'http://some.custom/channel/osx-64/',
             'http://some.custom/channel/noarch/',
             'http://repo.continuum.io/pkgs/free/osx-64/',
             'http://repo.continuum.io/pkgs/free/noarch/',
             'http://repo.continuum.io/pkgs/pro/osx-64/',
             'http://repo.continuum.io/pkgs/pro/noarch/',
             'https://conda.anaconda.org/username/osx-64/',
             'https://conda.anaconda.org/username/noarch/',
             'file:///Users/username/repo/osx-64/',
             'file:///Users/username/repo/noarch/',
             'https://your.repo/username/osx-64/',
             'https://your.repo/username/noarch/']
        priurls = config.prioritize_channels(normurls)
        assert dict(priurls) == {
             'file:///Users/username/repo/noarch/': ('file:///Users/username/repo', 5),
             'file:///Users/username/repo/osx-64/': ('file:///Users/username/repo', 5),
             'http://repo.continuum.io/pkgs/free/noarch/': ('defaults', 1),
             'http://repo.continuum.io/pkgs/free/osx-64/': ('defaults', 1),
             'http://repo.continuum.io/pkgs/pro/noarch/': ('defaults', 1),
             'http://repo.continuum.io/pkgs/pro/osx-64/': ('defaults', 1),
             'http://some.custom/channel/noarch/': ('http://some.custom/channel', 3),
             'http://some.custom/channel/osx-64/': ('http://some.custom/channel', 3),
             'https://conda.anaconda.org/username/noarch/': ('https://conda.anaconda.org/username', 4),
             'https://conda.anaconda.org/username/osx-64/': ('https://conda.anaconda.org/username', 4),
             'https://your.repo/binstar_username/noarch/': ('binstar_username', 2),
             'https://your.repo/binstar_username/osx-64/': ('binstar_username', 2),
             'https://your.repo/username/noarch/': ('username', 6),
             'https://your.repo/username/osx-64/': ('username', 6)}
Пример #17
0
def get_index(channel_urls=(),
              prepend=True,
              platform=None,
              use_local=False,
              use_cache=False,
              unknown=False,
              offline=False,
              prefix=None):
    """
    Return the index of packages available on the channels

    If prepend=False, only the channels passed in as arguments are used.
    If platform=None, then the current platform is used.
    If prefix is supplied, then the packages installed in that prefix are added.
    """
    if use_local:
        channel_urls = ['local'] + list(channel_urls)
    channel_urls = normalize_urls(channel_urls, platform, offline)
    if prepend:
        channel_urls.extend(get_channel_urls(platform, offline))
    channel_urls = prioritize_channels(channel_urls)
    index = fetch_index(channel_urls, use_cache=use_cache, unknown=unknown)
    if prefix:
        priorities = {c: p for c, p in itervalues(channel_urls)}
        maxp = max(itervalues(priorities)) + 1 if priorities else 1
        for dist, info in iteritems(install.linked_data(prefix)):
            fn = info['fn']
            schannel = info['schannel']
            prefix = '' if schannel == 'defaults' else schannel + '::'
            priority = priorities.get(schannel, maxp)
            key = prefix + fn
            if key in index:
                # Copy the link information so the resolver knows this is installed
                index[key]['link'] = info.get('link')
            else:
                # only if the package in not in the repodata, use local
                # conda-meta (with 'depends' defaulting to [])
                info.setdefault('depends', [])
                info['priority'] = priority
                index[key] = info
    return index
Пример #18
0
    def test_normalize_urls(self):
        current_platform = config.subdir
        assert config.DEFAULT_CHANNEL_ALIAS == 'https://conda.anaconda.org/'
        assert config.rc.get('channel_alias') == 'https://your.repo/'
        assert config.channel_prefix(False) == 'https://your.repo/'
        assert config.binstar_domain == 'https://mybinstar.com/'
        assert config.binstar_domain_tok == 'https://mybinstar.com/t/01234abcde/'

        channel_urls = [
            'defaults', 'system', 
            'https://conda.anaconda.org/username',
            'file:///Users/username/repo', 
            'https://mybinstar.com/t/5768wxyz/test2', 
            'https://mybinstar.com/test', 
            'https://conda.anaconda.org/t/abcdefgh/username', 
            'username'
        ]
        platform = 'osx-64'

        normurls = config.normalize_urls(channel_urls, platform)
        assert normurls == [
           # defaults
           'https://repo.continuum.io/pkgs/free/osx-64/',
           'https://repo.continuum.io/pkgs/free/noarch/',
           'https://repo.continuum.io/pkgs/pro/osx-64/',
           'https://repo.continuum.io/pkgs/pro/noarch/',
           # system (condarc)
           'https://your.repo/binstar_username/osx-64/',
           'https://your.repo/binstar_username/noarch/',
           'http://some.custom/channel/osx-64/',
           'http://some.custom/channel/noarch/',
           # defaults is repeated in condarc; that's OK
           'https://repo.continuum.io/pkgs/free/osx-64/',
           'https://repo.continuum.io/pkgs/free/noarch/',
           'https://repo.continuum.io/pkgs/pro/osx-64/',
           'https://repo.continuum.io/pkgs/pro/noarch/',
           # conda.anaconda.org is not our default binstar clinet
           'https://conda.anaconda.org/username/osx-64/',
           'https://conda.anaconda.org/username/noarch/',
           'file:///Users/username/repo/osx-64/',
           'file:///Users/username/repo/noarch/',
           # mybinstar.com is not channel_alias, but we still add tokens
           'https://mybinstar.com/t/5768wxyz/test2/osx-64/',
           'https://mybinstar.com/t/5768wxyz/test2/noarch/',
           # token already supplied, do not change/remove it
           'https://mybinstar.com/t/01234abcde/test/osx-64/',
           'https://mybinstar.com/t/01234abcde/test/noarch/',
           # we do not remove tokens from conda.anaconda.org
           'https://conda.anaconda.org/t/abcdefgh/username/osx-64/',
           'https://conda.anaconda.org/t/abcdefgh/username/noarch/',
           # short channel; add channel_alias
           'https://your.repo/username/osx-64/',
           'https://your.repo/username/noarch/']

        priurls = config.prioritize_channels(normurls)
        assert dict(priurls) == {
           # defaults appears twice, keep higher priority
           'https://repo.continuum.io/pkgs/free/noarch/': ('defaults', 1),
           'https://repo.continuum.io/pkgs/free/osx-64/': ('defaults', 1),
           'https://repo.continuum.io/pkgs/pro/noarch/': ('defaults', 1),
           'https://repo.continuum.io/pkgs/pro/osx-64/': ('defaults', 1),
           'https://your.repo/binstar_username/noarch/': ('binstar_username', 2),
           'https://your.repo/binstar_username/osx-64/': ('binstar_username', 2),
           'http://some.custom/channel/noarch/': ('http://some.custom/channel', 3),
           'http://some.custom/channel/osx-64/': ('http://some.custom/channel', 3),
           'https://conda.anaconda.org/t/abcdefgh/username/noarch/': ('https://conda.anaconda.org/username', 4),
           'https://conda.anaconda.org/t/abcdefgh/username/osx-64/': ('https://conda.anaconda.org/username', 4),
           'file:///Users/username/repo/noarch/': ('file:///Users/username/repo', 5),
           'file:///Users/username/repo/osx-64/': ('file:///Users/username/repo', 5),
           # the tokenized version came first, but we still give it the same priority
           'https://conda.anaconda.org/username/noarch/': ('https://conda.anaconda.org/username', 4),
           'https://conda.anaconda.org/username/osx-64/': ('https://conda.anaconda.org/username', 4),
           'https://mybinstar.com/t/5768wxyz/test2/noarch/': ('https://mybinstar.com/test2', 6),
           'https://mybinstar.com/t/5768wxyz/test2/osx-64/': ('https://mybinstar.com/test2', 6),
           'https://mybinstar.com/t/01234abcde/test/noarch/': ('https://mybinstar.com/test', 7),
           'https://mybinstar.com/t/01234abcde/test/osx-64/': ('https://mybinstar.com/test', 7),
           'https://your.repo/username/noarch/': ('username', 8),
           'https://your.repo/username/osx-64/': ('username', 8)
        }

        # Delete the channel alias so now the short channels point to binstar
        del config.rc['channel_alias']
        config.rc['offline'] = False
        config.load_condarc()
        config.binstar_client = BinstarTester()
        normurls = config.normalize_urls(channel_urls, platform)
        # all your.repo references should be changed to mybinstar.com
        assert normurls == [
           'https://repo.continuum.io/pkgs/free/osx-64/',
           'https://repo.continuum.io/pkgs/free/noarch/',
           'https://repo.continuum.io/pkgs/pro/osx-64/',
           'https://repo.continuum.io/pkgs/pro/noarch/',
           'https://mybinstar.com/t/01234abcde/binstar_username/osx-64/',
           'https://mybinstar.com/t/01234abcde/binstar_username/noarch/',
           'http://some.custom/channel/osx-64/',
           'http://some.custom/channel/noarch/',
           'https://repo.continuum.io/pkgs/free/osx-64/',
           'https://repo.continuum.io/pkgs/free/noarch/',
           'https://repo.continuum.io/pkgs/pro/osx-64/',
           'https://repo.continuum.io/pkgs/pro/noarch/',
           'https://conda.anaconda.org/username/osx-64/',
           'https://conda.anaconda.org/username/noarch/',
           'file:///Users/username/repo/osx-64/',
           'file:///Users/username/repo/noarch/',
           'https://mybinstar.com/t/5768wxyz/test2/osx-64/',
           'https://mybinstar.com/t/5768wxyz/test2/noarch/',
           'https://mybinstar.com/t/01234abcde/test/osx-64/',
           'https://mybinstar.com/t/01234abcde/test/noarch/',
           'https://conda.anaconda.org/t/abcdefgh/username/osx-64/',
           'https://conda.anaconda.org/t/abcdefgh/username/noarch/',
           'https://mybinstar.com/t/01234abcde/username/osx-64/',
           'https://mybinstar.com/t/01234abcde/username/noarch/'
        ]

        # Delete the anaconda token
        config.load_condarc()
        config.binstar_client = BinstarTester(token=None)
        normurls = config.normalize_urls(channel_urls, platform)
        # tokens should not be added (but supplied tokens are kept)
        assert normurls == [
           'https://repo.continuum.io/pkgs/free/osx-64/',
           'https://repo.continuum.io/pkgs/free/noarch/',
           'https://repo.continuum.io/pkgs/pro/osx-64/',
           'https://repo.continuum.io/pkgs/pro/noarch/',
           'https://mybinstar.com/binstar_username/osx-64/',
           'https://mybinstar.com/binstar_username/noarch/',
           'http://some.custom/channel/osx-64/',
           'http://some.custom/channel/noarch/',
           'https://repo.continuum.io/pkgs/free/osx-64/',
           'https://repo.continuum.io/pkgs/free/noarch/',
           'https://repo.continuum.io/pkgs/pro/osx-64/',
           'https://repo.continuum.io/pkgs/pro/noarch/',
           'https://conda.anaconda.org/username/osx-64/',
           'https://conda.anaconda.org/username/noarch/',
           'file:///Users/username/repo/osx-64/',
           'file:///Users/username/repo/noarch/',
           'https://mybinstar.com/t/5768wxyz/test2/osx-64/',
           'https://mybinstar.com/t/5768wxyz/test2/noarch/',
           'https://mybinstar.com/test/osx-64/',
           'https://mybinstar.com/test/noarch/',
           'https://conda.anaconda.org/t/abcdefgh/username/osx-64/',
           'https://conda.anaconda.org/t/abcdefgh/username/noarch/',
           'https://mybinstar.com/username/osx-64/',
           'https://mybinstar.com/username/noarch/'
        ]

        # Turn off add_anaconda_token
        config.rc['add_binstar_token'] = False
        config.load_condarc()
        config.binstar_client = BinstarTester()
        normurls2 = config.normalize_urls(channel_urls, platform)
        # tokens should not be added (but supplied tokens are kept)
        assert normurls == normurls2

        # Disable binstar client altogether
        config.load_condarc()
        config.binstar_client = ()
        normurls = config.normalize_urls(channel_urls, platform)
        # should drop back to conda.anaconda.org
        assert normurls == [
          'https://repo.continuum.io/pkgs/free/osx-64/',
          'https://repo.continuum.io/pkgs/free/noarch/',
          'https://repo.continuum.io/pkgs/pro/osx-64/',
          'https://repo.continuum.io/pkgs/pro/noarch/',
          'https://conda.anaconda.org/binstar_username/osx-64/',
          'https://conda.anaconda.org/binstar_username/noarch/',
          'http://some.custom/channel/osx-64/',
          'http://some.custom/channel/noarch/',
          'https://repo.continuum.io/pkgs/free/osx-64/',
          'https://repo.continuum.io/pkgs/free/noarch/',
          'https://repo.continuum.io/pkgs/pro/osx-64/',
          'https://repo.continuum.io/pkgs/pro/noarch/',
          'https://conda.anaconda.org/username/osx-64/',
          'https://conda.anaconda.org/username/noarch/',
          'file:///Users/username/repo/osx-64/',
          'file:///Users/username/repo/noarch/',
          'https://mybinstar.com/t/5768wxyz/test2/osx-64/',
          'https://mybinstar.com/t/5768wxyz/test2/noarch/',
          'https://mybinstar.com/test/osx-64/',
          'https://mybinstar.com/test/noarch/',
          'https://conda.anaconda.org/t/abcdefgh/username/osx-64/',
          'https://conda.anaconda.org/t/abcdefgh/username/noarch/',
          'https://conda.anaconda.org/username/osx-64/',
          'https://conda.anaconda.org/username/noarch/'
        ]