示例#1
0
def test_ssl_verify_set_filename():
    with make_temp_condarc() as rc, Utf8NamedTemporaryFile() as tf:
        stdout, stderr, _ = run_command(Commands.CONFIG, '--file', rc, '--set',
                                        'ssl_verify', tf.name)
        assert stdout == stderr == ''
        reset_context([rc])
        assert context.ssl_verify == tf.name
示例#2
0
def test_channel_priority():
    fn1 = 'pandas-0.10.1-np17py27_0.tar.bz2'
    fn2 = 'other::' + fn1
    spec = ['pandas', 'python 2.7*']
    index2 = index.copy()
    index2[fn2] = index2[fn1].copy()
    r2 = Resolve(index2)
    rec = r2.index[fn2]

    os.environ['CONDA_CHANNEL_PRIORITY'] = 'True'
    reset_context(())

    rec['priority'] = 0
    # Should select the "other", older package because it
    # has a lower channel priority number
    installed1 = r2.install(spec)
    # Should select the newer package because now the "other"
    # package has a higher priority number
    rec['priority'] = 2
    installed2 = r2.install(spec)
    # Should also select the newer package because we have
    # turned off channel priority altogether

    os.environ['CONDA_CHANNEL_PRIORITY'] = 'False'
    reset_context(())

    rec['priority'] = 0
    installed3 = r2.install(spec)
    assert installed1 != installed2
    assert installed1 != installed3
    assert installed2 == installed3
示例#3
0
def test_ssl_verify_set_bool():
    with make_temp_condarc() as rc:
        stdout, stderr, _ = run_command(Commands.CONFIG, '--file', rc, '--set',
                                        'ssl_verify', 'no')
        assert stdout == stderr == ''
        reset_context([rc])
        assert context.ssl_verify is False
示例#4
0
def make_temp_env(*packages, **kwargs):
    name = kwargs.pop("name", None)
    use_restricted_unicode = kwargs.pop("use_restricted_unicode", False)

    prefix = kwargs.pop("prefix", None) or _get_temp_prefix(
        name=name, use_restricted_unicode=use_restricted_unicode)
    clean_prefix = kwargs.pop("clean_prefix", None)
    if clean_prefix:
        if os.path.exists(prefix):
            rm_rf(prefix)
    if not isdir(prefix):
        make_temp_prefix(name, use_restricted_unicode, prefix)
    with disable_logger("fetch"), disable_logger("dotupdate"):
        try:
            # try to clear any config that's been set by other tests
            # CAUTION :: This does not partake in the context stack management code
            #            of env_{var,vars,unmodified} and, when used in conjunction
            #            with that code, this *must* be called first.
            reset_context([os.path.join(prefix + os.sep, "condarc")])
            run_command(Commands.CREATE, prefix, *packages, **kwargs)
            yield prefix
        finally:
            if "CONDA_TEST_SAVE_TEMPS" not in os.environ:
                rmtree(prefix, ignore_errors=True)
            else:
                log.warning(
                    "CONDA_TEST_SAVE_TEMPS :: retaining make_temp_env {}".
                    format(prefix))
示例#5
0
 def test_signing_metadata_url_base(self):
     SIGNING_URL_BASE = "https://conda.example.com/pkgs"
     string = f"signing_metadata_url_base: {SIGNING_URL_BASE}"
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string)))
     context._set_raw_data(rd)
     assert context.signing_metadata_url_base == SIGNING_URL_BASE
示例#6
0
    def test_bad_anaconda_token_infinite_loop(self):
        # First, confirm we get a 401 UNAUTHORIZED response from anaconda.org
        response = requests.get("https://conda.anaconda.org/t/cqgccfm1mfma/data-portal/"
                                "%s/repodata.json" % context.subdir)
        assert response.status_code == 401

        try:
            prefix = make_temp_prefix(str(uuid4())[:7])
            channel_url = "https://conda.anaconda.org/t/cqgccfm1mfma/data-portal"
            run_command(Commands.CONFIG, prefix, "--add channels %s" % channel_url)
            stdout, stderr = run_command(Commands.CONFIG, prefix, "--show")
            yml_obj = yaml_load(stdout)
            assert yml_obj['channels'] == [channel_url, 'defaults']

            with pytest.raises(CondaHTTPError):
                run_command(Commands.SEARCH, prefix, "boltons", "--json")

            stdout, stderr = run_command(Commands.SEARCH, prefix, "boltons", "--json",
                                         use_exception_handler=True)
            json_obj = json.loads(stdout)
            assert json_obj['status_code'] == 401

        finally:
            rmtree(prefix, ignore_errors=True)
            reset_context()
