Ejemplo n.º 1
0
    def test_shortcut_absent_when_condarc_set(self):
        from menuinst.win32 import dirs as win_locations
        user_mode = 'user' if exists(join(sys.prefix, u'.nonadmin')) else 'system'
        shortcut_dir = win_locations[user_mode]["start"]
        shortcut_dir = join(shortcut_dir, "Anaconda{0} ({1}-bit)"
                                          "".format(sys.version_info.major, config.bits))

        prefix = make_temp_prefix(str(uuid4())[:7])
        shortcut_file = join(shortcut_dir, "Anaconda Prompt ({0}).lnk".format(basename(prefix)))
        assert not isfile(shortcut_file)

        try:
            # set condarc shortcuts: False
            config.load_condarc("")
            run_command(Commands.CONFIG, prefix, "--set shortcuts false")
            stdout, stderr = run_command(Commands.CONFIG, prefix, "--get", "--json")
            json_obj = json_loads(stdout)
            # assert json_obj['rc_path'] == join(prefix, 'condarc')
            assert json_obj['get']['shortcuts'] is False

            # including shortcuts: False should not get shortcuts installed
            run_command(Commands.CREATE, prefix, "console_shortcut")
            assert package_is_installed(prefix, 'console_shortcut')
            assert not isfile(shortcut_file)

            # make sure that cleanup without specifying --shortcuts still removes shortcuts
            run_command(Commands.REMOVE, prefix, 'console_shortcut')
            assert not package_is_installed(prefix, 'console_shortcut')
            assert not isfile(shortcut_file)
        finally:
            rmtree(prefix, ignore_errors=True)
            if isfile(shortcut_file):
                os.remove(shortcut_file)
Ejemplo n.º 2
0
    def test_shortcut_absent_does_not_barf_on_uninstall(self):
        from menuinst.win32 import dirs as win_locations

        user_mode = 'user' if exists(join(sys.prefix, u'.nonadmin')) else 'system'
        shortcut_dir = win_locations[user_mode]["start"]
        shortcut_dir = join(shortcut_dir, "Anaconda{0} ({1}-bit)"
                                          "".format(sys.version_info.major, config.bits))

        prefix = make_temp_prefix(str(uuid4())[:7])
        shortcut_file = join(shortcut_dir, "Anaconda Prompt ({0}).lnk".format(basename(prefix)))
        assert not isfile(shortcut_file)

        try:
            # not including --shortcuts, should not get shortcuts installed
            config.load_condarc("")
            run_command(Commands.CREATE, prefix, "console_shortcut")
            assert package_is_installed(prefix, 'console_shortcut')
            assert not isfile(shortcut_file)

            # make sure that cleanup without specifying --shortcuts still removes shortcuts
            run_command(Commands.REMOVE, prefix, 'console_shortcut')
            assert not package_is_installed(prefix, 'console_shortcut')
            assert not isfile(shortcut_file)
        finally:
            rmtree(prefix, ignore_errors=True)
            if isfile(shortcut_file):
                os.remove(shortcut_file)
Ejemplo n.º 3
0
    def test_shortcut_creation_installs_shortcut(self):
        from menuinst.win32 import dirs as win_locations

        user_mode = 'user' if exists(join(sys.prefix,
                                          u'.nonadmin')) else 'system'
        shortcut_dir = win_locations[user_mode]["start"]
        shortcut_dir = join(
            shortcut_dir, "Anaconda{0} ({1}-bit)"
            "".format(sys.version_info.major, config.bits))

        prefix = make_temp_prefix(str(uuid4())[:7])
        shortcut_file = join(
            shortcut_dir, "Anaconda Prompt ({0}).lnk".format(basename(prefix)))
        try:
            config.load_condarc("")
            run_command(Commands.CREATE, prefix, "console_shortcut",
                        "--shortcuts")
            assert package_is_installed(prefix, 'console_shortcut')
            assert isfile(shortcut_file), ("Shortcut not found in menu dir. "
                                           "Contents of dir:\n"
                                           "{0}".format(
                                               os.listdir(shortcut_dir)))

            # make sure that cleanup without specifying --shortcuts still removes shortcuts
            run_command(Commands.REMOVE, prefix, 'console_shortcut')
            assert not package_is_installed(prefix, 'console_shortcut')
            assert not isfile(shortcut_file)
        finally:
            rmtree(prefix, ignore_errors=True)
            if isfile(shortcut_file):
                os.remove(shortcut_file)
