def test_config_command_remove_force(): # Finally, test --remove, --remove-key with make_temp_condarc() as rc: run_conda_command("config", "--file", rc, "--add", "channels", "test") run_conda_command("config", "--file", rc, "--set", "always_yes", "true") stdout, stderr = run_conda_command("config", "--file", rc, "--remove", "channels", "test") assert stdout == stderr == "" assert yaml_load(_read_test_condarc(rc)) == {"channels": ["defaults"], "always_yes": True} stdout, stderr = run_conda_command("config", "--file", rc, "--remove", "channels", "test", "--force") assert stdout == "" assert ( "CondaKeyError: Error with key 'channels': 'test' is not in the 'channels' " "key of the config file" in stderr ) stdout, stderr = run_conda_command("config", "--file", rc, "--remove", "disallow", "python", "--force") assert stdout == "" assert "CondaKeyError: Error with key 'disallow': key 'disallow' " "is not in the config file" in stderr stdout, stderr = run_conda_command("config", "--file", rc, "--remove-key", "always_yes", "--force") assert stdout == stderr == "" assert yaml_load(_read_test_condarc(rc)) == {"channels": ["defaults"]} stdout, stderr = run_conda_command("config", "--file", rc, "--remove-key", "always_yes", "--force") assert stdout == "" assert "CondaKeyError: Error with key 'always_yes': key 'always_yes' " "is not in the config file" in stderr
def test_config_command_remove_force(): # Finally, test --remove, --remove-key with make_temp_condarc() as rc: run_conda_command('config', '--file', rc, '--add', 'channels', 'test') run_conda_command('config', '--file', rc, '--set', 'always_yes', 'true') stdout, stderr = run_conda_command('config', '--file', rc, '--remove', 'channels', 'test') assert stdout == stderr == '' assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults'], 'always_yes': True} stdout, stderr = run_conda_command('config', '--file', rc, '--remove', 'channels', 'test', '--force') assert stdout == '' assert stderr == "Key error: 'test' is not in the 'channels' key of the config file" stdout, stderr = run_conda_command('config', '--file', rc, '--remove', 'disallow', 'python', '--force') assert stdout == '' assert stderr == "Key error: key 'disallow' is not in the config file" stdout, stderr = run_conda_command('config', '--file', rc, '--remove-key', 'always_yes', '--force') assert stdout == stderr == '' assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults']} stdout, stderr = run_conda_command('config', '--file', rc, '--remove-key', 'always_yes', '--force') assert stdout == '' assert stderr == "Key error: key 'always_yes' is not in the config file"
def test_config_command_remove_force(): # Finally, test --remove, --remove-key with make_temp_condarc() as rc: run_command(Commands.CONFIG, '--file', rc, '--add', 'channels', 'test') run_command(Commands.CONFIG, '--file', rc, '--set', 'always_yes', 'true') stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove', 'channels', 'test') assert stdout == stderr == '' assert yaml_load(_read_test_condarc(rc)) == { 'channels': ['defaults'], 'always_yes': True } stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove', 'channels', 'test', '--force', use_exception_handler=True) assert stdout == '' assert "CondaKeyError: Error with key 'channels': 'test' is not in the 'channels' " \ "key of the config file" in stderr stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove', 'disallow', 'python', '--force', use_exception_handler=True) assert stdout == '' assert "CondaKeyError: Error with key 'disallow': key 'disallow' " \ "is not in the config file" in stderr stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove-key', 'always_yes', '--force') assert stdout == stderr == '' assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults']} stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove-key', 'always_yes', '--force', use_exception_handler=True) assert stdout == '' assert "CondaKeyError: Error with key 'always_yes': key 'always_yes' " \ "is not in the config file" in stderr
def collect_rc(): rc = {} if isfile(user_rc_path): with open(user_rc_path) as fh: rc.update(yaml_load(fh.read())) if isfile(sys_rc_path): with open(sys_rc_path) as fh: rc.update(yaml_load(fh.read())) return rc
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()
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', ]
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' """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters( 'testdata', yaml_load(string))) context._set_raw_data(rd)
def test_create_default_packages_no_default_packages(self): try: prefix = make_temp_prefix(str(uuid4())[:7]) # set packages run_command(Commands.CONFIG, prefix, "--add create_default_packages python") run_command(Commands.CONFIG, prefix, "--add create_default_packages pip") run_command(Commands.CONFIG, prefix, "--add create_default_packages flask") stdout, stderr = run_command(Commands.CONFIG, prefix, "--show") yml_obj = yaml_load(stdout) assert yml_obj['create_default_packages'] == [ 'flask', 'pip', 'python' ] assert not package_is_installed(prefix, 'python-2') assert not package_is_installed(prefix, 'pytz') assert not package_is_installed(prefix, 'flask') with make_temp_env("python=2", "pytz", "--no-default-packages", prefix=prefix): assert_package_is_installed(prefix, 'python-2') assert_package_is_installed(prefix, 'pytz') assert not package_is_installed(prefix, 'flask') finally: rmtree(prefix, ignore_errors=True)
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', ]
def test_config_command_show(): # test alphabetical yaml output with make_temp_condarc() as rc: stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--show') output_keys = yaml_load(stdout).keys() assert stderr == '' assert sorted(output_keys) == [item for item in output_keys]
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)
def test_map_parameter_must_be_map(self): # regression test for conda/conda#3467 string = dals(""" proxy_servers: bad values """) data = odict(s1=YamlRawParameter.make_raw_parameters('s1', yaml_load(string))) config = SampleConfiguration()._set_raw_data(data) raises(InvalidTypeError, config.validate_all)
def test_anaconda_token_with_private_package(self): # TODO: should also write a test to use binstar_client to set the token, # then let conda load the token # Step 0. xfail if a token is set, for example when testing locally tokens = read_binstar_tokens() if tokens: pytest.xfail("binstar token found in global configuration") # Step 1. Make sure without the token we don't see the anyjson package try: prefix = make_temp_prefix(str(uuid4())[:7]) channel_url = "https://conda.anaconda.org/kalefranz" run_command(Commands.CONFIG, prefix, "--add channels %s" % channel_url) run_command(Commands.CONFIG, prefix, "--remove channels defaults") stdout, stderr = run_command(Commands.CONFIG, prefix, "--show") yml_obj = yaml_load(stdout) assert yml_obj['channels'] == [channel_url] stdout, stderr = run_command(Commands.SEARCH, prefix, "anyjson", "--platform", "linux-64", "--json") json_obj = json_loads(stdout) assert len(json_obj) == 0 finally: rmtree(prefix, ignore_errors=True) # Step 2. Now with the token make sure we can see the anyjson package try: prefix = make_temp_prefix(str(uuid4())[:7]) channel_url = "https://conda.anaconda.org/t/zlZvSlMGN7CB/kalefranz" run_command(Commands.CONFIG, prefix, "--add channels %s" % channel_url) run_command(Commands.CONFIG, prefix, "--remove channels defaults") stdout, stderr = run_command(Commands.CONFIG, prefix, "--show") yml_obj = yaml_load(stdout) assert yml_obj['channels'] == [channel_url] stdout, stderr = run_command(Commands.SEARCH, prefix, "anyjson", "--platform", "linux-64", "--json") json_obj = json_loads(stdout) assert 'anyjson' in json_obj finally: rmtree(prefix, ignore_errors=True)
def test_config_command_show(): # test alphabetical yaml output with make_temp_condarc() as rc: stdout, stderr = run_conda_command("config", "--file", rc, "--show") output_keys = yaml_load(stdout).keys() assert stderr == "" assert sorted(output_keys) == [item for item in output_keys]
def test_config_command_show(): # test alphabetical yaml output with make_temp_condarc() as rc: stdout, stderr = run_conda_command('config', '--file', rc, '--show') output_keys = yaml_load(stdout).keys() assert stderr == '' assert sorted(output_keys) == [item for item in output_keys]
def test_map_parameter_must_be_map(self): # regression test for conda/conda#3467 string = dals(""" proxy_servers: bad values """) data = odict( s1=YamlRawParameter.make_raw_parameters('s1', yaml_load(string))) config = SampleConfiguration()._set_raw_data(data) raises(InvalidTypeError, config.validate_all)
def test_config_set(): # Test the config set command # Make sure it accepts only boolean values for boolean keys and any value for string keys with make_temp_condarc() as rc: stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--set', 'always_yes', 'yes') assert stdout == '' assert stderr == '' with open(rc) as fh: content = yaml_load(fh.read()) assert content['always_yes'] is True stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--set', 'always_yes', 'no') assert stdout == '' assert stderr == '' with open(rc) as fh: content = yaml_load(fh.read()) assert content['always_yes'] is False stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--set', 'proxy_servers.http', '1.2.3.4:5678') assert stdout == '' assert stderr == '' with open(rc) as fh: content = yaml_load(fh.read()) assert content['always_yes'] is False assert content['proxy_servers'] == {'http': '1.2.3.4:5678'} stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--set', 'ssl_verify', 'false') assert stdout == '' assert stderr == '' stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--get', 'ssl_verify') assert stdout.strip() == '--set ssl_verify False' assert stderr == ''
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
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
def test_config_command_remove_force(): # Finally, test --remove, --remove-key with make_temp_condarc() as rc: run_conda_command('config', '--file', rc, '--add', 'channels', 'test') run_conda_command('config', '--file', rc, '--set', 'always_yes', 'true') stdout, stderr = run_conda_command('config', '--file', rc, '--remove', 'channels', 'test') assert stdout == stderr == '' assert yaml_load(_read_test_condarc(rc)) == { 'channels': ['defaults'], 'always_yes': True } stdout, stderr = run_conda_command('config', '--file', rc, '--remove', 'channels', 'test', '--force') assert stdout == '' assert stderr == """\ CondaKeyError: Error with key 'channels': 'test' is not in the 'channels' key of the config file""" stdout, stderr = run_conda_command('config', '--file', rc, '--remove', 'disallow', 'python', '--force') assert stdout == '' assert stderr == """\ CondaKeyError: Error with key 'disallow': key 'disallow' is not in the config file""" stdout, stderr = run_conda_command('config', '--file', rc, '--remove-key', 'always_yes', '--force') assert stdout == stderr == '' assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults']} stdout, stderr = run_conda_command('config', '--file', rc, '--remove-key', 'always_yes', '--force') assert stdout == '' assert stderr == """\
def test_yaml_complex(): test_string = dals(""" single_bool: false single_str: no # comment here a_seq_1: - 1 - 2 - 3 a_seq_2: - 1 # with comment - two: 2 - 3 a_map: # comment field1: true field2: yes # final comment """) python_structure = { 'single_bool': False, 'single_str': 'no', 'a_seq_1': [ 1, 2, 3, ], 'a_seq_2': [ 1, {'two': 2}, 3, ], 'a_map': { 'field1': True, 'field2': 'yes', }, } loaded_from_string = yaml_load(test_string) assert python_structure == loaded_from_string dumped_from_load = yaml_dump(loaded_from_string) print(dumped_from_load) assert dumped_from_load == test_string
def test_config_command_remove_force(): # Finally, test --remove, --remove-key with make_temp_condarc() as rc: run_command(Commands.CONFIG, '--file', rc, '--add', 'channels', 'test') run_command(Commands.CONFIG, '--file', rc, '--set', 'always_yes', 'true') stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove', 'channels', 'test') assert stdout == stderr == '' assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults'], 'always_yes': True} stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove', 'channels', 'test', '--force', use_exception_handler=True) assert stdout == '' assert "CondaKeyError: Error with key 'channels': 'test' is not in the 'channels' " \ "key of the config file" in stderr stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove', 'disallow', 'python', '--force', use_exception_handler=True) assert stdout == '' assert "CondaKeyError: Error with key 'disallow': key 'disallow' " \ "is not in the config file" in stderr stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove-key', 'always_yes', '--force') assert stdout == stderr == '' assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults']} stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove-key', 'always_yes', '--force', use_exception_handler=True) assert stdout == '' assert "CondaKeyError: Error with key 'always_yes': key 'always_yes' " \ "is not in the config file" in stderr
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)
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._set_raw_data(rd) Channel._reset_state() cls.platform = context.subdir
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
def test_create_default_packages_no_default_packages(self): try: prefix = make_temp_prefix(str(uuid4())[:7]) # set packages run_command(Commands.CONFIG, prefix, "--add create_default_packages python") run_command(Commands.CONFIG, prefix, "--add create_default_packages pip") run_command(Commands.CONFIG, prefix, "--add create_default_packages flask") stdout, stderr = run_command(Commands.CONFIG, prefix, "--show") yml_obj = yaml_load(stdout) assert yml_obj['create_default_packages'] == ['flask', 'pip', 'python'] assert not package_is_installed(prefix, 'python-2') assert not package_is_installed(prefix, 'numpy') assert not package_is_installed(prefix, 'flask') with make_temp_env("python=2", "numpy", "--no-default-packages", prefix=prefix): assert_package_is_installed(prefix, 'python-2') assert_package_is_installed(prefix, 'numpy') assert not package_is_installed(prefix, 'flask') finally: rmtree(prefix, ignore_errors=True)
def test_config_command_parser(): # Now test the YAML "parser" # Channels is normal content. # create_default_packages has extra spaces in list items condarc = """\ channels: - test - defaults create_default_packages : - ipython - numpy changeps1: false # Here is a comment always_yes: true """ # First verify that this itself is valid YAML assert yaml_load(condarc) == { 'channels': ['test', 'defaults'], 'create_default_packages': ['ipython', 'numpy'], 'changeps1': False, 'always_yes': True } with make_temp_condarc(condarc) as rc: stdout, stderr = run_conda_command('config', '--file', rc, '--get') print(stdout) assert stdout == """\ --set always_yes True --set changeps1 False --add channels 'defaults' # lowest priority --add channels 'test' # highest priority --add create_default_packages 'numpy' --add create_default_packages 'ipython'\ """ with open(rc, 'r') as fh: print(fh.read()) stdout, stderr = run_conda_command('config', '--file', rc, '--prepend', 'channels', 'mychannel') assert stdout == stderr == '' with open(rc, 'r') as fh: print(fh.read()) assert _read_test_condarc(rc) == """\ channels: - mychannel - test - defaults create_default_packages: - ipython - numpy changeps1: false # Here is a comment always_yes: true """ stdout, stderr = run_conda_command('config', '--file', rc, '--set', 'changeps1', 'true') assert stdout == stderr == '' assert _read_test_condarc(rc) == """\ channels: - mychannel - test - defaults create_default_packages: - ipython - numpy changeps1: true # Here is a comment always_yes: true """ # Test adding a new list key. We couldn't test this above because it # doesn't work yet with odd whitespace condarc = """\ channels: - test - defaults always_yes: true """ with make_temp_condarc(condarc) as rc: stdout, stderr = run_conda_command('config', '--file', rc, '--add', 'disallow', 'perl') assert stdout == stderr == '' assert _read_test_condarc(rc) == condarc + """\
def test_config_command_parser(): # Now test the YAML "parser" # Channels is normal content. # create_default_packages has extra spaces in list items condarc = """\ channels: - test - defaults create_default_packages : - ipython - numpy changeps1: false # Here is a comment always_yes: true """ # First verify that this itself is valid YAML assert yaml_load(condarc) == { "channels": ["test", "defaults"], "create_default_packages": ["ipython", "numpy"], "changeps1": False, "always_yes": True, } with make_temp_condarc(condarc) as rc: stdout, stderr = run_conda_command("config", "--file", rc, "--get") print(stdout) assert ( stdout == """\ --set always_yes True --set changeps1 False --add channels 'defaults' # lowest priority --add channels 'test' # highest priority --add create_default_packages 'numpy' --add create_default_packages 'ipython'\ """ ) with open(rc, "r") as fh: print(fh.read()) stdout, stderr = run_conda_command("config", "--file", rc, "--prepend", "channels", "mychannel") assert stdout == stderr == "" with open(rc, "r") as fh: print(fh.read()) assert ( _read_test_condarc(rc) == """\ channels: - mychannel - test - defaults create_default_packages: - ipython - numpy changeps1: false # Here is a comment always_yes: true """ ) stdout, stderr = run_conda_command("config", "--file", rc, "--set", "changeps1", "true") assert stdout == stderr == "" assert ( _read_test_condarc(rc) == """\ channels: - mychannel - test - defaults create_default_packages: - ipython - numpy changeps1: true # Here is a comment always_yes: true """ ) # Test adding a new list key. We couldn't test this above because it # doesn't work yet with odd whitespace condarc = """\ channels: - test - defaults always_yes: true """ with make_temp_condarc(condarc) as rc: stdout, stderr = run_conda_command("config", "--file", rc, "--add", "disallow", "perl") assert stdout == stderr == "" assert ( _read_test_condarc(rc) == condarc + """\ disallow: - perl """ )
def test_dump(): obj = dict([ ('a_seq', [1, 2, 3]), ('a_map', {'a_key': 'a_value'}), ]) assert obj == yaml_load(yaml_dump(obj))
def load_from_string_data(*seq): return odict( (f, YamlRawParameter.make_raw_parameters(f, yaml_load(test_yaml_raw[f]))) for f in seq)
def test_config_command_parser(): # Now test the YAML "parser" # Channels is normal content. # create_default_packages has extra spaces in list items condarc = """\ channels: - test - defaults create_default_packages : - ipython - numpy changeps1: false # Here is a comment always_yes: true """ # First verify that this itself is valid YAML assert yaml_load(condarc) == {'channels': ['test', 'defaults'], 'create_default_packages': ['ipython', 'numpy'], 'changeps1': False, 'always_yes': True} with make_temp_condarc(condarc) as rc: stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--get', use_exception_handler=True) print(stdout) assert stdout.strip() == """\ --set always_yes True --set changeps1 False --add channels 'defaults' # lowest priority --add channels 'test' # highest priority --add create_default_packages 'numpy' --add create_default_packages 'ipython'\ """ with open(rc, 'r') as fh: print(fh.read()) stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--prepend', 'channels', 'mychannel') assert stdout == stderr == '' with open(rc, 'r') as fh: print(fh.read()) assert _read_test_condarc(rc) == """\ channels: - mychannel - test - defaults create_default_packages: - ipython - numpy changeps1: false # Here is a comment always_yes: true """ stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--set', 'changeps1', 'true') assert stdout == stderr == '' assert _read_test_condarc(rc)== """\ channels: - mychannel - test - defaults create_default_packages: - ipython - numpy changeps1: true # Here is a comment always_yes: true """ # Test adding a new list key. We couldn't test this above because it # doesn't work yet with odd whitespace condarc = """\ channels: - test - defaults always_yes: true """ with make_temp_condarc(condarc) as rc: stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--add', 'disallow', 'perl') assert stdout == stderr == '' assert _read_test_condarc(rc) == condarc + """\
def load_from_string_data(*seq): return odict((f, YamlRawParameter.make_raw_parameters(f, yaml_load(test_yaml_raw[f]))) for f in seq)