示例#7
0
 def _get_expandvars_context(attr, config_expr, env_value):
     with mock.patch.dict(os.environ, {"TEST_VAR": env_value}):
         reset_context(())
         string = f"{attr}: {config_expr}"
         rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string)))
         context._set_raw_data(rd)
         return getattr(context, attr)
示例#8
0
def test_channel_priority():
    fn1 = 'pandas-0.10.1-np17py27_0.tar.bz2'
    fn2 = 'other::' + fn1
    spec = ['pandas', 'python 2.7*']
    index2 = index.copy()
    index2[Dist(fn2)] = index2[Dist(fn1)].copy()
    index2 = {Dist(key): value for key, value in iteritems(index2)}
    r2 = Resolve(index2)
    rec = r2.index[Dist(fn2)]

    os.environ['CONDA_CHANNEL_PRIORITY'] = 'True'
    reset_context(())

    rec['priority'] = 0
    # Should select the "other", older package because it
    # has a lower channel priority number
    installed1 = r2.install(spec)
    # Should select the newer package because now the "other"
    # package has a higher priority number
    rec['priority'] = 2
    installed2 = r2.install(spec)
    # Should also select the newer package because we have
    # turned off channel priority altogether

    os.environ['CONDA_CHANNEL_PRIORITY'] = 'False'
    reset_context(())

    rec['priority'] = 0
    installed3 = r2.install(spec)
    assert installed1 != installed2
    assert installed1 != installed3
    assert installed2 == installed3
示例#9
0
 def setUp(self):
     string = dals("""
     custom_channels:
       darwin: https://some.url.somewhere/stuff
       chuck: http://another.url:8080/with/path
     custom_multichannels:
       michele:
         - https://do.it.with/passion
         - learn_from_every_thing
       steve:
         - more-downloads
     migrated_custom_channels:
       darwin: s3://just/cant
       chuck: file:///var/lib/repo/
     migrated_channel_aliases:
       - https://conda.anaconda.org
     channel_alias: ftp://new.url:8082
     conda-build:
       root-dir: /some/test/path
     proxy_servers:
       http: http://user:[email protected]:8080
       https: none
       ftp:
       sftp: ''
       ftps: false
       rsync: 'false'
     aggressive_update_packages: []
     """)
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
     context._set_raw_data(rd)
示例#10
0
 def setUp(self):
     string = dals("""
     custom_channels:
       darwin: https://some.url.somewhere/stuff
       chuck: http://another.url:8080/with/path
     custom_multichannels:
       michele:
         - https://do.it.with/passion
         - learn_from_every_thing
       steve:
         - more-downloads
     migrated_custom_channels:
       darwin: s3://just/cant
       chuck: file:///var/lib/repo/
     migrated_channel_aliases:
       - https://conda.anaconda.org
     channel_alias: ftp://new.url:8082
     conda-build:
       root-dir: /some/test/path
     proxy_servers:
       http: http://user:[email protected]:8080
       https: none
       ftp:
       sftp: ''
       ftps: false
       rsync: 'false'
     aggressive_update_packages: []
     """)
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters(
         'testdata', yaml_load(string)))
     context._set_raw_data(rd)
示例#11
0
    def setUpClass(cls):
        string = dals("""
        custom_channels:
          darwin: https://some.url.somewhere/stuff
          chuck: http://user1:[email protected]:8080/t/tk-1234/with/path
          pkgs/free: http://192.168.0.15:8080
        migrated_custom_channels:
          darwin: s3://just/cant
          chuck: file:///var/lib/repo/
          pkgs/free: https://repo.continuum.io
        migrated_channel_aliases:
          - https://conda.anaconda.org
        channel_alias: ftp://new.url:8082
        default_channels:
          - http://192.168.0.15:8080/pkgs/free
          - http://192.168.0.15:8080/pkgs/pro
          - http://192.168.0.15:8080/pkgs/msys2
        """)
        reset_context()
        rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
        context._add_raw_data(rd)
        Channel._reset_state()

        cls.platform = context.subdir

        cls.DEFAULT_URLS = ['http://192.168.0.15:8080/pkgs/free/%s' % cls.platform,
                            'http://192.168.0.15:8080/pkgs/free/noarch',
                            'http://192.168.0.15:8080/pkgs/pro/%s' % cls.platform,
                            'http://192.168.0.15:8080/pkgs/pro/noarch',
                            'http://192.168.0.15:8080/pkgs/msys2/%s' % cls.platform,
                            'http://192.168.0.15:8080/pkgs/msys2/noarch',
                            ]