Ejemplo n.º 4
0
    def test_shortcut_absent_does_not_barf_on_uninstall(self):
        from menuinst.win32 import dirs as win_locations

        user_mode = 'user' if exists(join(sys.prefix,
                                          u'.nonadmin')) else 'system'
        shortcut_dir = win_locations[user_mode]["start"]
        shortcut_dir = join(
            shortcut_dir, "Anaconda{0} ({1}-bit)"
            "".format(sys.version_info.major, config.bits))

        prefix = make_temp_prefix(str(uuid4())[:7])
        shortcut_file = join(
            shortcut_dir, "Anaconda Prompt ({0}).lnk".format(basename(prefix)))
        assert not isfile(shortcut_file)

        try:
            # not including --shortcuts, should not get shortcuts installed
            config.load_condarc("")
            run_command(Commands.CREATE, prefix, "console_shortcut")
            assert package_is_installed(prefix, 'console_shortcut')
            assert not isfile(shortcut_file)

            # make sure that cleanup without specifying --shortcuts still removes shortcuts
            run_command(Commands.REMOVE, prefix, 'console_shortcut')
            assert not package_is_installed(prefix, 'console_shortcut')
            assert not isfile(shortcut_file)
        finally:
            rmtree(prefix, ignore_errors=True)
            if isfile(shortcut_file):
                os.remove(shortcut_file)
Ejemplo n.º 5
0
    def test_shortcut_creation_installs_shortcut(self):
        from menuinst.win32 import dirs as win_locations
        user_mode = 'user' if exists(join(sys.prefix, u'.nonadmin')) else 'system'
        shortcut_dir = win_locations[user_mode]["start"]
        shortcut_dir = join(shortcut_dir, "Anaconda{0} ({1}-bit)"
                                          "".format(sys.version_info.major, config.bits))

        prefix = make_temp_prefix(str(uuid4())[:7])
        shortcut_file = join(shortcut_dir, "Anaconda Prompt ({0}).lnk".format(basename(prefix)))
        try:
            config.load_condarc("")
            run_command(Commands.CREATE, prefix, "console_shortcut", "--shortcuts")
            assert package_is_installed(prefix, 'console_shortcut')
            assert isfile(shortcut_file), ("Shortcut not found in menu dir. "
                                           "Contents of dir:\n"
                                           "{0}".format(os.listdir(shortcut_dir)))

            # make sure that cleanup without specifying --shortcuts still removes shortcuts
            run_command(Commands.REMOVE, prefix, 'console_shortcut')
            assert not package_is_installed(prefix, 'console_shortcut')
            assert not isfile(shortcut_file)
        finally:
            rmtree(prefix, ignore_errors=True)
            if isfile(shortcut_file):
                os.remove(shortcut_file)
Ejemplo n.º 6
0
 def test_shortcut_in_underscore_env_shows_message(self):
     prefix = make_temp_prefix("_" + str(uuid4())[:7])
     try:
         config.load_condarc("")
         stdout, stderr = run_command(Commands.CREATE, prefix, "console_shortcut")
         assert ("Environment name starts with underscore '_'.  "
                 "Skipping menu installation." in stderr)
     finally:
         rmtree(prefix, ignore_errors=True)
Ejemplo n.º 7
0
def make_temp_env(*packages):
    prefix = make_temp_prefix()
    try:
        # try to clear any config that's been set by other tests
        config.load_condarc(join(prefix, 'condarc'))
        run_command(Commands.CREATE, prefix, *packages)
        yield prefix
    finally:
        rmtree(prefix, ignore_errors=True)
Ejemplo n.º 8
0
 def test_shortcut_in_underscore_env_shows_message(self):
     prefix = make_temp_prefix("_" + str(uuid4())[:7])
     try:
         config.load_condarc("")
         stdout, stderr = run_command(Commands.CREATE, prefix,
                                      "console_shortcut", "--shortcuts")
         assert ("Environment name starts with underscore '_'.  "
                 "Skipping menu installation." in stderr)
     finally:
         rmtree(prefix, ignore_errors=True)
Ejemplo n.º 9
0
 def test_shortcut_not_attempted_without_shortcuts_arg(self):
     prefix = make_temp_prefix("_" + str(uuid4())[:7])
     try:
         config.load_condarc("")
         stdout, stderr = run_command(Commands.CREATE, prefix, "console_shortcut")
         # This test is sufficient, because it effectively verifies that the code
         #  path was not visited.
         assert ("Environment name starts with underscore '_'.  Skipping menu installation."
                 not in stderr)
     finally:
         rmtree(prefix, ignore_errors=True)