示例#12
0
def test_channel_priority():
    fn1 = 'pandas-0.10.1-np17py27_0.tar.bz2'
    fn2 = 'other::' + fn1
    spec = ['pandas', 'python 2.7*']
    index2 = index.copy()
    index2[Dist(fn2)] = index2[Dist(add_defaults_if_no_channel(fn1))].copy()
    index2 = {Dist(key): value for key, value in iteritems(index2)}
    r2 = Resolve(index2)
    rec = r2.index[Dist(fn2)]

    os.environ['CONDA_CHANNEL_PRIORITY'] = 'True'
    reset_context(())

    r2.index[Dist(fn2)] = IndexRecord.from_objects(r2.index[Dist(fn2)], priority=0)
    # Should select the "other", older package because it
    # has a lower channel priority number
    installed1 = r2.install(spec)
    # Should select the newer package because now the "other"
    # package has a higher priority number
    r2.index[Dist(fn2)] = IndexRecord.from_objects(r2.index[Dist(fn2)], priority=2)
    installed2 = r2.install(spec)
    # Should also select the newer package because we have
    # turned off channel priority altogether

    os.environ['CONDA_CHANNEL_PRIORITY'] = 'False'
    reset_context(())

    r2.index[Dist(fn2)] = IndexRecord.from_objects(r2.index[Dist(fn2)], priority=0)
    installed3 = r2.install(spec)
    assert installed1 != installed2
    assert installed1 != installed3
    assert installed2 == installed3
示例#13
0
    def test_bad_anaconda_token_infinite_loop(self):
        # First, confirm we get a 401 UNAUTHORIZED response from anaconda.org
        response = requests.get("https://conda.anaconda.org/t/cqgccfm1mfma/data-portal/"
                                "%s/repodata.json" % context.subdir)
        assert response.status_code == 401

        try:
            prefix = make_temp_prefix(str(uuid4())[:7])
            channel_url = "https://conda.anaconda.org/t/cqgccfm1mfma/data-portal"
            run_command(Commands.CONFIG, prefix, "--add channels %s" % channel_url)
            stdout, stderr = run_command(Commands.CONFIG, prefix, "--show")
            yml_obj = yaml_load(stdout)
            assert yml_obj['channels'] == [channel_url, 'defaults']

            with pytest.raises(CondaHTTPError):
                run_command(Commands.SEARCH, prefix, "boltons", "--json")

            stdout, stderr = run_command(Commands.SEARCH, prefix, "boltons", "--json",
                                         use_exception_handler=True)
            json_obj = json.loads(stdout)
            assert json_obj['status_code'] == 401

        finally:
            rmtree(prefix, ignore_errors=True)
            reset_context()
示例#14
0
    def setUp(cls):
        string = dals("""
        custom_channels:
          darwin: https://some.url.somewhere/stuff
          chuck: http://user1:[email protected]:8080/t/tk-1234/with/path
          pkgs/anaconda: http://192.168.0.15:8080
        migrated_custom_channels:
          darwin: s3://just/cant
          chuck: file:///var/lib/repo/
          pkgs/anaconda: https://repo.continuum.io
        migrated_channel_aliases:
          - https://conda.anaconda.org
        channel_alias: ftp://new.url:8082
        default_channels:
          - http://192.168.0.15:8080/pkgs/anaconda
          - http://192.168.0.15:8080/pkgs/pro
          - http://192.168.0.15:8080/pkgs/msys2
        """)
        reset_context()
        rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
        context._set_raw_data(rd)
        Channel._reset_state()

        cls.platform = context.subdir

        cls.DEFAULT_URLS = ['http://192.168.0.15:8080/pkgs/anaconda/%s' % cls.platform,
                            'http://192.168.0.15:8080/pkgs/anaconda/noarch',
                            'http://192.168.0.15:8080/pkgs/pro/%s' % cls.platform,
                            'http://192.168.0.15:8080/pkgs/pro/noarch',
                            'http://192.168.0.15:8080/pkgs/msys2/%s' % cls.platform,
                            'http://192.168.0.15:8080/pkgs/msys2/noarch',
                            ]
示例#15
0
 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')
示例#16
0
 def test_anaconda_token(self):
     try:
         assert context.anaconda_token == 'tk-123-456-cba'
         os.environ['CONDA_ANACONDA_TOKEN'] = 'tk-123-789-def'
         reset_context()
         assert context.anaconda_token == 'tk-123-789-def'
     finally:
         os.environ.pop('CONDA_ANACONDA_TOKEN', None)
示例#17
0
 def test_anaconda_token(self):
     try:
         assert context.anaconda_token == 'tk-123-456-cba'
         os.environ['CONDA_ANACONDA_TOKEN'] = 'tk-123-789-def'
         reset_context()
         assert context.anaconda_token == 'tk-123-789-def'
     finally:
         os.environ.pop('CONDA_ANACONDA_TOKEN', None)
示例#18
0
 def test_client_ssl_cert(self):
     string = dals("""
     client_ssl_cert_key: /some/key/path
     """)
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
     context._set_raw_data(rd)
     pytest.raises(ValidationError, context.validate_configuration)
示例#19
0
 def test_client_ssl_cert(self):
     string = dals("""
     client_ssl_cert_key: /some/key/path
     """)
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
     context._add_raw_data(rd)
     pytest.raises(ValidationError, context.validate_configuration)
示例#20
0
    def test_prefix_cli_flag(self):
        envs_dirs = (join(self.prefix, 'first-envs-dir'), join(self.prefix, 'seconds-envs-dir'))
        with env_var('CONDA_ENVS_DIRS', os.pathsep.join(envs_dirs), conda_tests_ctxt_mgmt_def_pol):

            # even if prefix doesn't exist, it can be a target prefix
            reset_context((), argparse_args=AttrDict(prefix='./blarg', func='create'))
            target_prefix = join(os.getcwd(), 'blarg')
            assert context.target_prefix == target_prefix
            assert not isdir(target_prefix)
示例#21
0
 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')
示例#22
0
 def test_signing_metadata_url_base_empty_default_channels(self):
     string = dals("""
     default_channels: []
     """)
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string)))
     context._set_raw_data(rd)
     assert len(context.default_channels) is 0
     assert context.signing_metadata_url_base is None
示例#23
0
 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')
示例#24
0
 def setUpClass(cls):
     reset_context()
     cls.platform = context.subdir
     cls.DEFAULT_URLS = ['https://repo.continuum.io/pkgs/free/%s' % cls.platform,
                         'https://repo.continuum.io/pkgs/free/noarch',
                         'https://repo.continuum.io/pkgs/pro/%s' % cls.platform,
                         'https://repo.continuum.io/pkgs/pro/noarch']
     if on_win:
         cls.DEFAULT_URLS.extend(['https://repo.continuum.io/pkgs/msys2/%s' % cls.platform,
                                  'https://repo.continuum.io/pkgs/msys2/noarch'])
示例#25
0
def run_inprocess_conda_command(command):
    reset_context(())
    with argv(split(command)), captured() as c:
        initialize_logging()
        try:
            exit_code = cli.main()
        except SystemExit:
            pass
    print(c.stderr, file=sys.stderr)
    print(c.stdout)
    return c.stdout, c.stderr, exit_code
示例#26
0
文件: test_create.py 项目: ESSS/conda
def make_temp_env(*packages, **kwargs):
    prefix = kwargs.pop('prefix', None) or make_temp_prefix()
    assert isdir(prefix), prefix
    with disable_logger('fetch'), disable_logger('dotupdate'):
        try:
            # try to clear any config that's been set by other tests
            reset_context([os.path.join(prefix+os.sep, 'condarc')])
            run_command(Commands.CREATE, prefix, *packages)
            yield prefix
        finally:
            rmtree(prefix, ignore_errors=True)
示例#27
0
def make_temp_env(*packages, **kwargs):
    prefix = kwargs.pop('prefix', None) or make_temp_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')])
                run_command(Commands.CREATE, prefix, *packages)
                yield prefix
            finally:
                rmtree(prefix, ignore_errors=True)
示例#28
0
文件: helpers.py 项目: jaimergp/conda
def run_inprocess_conda_command(command):
    reset_context(())
    with argv(split(command)), captured() as c:
        initialize_logging()
        try:
            exit_code = cli.main()
        except SystemExit:
            pass
    print(c.stderr, file=sys.stderr)
    print(c.stdout)
    return c.stdout, c.stderr, exit_code
示例#29
0
def make_temp_env(*packages, **kwargs):
    prefix = kwargs.pop('prefix', None) or make_temp_prefix()
    assert isdir(prefix), prefix
    with disable_logger('fetch'), disable_logger('dotupdate'):
        try:
            # try to clear any config that's been set by other tests
            reset_context([os.path.join(prefix+os.sep, 'condarc')])
            run_command(Commands.CREATE, prefix, *packages)
            yield prefix
        finally:
            rmtree(prefix, ignore_errors=True)