Ejemplo n.º 10
0
def make_temp_env(*packages):
    prefix = make_temp_prefix()
    prefix_condarc = join(prefix, 'condarc')
    try:
        # try to clear any config that's been set by other tests
        if packages:
            config.load_condarc(prefix_condarc)
            run_command(Commands.CREATE, prefix, *packages)
        yield prefix
    finally:
        rmtree(prefix, ignore_errors=True)
Ejemplo n.º 11
0
 def test_shortcut_not_attempted_without_shortcuts_arg(self):
     prefix = make_temp_prefix("_" + str(uuid4())[:7])
     try:
         config.load_condarc("")
         stdout, stderr = run_command(Commands.CREATE, prefix,
                                      "console_shortcut")
         # This test is sufficient, because it effectively verifies that the code
         #  path was not visited.
         assert (
             "Environment name starts with underscore '_'.  Skipping menu installation."
             not in stderr)
     finally:
         rmtree(prefix, ignore_errors=True)
Ejemplo n.º 12
0
 def __init__(self, *args, **kwargs):
     config.rc = config.load_condarc(config.rc_path)
     # Otherwise normalization tests will fail if the user is logged into
     # binstar.
     config.rc['add_binstar_token'] = False
     config.channel_alias = config.rc['channel_alias']
     super(TestConfig, self).__init__(*args, **kwargs)
Ejemplo n.º 13
0
 def __init__(self, *args, **kwargs):
     config.rc = config.load_condarc(config.rc_path)
     # Otherwise normalization tests will fail if the user is logged into
     # binstar.
     config.rc['add_binstar_token'] = False
     config.channel_alias = config.rc['channel_alias']
     super(TestConfig, self).__init__(*args, **kwargs)
Ejemplo n.º 14
0
def make_temp_env(*packages):
    prefix = make_temp_prefix()
    try:
        # try to clear any config that's been set by other tests
        config.rc = config.load_condarc('')

        p = conda_argparse.ArgumentParser()
        sub_parsers = p.add_subparsers(metavar='command', dest='cmd')
        create_configure_parser(sub_parsers)

        command = "create -y -q -p {0} {1}".format(escape_for_winpath(prefix), " ".join(packages))

        args = p.parse_args(split(command))
        args.func(args, p)

        yield prefix
    finally:
        rmtree(prefix, ignore_errors=True)
Ejemplo n.º 15
0
def make_temp_env(*packages):
    prefix = make_temp_prefix()
    try:
        # try to clear any config that's been set by other tests
        config.rc = config.load_condarc('')

        p = conda_argparse.ArgumentParser()
        sub_parsers = p.add_subparsers(metavar='command', dest='cmd')
        create_configure_parser(sub_parsers)

        command = "create -y -q -p {0} {1}".format(escape_for_winpath(prefix), " ".join(packages))

        args = p.parse_args(split(command))
        args.func(args, p)

        yield prefix
    finally:
        rmtree(prefix, ignore_errors=True)
Ejemplo n.º 16
0
def reload_config(prefix):
    prefix_condarc = join(prefix, 'condarc')
    config.load_condarc(prefix_condarc)
Ejemplo n.º 17
0
def reload_config(prefix):
    prefix_condarc = join(prefix, 'condarc')
    config.load_condarc(prefix_condarc)
Ejemplo n.º 18
0
 def __init__(self, *args, **kwargs):
     config.rc = config.load_condarc(config.rc_path)
     super(TestConfig, self).__init__(*args, **kwargs)
Ejemplo n.º 19
0
 def __init__(self, *args, **kwargs):
     config.rc = config.load_condarc(config.rc_path)
     super(TestConfig, self).__init__(*args, **kwargs)
Ejemplo n.º 20
0
 def tearDown(self):
     # Restore original condarc
     config.rc = self.rc
     config.load_condarc()
Ejemplo n.º 21
0
 def setUp(self):
     # Load the test condarc file
     self.rc, config.rc = config.rc, testrc
     config.load_condarc()
     config.binstar_client = BinstarTester()
     config.init_binstar()
Ejemplo n.º 22
0
 def test_proxy_settings(self):
     config.rc = config.load_condarc(config.rc_path)
     servers = config.get_proxy_servers()
     self.assertEqual(len(servers),2)
     self.assertEqual(servers['http'],'http://*****:*****@corp.com:8080')
     self.assertEqual(servers['https'], 'https://*****:*****@corp.com:8080')
Ejemplo n.º 23
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/'
        ]
Ejemplo n.º 24
0
 def test_proxy_settings(self):
     # reload the config file
     config.rc = config.load_condarc(config.rc_path)
     self.assertEqual(config.get_proxy_servers(),
                      {'http': 'http://*****:*****@corp.com:8080',
                       'https': 'https://*****:*****@corp.com:8080'})