示例#30
0
    def test_prefix_cli_flag(self):
        envs_dirs = (join(self.prefix, 'first-envs-dir'),
                     join(self.prefix, 'seconds-envs-dir'))
        with env_var('CONDA_ENVS_DIRS', os.pathsep.join(envs_dirs),
                     reset_context):

            # even if prefix doesn't exist, it can be a target prefix
            reset_context((), argparse_args=AttrDict(prefix='./blarg'))
            target_prefix = join(os.getcwd(), 'blarg')
            assert context.target_prefix == target_prefix
            assert not isdir(target_prefix)
示例#31
0
 def setUpClass(cls):
     reset_context(())
     cls.platform = context.subdir
     cls.DEFAULT_URLS = ['https://repo.anaconda.com/pkgs/main/%s' % cls.platform,
                         'https://repo.anaconda.com/pkgs/main/noarch',
                         'https://repo.anaconda.com/pkgs/r/%s' % cls.platform,
                         'https://repo.anaconda.com/pkgs/r/noarch',
                         ]
     if on_win:
         cls.DEFAULT_URLS.extend(['https://repo.anaconda.com/pkgs/msys2/%s' % cls.platform,
                                  'https://repo.anaconda.com/pkgs/msys2/noarch'])
示例#32
0
def make_temp_condarc(value=None):
    try:
        tempfile = NamedTemporaryFile(suffix='.yml', delete=False)
        tempfile.close()
        temp_path = tempfile.name
        if value:
            with open(temp_path, 'w') as f:
                f.write(value)
        reset_context([temp_path])
        yield temp_path
    finally:
        rm_rf(temp_path)
示例#33
0
文件: helpers.py 项目: zhubonan/conda
def run_inprocess_conda_command(command, disallow_stderr=True):
    # anything that uses this function is an integration test
    reset_context(())
    with argv(split(command)), captured(disallow_stderr) as c:
        initialize_logging()
        try:
            exit_code = cli.main()
        except SystemExit:
            pass
    print(c.stderr, file=sys.stderr)
    print(c.stdout)
    return c.stdout, c.stderr, exit_code
示例#34
0
 def setUpClass(cls):
     reset_context()
     cls.platform = context.subdir
     cls.DEFAULT_URLS = ['https://repo.continuum.io/pkgs/free/%s' % cls.platform,
                         'https://repo.continuum.io/pkgs/free/noarch',
                         'https://repo.continuum.io/pkgs/r/%s' % cls.platform,
                         'https://repo.continuum.io/pkgs/r/noarch',
                         'https://repo.continuum.io/pkgs/pro/%s' % cls.platform,
                         'https://repo.continuum.io/pkgs/pro/noarch']
     if on_win:
         cls.DEFAULT_URLS.extend(['https://repo.continuum.io/pkgs/msys2/%s' % cls.platform,
                                  'https://repo.continuum.io/pkgs/msys2/noarch'])
示例#35
0
def make_temp_condarc(value=None):
    try:
        tempfile = NamedTemporaryFile(suffix='.yml', delete=False)
        tempfile.close()
        temp_path = tempfile.name
        if value:
            with open(temp_path, 'w') as f:
                f.write(value)
        reset_context([temp_path])
        yield temp_path
    finally:
        rm_rf(temp_path)
示例#36
0
def run_inprocess_conda_command(command, disallow_stderr=True):
    # anything that uses this function is an integration test
    reset_context(())
    # May want to do this to command:
    with argv(encode_arguments(shlex_split_unicode(command))), captured(disallow_stderr) as c:
        initialize_logging()
        try:
            exit_code = cli.main(*sys.argv)
        except SystemExit:
            pass
    print(c.stderr, file=sys.stderr)
    print(c.stdout)
    return c.stdout, c.stderr, exit_code
示例#37
0
def run_inprocess_conda_command(command, disallow_stderr=True):
    # anything that uses this function is an integration test
    reset_context(())
    # May want to do this to command:
    with argv(encode_arguments(shlex_split_unicode(command))), captured(disallow_stderr) as c:
        initialize_logging()
        try:
            exit_code = cli.main(*sys.argv)
        except SystemExit:
            pass
    print(c.stderr, file=sys.stderr)
    print(c.stdout)
    return c.stdout, c.stderr, exit_code
示例#38
0
    def setUpClass(cls):
        string = dals("""
        default_channels:
           - http://test/conda/anaconda
        channels:
           - http://test/conda/anaconda-cluster
        """)
        reset_context()
        rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
        context._set_raw_data(rd)
        Channel._reset_state()

        cls.platform = context.subdir
示例#39
0
    def setUpClass(cls):
        string = dals("""
        channel_alias: https://10.2.3.4:8080/conda/t/tk-123-45
        migrated_channel_aliases:
          - https://conda.anaconda.org
          - http://10.2.3.4:7070/conda
        """)
        reset_context()
        rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
        context._add_raw_data(rd)
        Channel._reset_state()

        cls.platform = context.subdir
示例#40
0
    def setUpClass(cls):
        string = dals("""
        channel_alias: https://10.2.3.4:8080/conda/t/tk-123-45
        migrated_channel_aliases:
          - https://conda.anaconda.org
          - http://10.2.3.4:7070/conda
        """)
        reset_context()
        rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
        context._set_raw_data(rd)
        Channel._reset_state()

        cls.platform = context.subdir
示例#41
0
 def setUpClass(cls):
     reset_context(())
     cls.platform = context.subdir
     cls.DEFAULT_URLS = ['https://repo.anaconda.com/pkgs/main/%s' % cls.platform,
                         'https://repo.anaconda.com/pkgs/main/noarch',
                         'https://repo.anaconda.com/pkgs/free/%s' % cls.platform,
                         'https://repo.anaconda.com/pkgs/free/noarch',
                         'https://repo.anaconda.com/pkgs/r/%s' % cls.platform,
                         'https://repo.anaconda.com/pkgs/r/noarch',
                         ]
     if on_win:
         cls.DEFAULT_URLS.extend(['https://repo.anaconda.com/pkgs/msys2/%s' % cls.platform,
                                  'https://repo.anaconda.com/pkgs/msys2/noarch'])
示例#42
0
 def test_specify_same_channels_cli_as_in_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 the same as in condarc
     # 'defaults' should not be added
     # See https://github.com/conda/conda/issues/10732
     reset_context((), argparse_args=AttrDict(channel=['conda-forge']))
     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', )
示例#43
0
    def setUpClass(cls):
        string = dals("""
        default_channels:
           - http://test/conda/anaconda
        channels:
           - http://test/conda/anaconda-cluster
        """)
        reset_context()
        rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
        context._set_raw_data(rd)
        Channel._reset_state()

        cls.platform = context.subdir
示例#44
0
 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')
示例#45
0
文件: helpers.py 项目: jaimergp/conda
def run_conda_command(*args):
    # used in tests_config (31 times) and test_info (6 times)
    env = os.environ.copy()
    p = subprocess.Popen((sys.executable, "-m", "conda") + args, stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE, env=env)

    stdout, stderr = [stream.strip().decode('utf-8').replace('\r\n', '\n').replace('\\\\', '\\')
                      for stream in p.communicate()]
    print(stdout)
    print(stderr, file=sys.stderr)
    # assert p.returncode == 0, p.returncode
    if args[0] == 'config':
        reset_context([args[2]])
    return stdout, strip_expected(stderr)
示例#46
0
 def setUpClass(cls):
     channels_config = dals("""
     channels:
       - http://user22:[email protected]:8080
       
     whitelist_channels:
       - http://user22:[email protected]:8080
     
     custom_channels:
       unexpanded: http://user1:[email protected]:8080/with/path/t/tk-1234
       expanded: http://user33:[email protected]:8080/with/path/t/tk-1234
     """)
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(channels_config)))
     context._set_raw_data(rd)
示例#47
0
 def setUp(self):
     string = dals("""
     custom_channels:
       darwin: https://some.url.somewhere/stuff
       chuck: http://another.url:8080/with/path
     migrated_custom_channels:
       darwin: s3://just/cant
       chuck: file:///var/lib/repo/
     migrated_channel_aliases:
       - https://conda.anaconda.org
     channel_alias: ftp://new.url:8082
     """)
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
     context._add_raw_data(rd)
示例#48
0
 def test_add_anaconda_token(self):
     try:
         token = "tk-abc-def-123"
         os.environ['CONDA_ANACONDA_TOKEN'] = token
         reset_context()
         assert context.anaconda_token == token
         url = "https://conda.anaconda.org/binstar/osx-64/repodata.json.bz2"
         url_with_token = "https://conda.anaconda.org/t/%s/binstar/osx-64/repodata.json.bz2" % token
         request = Request(url)
         ba = BinstarAuth()
         rback = ba(request)
         assert request.url == rback.url == url_with_token
     finally:
         os.environ.pop('CONDA_ANACONDA_TOKEN', None)
         reset_context()
示例#49
0
 def setUp(self):
     string = dals("""
     custom_channels:
       darwin: https://some.url.somewhere/stuff
       chuck: http://another.url:8080/with/path
     migrated_custom_channels:
       darwin: s3://just/cant
       chuck: file:///var/lib/repo/
     migrated_channel_aliases:
       - https://conda.anaconda.org
     channel_alias: ftp://new.url:8082
     """)
     reset_context()
     rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
     context._add_raw_data(rd)
示例#50
0
 def test_add_anaconda_token(self):
     try:
         token = "tk-abc-def-123"
         os.environ['CONDA_ANACONDA_TOKEN'] = token
         reset_context()
         assert context.anaconda_token == token
         url = "https://conda.anaconda.org/binstar/osx-64/repodata.json.bz2"
         url_with_token = "https://conda.anaconda.org/t/%s/binstar/osx-64/repodata.json.bz2" % token
         request = Request(url)
         ba = BinstarAuth()
         rback = ba(request)
         assert request.url == rback.url == url_with_token
     finally:
         os.environ.pop('CONDA_ANACONDA_TOKEN', None)
         reset_context()
示例#51
0
    def test_conda_bld_path_1(self):
        saved_envs_path = os.environ.get('CONDA_BLD_PATH')
        beginning = "C:" + os.sep if on_win else os.sep
        path = beginning + os.sep.join(['tmp', 'conda-bld'])
        url = path_to_url(path)
        try:
            os.environ['CONDA_BLD_PATH'] = path
            reset_context()

            channel = Channel('local')
            assert channel.channel_name == "local"
            assert channel.channel_location is None
            assert channel.platform is None
            assert channel.package_filename is None
            assert channel.auth is None
            assert channel.token is None
            assert channel.scheme is None
            assert channel.canonical_name == "local"
            assert channel.url() is None
            assert channel.urls() == [
                join_url(url, context.subdir),
                join_url(url, 'noarch'),
            ]

            channel = Channel(url)
            assert channel.canonical_name == "local"
            assert channel.platform is None
            assert channel.package_filename is None
            assert channel.auth is None
            assert channel.token is None
            assert channel.scheme == "file"
            assert channel.urls() == [
                join_url(url, context.subdir),
                join_url(url, 'noarch'),
            ]
            assert channel.url() == join_url(url, context.subdir)
            assert channel.channel_name == basename(path)
            assert channel.channel_location == path_to_url(dirname(path)).replace('file://', '', 1)
            assert channel.canonical_name == "local"

        finally:
            if saved_envs_path:
                os.environ['CONDA_BLD_PATH'] = saved_envs_path
            else:
                del os.environ['CONDA_BLD_PATH']
示例#52
0
文件: helpers.py 项目: Korijn/conda
def run_conda_command(*args):
    # used in tests_config (31 times) and test_info (6 times)
    env = {str(k): str(v) for k, v in iteritems(os.environ)}
    p = subprocess.Popen((sys.executable, "-m", "conda") + args, stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE, env=env)

    stdout, stderr = [stream.strip()
                          .decode('utf-8')
                          .replace('\r\n', '\n')
                          .replace('\\\\', '\\')
                          .replace("Using Anaconda API: https://api.anaconda.org\n", "")
                      for stream in p.communicate()]
    print(stdout)
    print(stderr, file=sys.stderr)
    # assert p.returncode == 0, p.returncode
    if args[0] == 'config':
        reset_context([args[2]])
    return stdout, strip_expected(stderr)
示例#53
0
    def test_conda_envs_path(self):
        saved_envs_path = os.environ.get('CONDA_ENVS_PATH')
        beginning = "C:" + os.sep if on_win else os.sep
        path1 = beginning + os.sep.join(['my', 'envs', 'dir', '1'])
        path2 = beginning + os.sep.join(['my', 'envs', 'dir', '2'])
        try:
            os.environ['CONDA_ENVS_PATH'] = path1
            reset_context()
            assert context.envs_dirs[0] == path1

            os.environ['CONDA_ENVS_PATH'] = os.pathsep.join([path1, path2])
            reset_context()
            assert context.envs_dirs[0] == path1
            assert context.envs_dirs[1] == path2
        finally:
            if saved_envs_path:
                os.environ['CONDA_ENVS_PATH'] = saved_envs_path
            else:
                del os.environ['CONDA_ENVS_PATH']
示例#54
0
def test_set_rc_string():
    # Test setting string keys in .condarc

    # We specifically test ssl_verify since it can be either a boolean or a string
    with make_temp_condarc() as rc:
        assert context.ssl_verify is True
        stdout, stderr = run_conda_command("config", "--file", rc, "--set", "ssl_verify", "no")
        assert stdout == ""
        assert stderr == ""

        reset_context([rc])
        assert context.ssl_verify is False

        stdout, stderr = run_conda_command("config", "--file", rc, "--set", "ssl_verify", "test_string.crt")
        assert stdout == ""
        assert stderr == ""

        reset_context([rc])
        assert context.ssl_verify == "test_string.crt"
示例#55
0
def test_set_rc_string():
    # Test setting string keys in .condarc

    # We specifically test ssl_verify since it can be either a boolean or a string
    with make_temp_condarc() as rc:
        assert context.ssl_verify is True
        stdout, stderr = run_conda_command('config', '--file', rc,
                                           '--set', 'ssl_verify', 'no')
        assert stdout == ''
        assert stderr == ''

        reset_context([rc])
        assert context.ssl_verify is False

        stdout, stderr = run_conda_command('config', '--file', rc,
                                           '--set', 'ssl_verify', 'test_string.crt')
        assert stdout == ''
        assert stderr == ''

        reset_context([rc])
        assert context.ssl_verify == 'test_string.crt'
示例#56
0
    def setUpClass(cls):
        string = dals("""
        custom_channels:
          chuck: http://user1:[email protected]:8080/with/path/t/tk-1234
          chuck/subchan: http://user33:[email protected]:8080/with/path/t/tk-1234
        channel_alias: ftp://nm:[email protected]:8082/t/zyx-wvut/
        channels:
          - mickey
          - https://conda.anaconda.cloud/t/tk-12-token/minnie
          - http://dont-do:[email protected]/daffy/label/main
        default_channels:
          - http://192.168.0.15:8080/pkgs/free
          - donald/label/main
          - http://us:[email protected]:8080/t/tkn-123/pkgs/r
        """)
        reset_context()
        rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string)))
        context._add_raw_data(rd)
        Channel._reset_state()

        cls.platform = context.subdir
示例#57
0
    def test_target_prefix(self):
        with tempdir() as prefix:
            mkdir_p(join(prefix, 'first', 'envs'))
            mkdir_p(join(prefix, 'second', 'envs'))
            create_package_cache_directory(join(prefix, 'first', 'pkgs'))
            create_package_cache_directory(join(prefix, 'second', 'pkgs'))
            envs_dirs = (join(prefix, 'first', 'envs'), join(prefix, 'second', 'envs'))
            with env_var('CONDA_ENVS_DIRS', os.pathsep.join(envs_dirs), reset_context):

                # with both dirs writable, choose first
                reset_context((), argparse_args=AttrDict(name='blarg', func='create'))
                assert context.target_prefix == join(envs_dirs[0], 'blarg')

                # with first dir read-only, choose second
                PackageCacheData._cache_.clear()
                make_read_only(join(envs_dirs[0], '.conda_envs_dir_test'))
                reset_context((), argparse_args=AttrDict(name='blarg', func='create'))
                assert context.target_prefix == join(envs_dirs[1], 'blarg')

                # if first dir is read-only but environment exists, choose first
                PackageCacheData._cache_.clear()
                mkdir_p(join(envs_dirs[0], 'blarg'))
                touch(join(envs_dirs[0], 'blarg', 'history'))
                reset_context((), argparse_args=AttrDict(name='blarg', func='create'))
                assert context.target_prefix == join(envs_dirs[0], 'blarg')
示例#58
0
def capture_with_argv(*argv):
    # only used in capture_json_with_argv()
    sys.argv = argv
    stdout, stderr = StringIO(), StringIO()
    oldstdout, oldstderr = sys.stdout, sys.stderr
    sys.stdout = stdout
    sys.stderr = stderr
    reset_context(())
    try:
        cli.main()
    except SystemExit:
        pass
    sys.stdout = oldstdout
    sys.stderr = oldstderr

    stdout.seek(0)
    stderr.seek(0)
    stdout, stderr = stdout.read(), stderr.read()

    print(stdout)
    print(stderr, file=sys.stderr)
    return stdout, strip_expected(stderr)
示例#59
0
def test_set_rc_string():
    # Test setting string keys in .condarc

    # We specifically test ssl_verify since it can be either a boolean or a string
    with make_temp_condarc() as rc:
        assert context.ssl_verify is True
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'ssl_verify', 'no')
        assert stdout == ''
        assert stderr == ''

        reset_context([rc])
        assert context.ssl_verify is False

        with NamedTemporaryFile() as tf:
            stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                      '--set', 'ssl_verify', tf.name)
            assert stdout == ''
            assert stderr == ''

            reset_context([rc])
            assert context.ssl_verify == tf.name