예제 #1
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
    try:
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'ssl_verify', 'yes')
        assert stdout == ''
        assert stderr == ''

        verify = yaml.load(open(test_condarc, 'r'))['ssl_verify']
        assert verify == True

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

        verify = yaml.load(open(test_condarc, 'r'))['ssl_verify']
        assert verify == 'test_string.crt'

        os.unlink(test_condarc)
    finally:
        try:
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #2
0
파일: test_config.py 프로젝트: AvdN/conda
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
    try:
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'ssl_verify', 'yes')
        assert stdout == ''
        assert stderr == ''

        verify = yaml.load(open(test_condarc, 'r'))['ssl_verify']
        assert verify == True

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

        verify = yaml.load(open(test_condarc, 'r'))['ssl_verify']
        assert verify == 'test_string.crt'


        os.unlink(test_condarc)
    finally:
        try:
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #3
0
파일: test_info.py 프로젝트: jaimergp/conda
def test_info():
    conda_info_out, conda_info_err = run_conda_command('info')
    assert_equals(conda_info_err, '')
    for name in ['platform', 'conda version', 'root environment',
                 'default environment', 'envs directories', 'package cache',
                 'channel URLs', 'config file', 'offline mode']:
        assert_in(name, conda_info_out)

    conda_info_e_out, conda_info_e_err = run_conda_command('info', '-e')
    assert_in('root', conda_info_e_out)
    assert_equals(conda_info_e_err, '')

    conda_info_s_out, conda_info_s_err = run_conda_command('info', '-s')
    assert_equals(conda_info_s_err, '')
    for name in ['sys.version', 'sys.prefix', 'sys.executable', 'conda location',
                 'conda-build', 'CIO_TEST', 'CONDA_DEFAULT_ENV', 'PATH', 'PYTHONPATH']:
        assert_in(name, conda_info_s_out)
    if config.platform == 'linux':
        assert_in('LD_LIBRARY_PATH', conda_info_s_out)
    if config.platform == 'osx':
        assert_in('DYLD_LIBRARY_PATH', conda_info_s_out)

    conda_info_all_out, conda_info_all_err = run_conda_command('info', '--all')
    assert_equals(conda_info_all_err, '')
    assert_in(conda_info_out, conda_info_all_out)
    assert_in(conda_info_e_out, conda_info_all_out)
    assert_in(conda_info_s_out, conda_info_all_out)
예제 #4
0
def test_info():
    conda_info_out, conda_info_err = run_conda_command('info')
    assert_equals(conda_info_err, '')
    for name in [
            'platform', 'conda version', 'root environment',
            'default environment', 'envs directories', 'package cache',
            'channel URLs', 'config file', 'is foreign system'
    ]:
        assert_in(name, conda_info_out)

    conda_info_e_out, conda_info_e_err = run_conda_command('info', '-e')
    assert_in('root', conda_info_e_out)
    assert_equals(conda_info_e_err, '')

    conda_info_s_out, conda_info_s_err = run_conda_command('info', '-s')
    assert_equals(conda_info_s_err, '')
    for name in [
            'sys.version', 'sys.prefix', 'sys.executable', 'conda location',
            'conda-build', 'CIO_TEST', 'CONDA_DEFAULT_ENV', 'PATH',
            'PYTHONPATH'
    ]:
        assert_in(name, conda_info_s_out)
    if config.platform == 'linux':
        assert_in('LD_LIBRARY_PATH', conda_info_s_out)
    if config.platform == 'osx':
        assert_in('DYLD_LIBRARY_PATH', conda_info_s_out)

    conda_info_all_out, conda_info_all_err = run_conda_command('info', '--all')
    assert_equals(conda_info_all_err, '')
    assert_in(conda_info_out, conda_info_all_out)
    assert_in(conda_info_e_out, conda_info_all_out)
    assert_in(conda_info_s_out, conda_info_all_out)
예제 #5
0
파일: test_config.py 프로젝트: conda/conda
def test_config_command_bad_args():
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command("config", "--file", rc, "--add", "notarealkey", "test")
        assert stdout == ""

        stdout, stderr = run_conda_command("config", "--file", rc, "--set", "notarealkey", "true")
        assert stdout == ""
예제 #6
0
def test_info():
    conda_info_out, conda_info_err = run_conda_command('info')
    assert conda_info_err == ''
    for name in ['platform', 'conda version', 'root environment',
        'default environment', 'envs directories', 'package cache',
        'channel URLs', 'config file', 'is foreign system']:
        assert name in conda_info_out

    conda_info_e_out, conda_info_e_err = run_conda_command('info', '-e')
    assert 'root' in conda_info_e_out
    assert conda_info_e_err == ''

    conda_info_s_out, conda_info_s_err = run_conda_command('info', '-s')
    assert conda_info_s_err == ''
    for name in ['sys.version', 'sys.prefix', 'sys.executable', 'conda location',
        'conda-build', 'CIO_TEST', 'CONDA_DEFAULT_ENV', 'PATH', 'PYTHONPATH']:
        assert name in conda_info_s_out
    if config.platform == 'linux':
        assert 'LD_LIBRARY_PATH' in conda_info_s_out
    if config.platform == 'osx':
        assert 'DYLD_LIBRARY_PATH' in conda_info_s_out

    conda_info_all_out, conda_info_all_err = run_conda_command('info', '--all')
    assert conda_info_all_err == ''
    assert conda_info_out in conda_info_all_out
    assert conda_info_e_out in conda_info_all_out
    assert conda_info_s_out in conda_info_all_out
예제 #7
0
def test_config_command_bad_args():
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
                                           'notarealkey', 'test')
        assert stdout == ''

        stdout, stderr = run_conda_command('config', '--file', rc, '--set',
                                           'notarealkey', 'true')
        assert stdout == ''
예제 #8
0
파일: test_config.py 프로젝트: AvdN/conda
def test_config_command_basics():

    try:
        # Test that creating the file adds the defaults channel
        assert not os.path.exists('test_condarc')
        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
            'channels', 'test')
        assert stdout == stderr == ''
        assert _read_test_condarc() == """\
channels:
  - test
  - defaults
"""
        os.unlink(test_condarc)

        # When defaults is explicitly given, it should not be added
        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
    'channels', 'test', '--add', 'channels', 'defaults')
        assert stdout == stderr == ''
        assert _read_test_condarc() == """\
channels:
  - defaults
  - test
"""
        os.unlink(test_condarc)

        # Duplicate keys should not be added twice
        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
        'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
        'channels', 'test')
        assert stdout == ''
        assert stderr == "Skipping channels: test, item already exists\n"
        assert _read_test_condarc() == """\
channels:
  - test
  - defaults
"""
        os.unlink(test_condarc)

        # Test creating a new file with --set
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
        '--set', 'always_yes', 'yes')
        assert stdout == stderr == ''
        assert _read_test_condarc() == """\
always_yes: yes
"""
        os.unlink(test_condarc)


    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #9
0
def test_config_command_basics():

    try:
        # Test that creating the file adds the defaults channel
        assert not os.path.exists('test_condarc')
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'channels', 'test')
        assert stdout == stderr == ''
        assert _read_test_condarc() == """\
channels:
  - test
  - defaults
"""
        os.unlink(test_condarc)

        # When defaults is explicitly given, it should not be added
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'channels', 'test',
                                           '--add', 'channels', 'defaults')
        assert stdout == stderr == ''
        assert _read_test_condarc() == """\
channels:
  - defaults
  - test
"""
        os.unlink(test_condarc)

        # Duplicate keys should not be added twice
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'channels', 'test')
        assert stdout == ''
        assert stderr == "Skipping channels: test, item already exists\n"
        assert _read_test_condarc() == """\
channels:
  - test
  - defaults
"""
        os.unlink(test_condarc)

        # Test creating a new file with --set
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'always_yes', 'yes')
        assert stdout == stderr == ''
        assert _read_test_condarc() == """\
always_yes: yes
"""
        os.unlink(test_condarc)

    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #10
0
def test_config_command_bad_args():
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'notarealkey', 'test')
        assert stdout == ''

        stdout, stderr = run_conda_command('config', '--file', rc, '--set',
            'notarealkey', 'true')
        assert stdout == ''
예제 #11
0
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), Loader=yaml.RoundTripLoader) == {'channels': ['defaults'],
            'always_yes': True}

        stdout, stderr = run_conda_command('config', '--file', rc,
            '--remove', 'channels', 'test', '--force')
        assert stdout == ''
        assert stderr == "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 == "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), Loader=yaml.RoundTripLoader) == {'channels': ['defaults']}

        stdout, stderr = run_conda_command('config', '--file', rc,
            '--remove-key', 'always_yes', '--force')

        assert stdout == ''
        assert stderr == "Error: key 'always_yes' is not in the config file"
예제 #12
0
파일: test_config.py 프로젝트: Zibi92/conda
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), Loader=yaml.RoundTripLoader) == {'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), Loader=yaml.RoundTripLoader) == {'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"
예제 #13
0
파일: test_config.py 프로젝트: conda/conda
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
예제 #14
0
파일: test_config.py 프로젝트: conda/conda
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 = run_conda_command("config", "--file", rc, "--set", "always_yes", "yes")

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command("config", "--file", rc, "--set", "always_yes", "no")

        assert stdout == ""
        assert stderr == ""
예제 #15
0
파일: test_config.py 프로젝트: conda/conda
def test_invalid_config():
    condarc = """\
fgddgh
channels:
  - test
"""
    try:
        with make_temp_condarc(condarc) as rc:
            rc_path = rc
            run_conda_command("config", "--file", rc, "--add", "channels", "test")
    except LoadError as err:
        error1 = "Load Error: in "
        error2 = "on line 1, column 8. Invalid YAML"
        assert error1 in err.message
        assert error2 in err.message
예제 #16
0
파일: test_config.py 프로젝트: AvdN/conda
def test_invalid_rc():
    # Some tests for unexpected input in the condarc, like keys that are the
    # wrong type
    try:
        condarc = """\
channels:
"""

        with open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--add', 'channels', 'test')
        assert stdout == ''
        assert stderr == """\
Error: Could not parse the yaml file. Use -f to use the
yaml parser (this will remove any structure or comments from the existing
.condarc file). Reason: key 'channels' should be a list, not NoneType.
"""
        assert _read_test_condarc() == condarc

        os.unlink(test_condarc)
    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #17
0
파일: test_config.py 프로젝트: Zibi92/conda
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 = run_conda_command('config', '--file', rc,
                                           '--set', 'always_yes', 'yes')

        assert stdout == ''
        assert stderr == ''

        stdout, stderr = run_conda_command('config', '--file', rc,
                                           '--set', 'always_yes', 'no')

        assert stdout == ''
        assert stderr == ''
예제 #18
0
def test_invalid_config():
    condarc = """\
fgddgh
channels:
  - test
"""
    try:
        with make_temp_condarc(condarc) as rc:
            rc_path = rc
            run_conda_command('config', '--file', rc, '--add', 'channels',
                              'test')
    except LoadError as err:
        error1 = "Load Error: in "
        error2 = "on line 1, column 8. Invalid YAML"
        assert error1 in err.message
        assert error2 in err.message
예제 #19
0
def test_info_package_json():
    out, err = run_conda_command("info", "--json", "numpy=1.11.0=py35_0")
    assert err == ""

    out = json.loads(out)
    assert set(out.keys()) == {"numpy=1.11.0=py35_0"}
    assert len(out["numpy=1.11.0=py35_0"]) == 1
    assert isinstance(out["numpy=1.11.0=py35_0"], list)

    out, err = run_conda_command("info", "--json", "numpy")
    assert err == ""

    out = json.loads(out)
    assert set(out.keys()) == {"numpy"}
    assert len(out["numpy"]) > 1
    assert isinstance(out["numpy"], list)
예제 #20
0
def test_info_package_json():
    out, err = run_conda_command("info", "--json", "numpy=1.11.0=py35_0")
    assert err == ""

    out = json.loads(out)
    assert set(out.keys()) == {"numpy=1.11.0=py35_0"}
    assert len(out["numpy=1.11.0=py35_0"]) == 1
    assert isinstance(out["numpy=1.11.0=py35_0"], list)

    out, err = run_conda_command("info", "--json", "numpy")
    assert err == ""

    out = json.loads(out)
    assert set(out.keys()) == {"numpy"}
    assert len(out["numpy"]) > 1
    assert isinstance(out["numpy"], list)
예제 #21
0
def test_invalid_rc():
    # Some tests for unexpected input in the condarc, like keys that are the
    # wrong type
    try:
        condarc = """\
channels:
"""

        with open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'channels', 'test')
        assert stdout == ''
        assert stderr == """\
Error: Could not parse the yaml file. Use -f to use the
yaml parser (this will remove any structure or comments from the existing
.condarc file). Reason: key 'channels' should be a list, not NoneType.
"""
        assert _read_test_condarc() == condarc

        os.unlink(test_condarc)
    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #22
0
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 = run_conda_command('config', '--file', rc, '--set',
                                           'always_yes', 'yes')

        assert stdout == ''
        assert stderr == ''

        stdout, stderr = run_conda_command('config', '--file', rc, '--set',
                                           'always_yes', 'no')

        assert stdout == ''
        assert stderr == ''
예제 #23
0
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]
예제 #24
0
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]
예제 #25
0
def test_config_command_remove_force():
    try:
        # Finally, test --remove, --remove-key, and --force (right now
        # --remove and --remove-key require --force)
        run_conda_command('config', '--file', test_condarc, '--add',
                          'channels', 'test')
        run_conda_command('config', '--file', test_condarc, '--set',
                          'always_yes', 'yes')
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--remove', 'channels', 'test',
                                           '--force')
        assert stdout == stderr == ''
        assert yaml.load(_read_test_condarc()) == {
            'channels': ['defaults'],
            'always_yes': True
        }

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--remove', 'channels', 'test',
                                           '--force')
        assert stdout == ''
        assert stderr == "Error: 'test' is not in the 'channels' key of the config file\n"

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--remove', 'disallow', 'python',
                                           '--force')
        assert stdout == ''
        assert stderr == "Error: key 'disallow' is not in the config file\n"

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--remove-key', 'always_yes',
                                           '--force')
        assert stdout == stderr == ''
        assert yaml.load(_read_test_condarc()) == {'channels': ['defaults']}

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--remove-key', 'always_yes',
                                           '--force')

        assert stdout == ''
        assert stderr == "Error: key 'always_yes' is not in the config file\n"
        os.unlink(test_condarc)

    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #26
0
파일: test_config.py 프로젝트: conda/conda
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"
예제 #27
0
def test_config_command_basics():

        # Test that creating the file adds the defaults channel
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
          'channels', 'test')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""
    with make_temp_condarc() as rc:
        # When defaults is explicitly given, it should not be added
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'channels', 'test', '--add', 'channels', 'defaults')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""
    # Duplicate keys should not be added twice
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'channels', 'test')
        assert stdout == ''
        assert stderr == "Skipping channels: test, item already exists"
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""

    # Test creating a new file with --set
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc,
            '--set', 'always_yes', 'true')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
예제 #28
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:
        stdout, stderr = run_conda_command('config', '--file', rc,
                                           '--set', 'ssl_verify', 'yes')
        assert stdout == ''
        assert stderr == ''

        verify = yaml.load(open(rc, 'r'), Loader=yaml.RoundTripLoader)['ssl_verify']
        assert verify == 'yes'

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

        verify = yaml.load(open(rc, 'r'), Loader=yaml.RoundTripLoader)['ssl_verify']
        assert verify == 'test_string.crt'
예제 #29
0
파일: test_config.py 프로젝트: AvdN/conda
def test_config_command_bad_args():
    try:
        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
            'notarealkey', 'test')
        assert stdout == ''

        assert not exists(test_condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--set',
            'notarealkey', 'yes')
        assert stdout == ''

        assert not exists(test_condarc)

    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #30
0
파일: test_config.py 프로젝트: Zibi92/conda
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:
        stdout, stderr = run_conda_command('config', '--file', rc,
                                           '--set', 'ssl_verify', 'yes')
        assert stdout == ''
        assert stderr == ''

        verify = yaml.load(open(rc, 'r'), Loader=yaml.RoundTripLoader)['ssl_verify']
        assert verify is True

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

        verify = yaml.load(open(rc, 'r'), Loader=yaml.RoundTripLoader)['ssl_verify']
        assert verify == 'test_string.crt'
예제 #31
0
def test_config_command_bad_args():
    try:
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'notarealkey', 'test')
        assert stdout == ''

        assert not exists(test_condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'notarealkey', 'yes')
        assert stdout == ''

        assert not exists(test_condarc)

    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #32
0
def test_config_set():
    # Test the config set command
    # Make sure it accepts any YAML 1.1 boolean values
    assert yaml_bool(True) is True
    assert yaml_bool(False) is False
    for str in ('yes', 'Yes', 'YES', 'on', 'On', 'ON', 'off', 'Off', 'OFF',
                'no', 'No', 'NO'):
        with make_temp_condarc() as rc:
            stdout, stderr = run_conda_command('config', '--file', rc, '--set',
                                               'always_yes', str)
            assert stdout == ''
            assert stderr == ''
예제 #33
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'
예제 #34
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'
예제 #35
0
def test_config_set():
    # Test the config set command
    # Make sure it accepts any YAML 1.1 boolean values
    assert yaml_bool(True) is True
    assert yaml_bool(False) is False
    for str in ('yes', 'Yes', 'YES', 'on', 'On', 'ON',
                'off', 'Off', 'OFF', 'no', 'No', 'NO'):
      with make_temp_condarc() as rc:
          stdout, stderr = run_conda_command('config', '--file', rc,
                                             '--set', 'always_yes', str)
          assert stdout == ''
          assert stderr == ''
예제 #36
0
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

    try:
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'always_yes', 'yes')

        assert stdout == ''
        assert stderr == 'Error: Key: always_yes; yes is not a YAML boolean.'

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'always_yes', 'no')

        assert stdout == ''
        assert stderr == 'Error: Key: always_yes; no is not a YAML boolean.'

    finally:
        try:
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #37
0
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

    try:
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'always_yes', 'yes')

        assert stdout == ''
        assert stderr == 'Error: Key: always_yes; yes is not a YAML boolean.'

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'always_yes', 'no')

        assert stdout == ''
        assert stderr == 'Error: Key: always_yes; no is not a YAML boolean.'

    finally:
        try:
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #38
0
파일: test_config.py 프로젝트: AvdN/conda
def test_config_command_remove_force():
    try:
        # Finally, test --remove, --remove-key, and --force (right now
        # --remove and --remove-key require --force)
        run_conda_command('config', '--file', test_condarc, '--add',
            'channels', 'test')
        run_conda_command('config', '--file', test_condarc, '--set',
            'always_yes', 'yes')
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--remove', 'channels', 'test', '--force')
        assert stdout == stderr == ''
        assert yaml.load(_read_test_condarc()) == {'channels': ['defaults'],
            'always_yes': True}

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--remove', 'channels', 'test', '--force')
        assert stdout == ''
        assert stderr == "Error: 'test' is not in the 'channels' key of the config file\n"

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--remove', 'disallow', 'python', '--force')
        assert stdout == ''
        assert stderr == "Error: key 'disallow' is not in the config file\n"

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--remove-key', 'always_yes', '--force')
        assert stdout == stderr == ''
        assert yaml.load(_read_test_condarc()) == {'channels': ['defaults']}

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--remove-key', 'always_yes', '--force')

        assert stdout == ''
        assert stderr == "Error: key 'always_yes' is not in the config file\n"
        os.unlink(test_condarc)

    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #39
0
def test_invalid_rc():
    # Some tests for unexpected input in the condarc, like keys that are the
    # wrong type
    condarc = """\
channels:
"""

    with make_temp_condarc(condarc) as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
                                           'channels', 'test')
        assert stdout == ''
        assert stderr == """\
Error: Could not parse the yaml file. Use -f to use the
yaml parser (this will remove any structure or comments from the existing
.condarc file). Reason: key 'channels' should be a list, not NoneType."""
        assert _read_test_condarc(rc) == condarc
예제 #40
0
파일: test_config.py 프로젝트: Zibi92/conda
def test_invalid_rc():
    # Some tests for unexpected input in the condarc, like keys that are the
    # wrong type
    condarc = """\
channels:
"""

    with make_temp_condarc(condarc) as rc:
        stdout, stderr = run_conda_command('config', '--file', rc,
                                           '--add', 'channels', 'test')
        assert stdout == ''
        assert stderr == """\
Parse error: Error: Could not parse the yaml file. Use -f to use the
yaml parser (this will remove any structure or comments from the existing
.condarc file). Reason: key 'channels' should be a list, not NoneType."""
        assert _read_test_condarc(rc) == condarc
예제 #41
0
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
예제 #42
0
def test_config_command_get():
    # Test --get
    condarc = """\
channels:
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: false

always_yes: true

invalid_key: true

channel_alias: http://alpha.conda.anaconda.org
"""
    with make_temp_condarc(condarc) as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--get')
        assert stdout == """\
--set always_yes True
--set changeps1 False
--set channel_alias http://alpha.conda.anaconda.org
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'\
"""
        assert stderr == "unknown key invalid_key"

        stdout, stderr = run_conda_command('config', '--file', rc, '--get',
                                           'channels')

        assert stdout == """\
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority\
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc, '--get',
                                           'changeps1')

        assert stdout == """\
--set changeps1 False\
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc, '--get',
                                           'changeps1', 'channels')

        assert stdout == """\
--set changeps1 False
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority\
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc, '--get',
                                           'allow_softlinks')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc, '--get',
                                           'track_features')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc, '--get',
                                           'invalid_key')

        assert stdout == ""
        assert "invalid choice: 'invalid_key'" in stderr

        stdout, stderr = run_conda_command('config', '--file', rc, '--get',
                                           'not_valid_key')

        assert stdout == ""
        assert "invalid choice: 'not_valid_key'" in stderr
예제 #43
0
파일: test_config.py 프로젝트: AvdN/conda
def test_config_command_get():
    try:
        # Test --get
        with open(test_condarc, 'w') as f:
            f.write("""\
channels:
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: no

always_yes: yes

invalid_key: yes

channel_alias: http://alpha.conda.anaconda.org
""")

        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--get')
        assert stdout == """\
--set always_yes True
--set changeps1 False
--set channel_alias http://alpha.conda.anaconda.org
--add channels 'defaults'
--add channels 'test'
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'
"""
        assert stderr == "unknown key invalid_key\n"

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
        '--get', 'channels')

        assert stdout == """\
--add channels 'defaults'
--add channels 'test'
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
        '--get', 'changeps1')

        assert stdout == """\
--set changeps1 False
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--get', 'changeps1', 'channels')

        assert stdout == """\
--set changeps1 False
--add channels 'defaults'
--add channels 'test'
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
        '--get', 'allow_softlinks')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
        '--get', 'track_features')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
        '--get', 'invalid_key')

        assert stdout == ""
        assert "invalid choice: 'invalid_key'" in stderr

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
        '--get', 'not_valid_key')

        assert stdout == ""
        assert "invalid choice: 'not_valid_key'" in stderr

        os.unlink(test_condarc)


    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #44
0
파일: test_config.py 프로젝트: Zibi92/conda
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: yes
"""
    # First verify that this itself is valid YAML
    assert yaml.load(condarc, Loader=yaml.RoundTripLoader) == {'channels': ['test', 'defaults'],
        'create_default_packages': ['ipython', 'numpy'], 'changeps1':
        False, 'always_yes': 'yes'}

    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'\
"""

        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'channels', 'mychannel')
        assert stdout == stderr == ''

        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 + """\
예제 #45
0
파일: test_config.py 프로젝트: Zibi92/conda
def test_config_command_get():
    # Test --get
    condarc = """\
channels:
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: false

always_yes: true

invalid_key: true

channel_alias: http://alpha.conda.anaconda.org
"""
    with make_temp_condarc(condarc) as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--get')
        assert stdout == """\
--set always_yes True
--set changeps1 False
--set channel_alias http://alpha.conda.anaconda.org
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'\
"""
        assert stderr == "unknown key invalid_key"

        stdout, stderr = run_conda_command('config', '--file', rc,
        '--get', 'channels')

        assert stdout == """\
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority\
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc,
        '--get', 'changeps1')

        assert stdout == """\
--set changeps1 False\
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc,
            '--get', 'changeps1', 'channels')

        assert stdout == """\
--set changeps1 False
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority\
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc,
        '--get', 'allow_softlinks')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc,
        '--get', 'track_features')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', rc,
        '--get', 'invalid_key')

        assert stdout == ""
        assert "invalid choice: 'invalid_key'" in stderr

        stdout, stderr = run_conda_command('config', '--file', rc,
        '--get', 'not_valid_key')

        assert stdout == ""
        assert "invalid choice: 'not_valid_key'" in stderr
예제 #46
0
파일: test_config.py 프로젝트: Zibi92/conda
def test_config_command_basics():

        # Test that creating the file adds the defaults channel
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
          'channels', 'test')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""
    with make_temp_condarc() as rc:
        # When defaults is explicitly given, it should not be added
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'channels', 'test', '--add', 'channels', 'defaults')
        assert stdout == ''
        assert stderr == "Warning: 'defaults' already in 'channels' list, moving to the front"
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""
    # Duplicate keys should not be added twice
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'channels', 'test')
        assert stdout == ''
        assert stderr == "Warning: 'test' already in 'channels' list, moving to the front"
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""

    # Test append
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
            'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', rc, '--append',
            'channels', 'test')
        assert stdout == ''
        assert stderr == "Warning: 'test' already in 'channels' list, moving to the back"
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""

    # Test duoble remove of defaults
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--remove',
            'channels', 'defaults')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', rc, '--remove',
            'channels', 'defaults')
        assert stdout == ''
        assert stderr == "Key error: 'defaults' is not in the 'channels' key of the config file"

    # Test creating a new file with --set
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc,
            '--set', 'always_yes', 'true')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
예제 #47
0
def test_config_command_get():
    try:
        # Test --get
        with open(test_condarc, 'w') as f:
            f.write("""\
channels:
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: no

always_yes: yes

invalid_key: yes

channel_alias: http://alpha.conda.anaconda.org
""")

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get')
        assert stdout == """\
--set always_yes True
--set changeps1 False
--set channel_alias http://alpha.conda.anaconda.org
--add channels 'defaults'
--add channels 'test'
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'
"""
        assert stderr == "unknown key invalid_key\n"

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get', 'channels')

        assert stdout == """\
--add channels 'defaults'
--add channels 'test'
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get', 'changeps1')

        assert stdout == """\
--set changeps1 False
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get', 'changeps1', 'channels')

        assert stdout == """\
--set changeps1 False
--add channels 'defaults'
--add channels 'test'
"""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get', 'allow_softlinks')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get', 'track_features')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get', 'invalid_key')

        assert stdout == ""
        assert "invalid choice: 'invalid_key'" in stderr

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get', 'not_valid_key')

        assert stdout == ""
        assert "invalid choice: 'not_valid_key'" in stderr

        os.unlink(test_condarc)

    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #48
0
def test_config_command_parser():
    try:
        # Now test the YAML "parser"
        condarc = """\
 channels : \n\
   -  test
   -  defaults \n\

 create_default_packages:
    - ipython
    - numpy

 changeps1 :  no

# Here is a comment
 always_yes: yes \n\
"""
        # 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 open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get')

        assert stdout == """\
--set always_yes True
--set changeps1 False
--add channels 'defaults'
--add channels 'test'
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'
"""
        assert stderr == ''

        # List keys with nonstandard whitespace are not yet supported. For
        # now, just test that it doesn't muck up the file.
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'create_default_packages',
                                           'sympy')
        assert stdout == ''
        assert stderr == """\
Error: Could not parse the yaml file. Use -f to use the
yaml parser (this will remove any structure or comments from the existing
.condarc file). Reason: modified yaml doesn't match what it should be
"""
        assert _read_test_condarc() == condarc

        #         assert _read_test_condarc() == """\
        #  channels : \n\
        #    -  test
        #    -  defaults \n\
        #
        #  create_default_packages:
        #     - sympy
        #     - ipython
        #     - numpy
        #
        #  changeps1 :  no
        #
        # # Here is a comment
        #  always_yes: yes \n\
        # """

        # New keys when the keys are indented are not yet supported either.
        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'disallow', 'perl')
        assert stdout == ''
        assert stderr == """\
Error: Could not parse the yaml file. Use -f to use the
yaml parser (this will remove any structure or comments from the existing
.condarc file). Reason: couldn't parse modified yaml
"""
        assert _read_test_condarc() == condarc

        #         assert _read_test_condarc() == """\
        #  channels : \n\
        #    -  test
        #    -  defaults \n\
        #
        #  create_default_packages:
        #     - sympy
        #     - ipython
        #     - numpy
        #
        #  changeps1 :  no
        #
        # # Here is a comment
        #  always_yes: yes \n\
        #  disallow:
        #    - perl
        # """

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'channels', 'mychannel')
        assert stdout == stderr == ''

        assert _read_test_condarc() == """\
 channels : \n\
   - mychannel
   -  test
   -  defaults \n\

 create_default_packages:
    - ipython
    - numpy

 changeps1 :  no

# Here is a comment
 always_yes: yes \n\
"""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'changeps1', 'yes')

        assert stdout == stderr == ''

        assert _read_test_condarc() == """\
 channels : \n\
   - mychannel
   -  test
   -  defaults \n\

 create_default_packages:
    - ipython
    - numpy

 changeps1 :  yes

# Here is a comment
 always_yes: yes \n\
"""

        os.unlink(test_condarc)

        # 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: yes
"""

        with open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'disallow', 'perl')
        assert stdout == stderr == ''
        assert _read_test_condarc() == condarc + """\

disallow:
  - perl
"""
        os.unlink(test_condarc)

    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #49
0
def test_config_command_parser():
    try:
        # 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: yes
"""
        # First verify that this itself is valid YAML
        assert yaml.load(condarc, Loader=yaml.RoundTripLoader) == {
            'channels': ['test', 'defaults'],
            'create_default_packages': ['ipython', 'numpy'],
            'changeps1': False,
            'always_yes': 'yes'
        }

        with open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--get')

        assert stdout == """\
--set always_yes yes
--set changeps1 False
--add channels 'defaults'
--add channels 'test'
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'\
"""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'channels', 'mychannel')
        assert stdout == stderr == ''

        assert _read_test_condarc() == """\
channels:
  - mychannel
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: false

# Here is a comment
always_yes: 'yes'
"""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--set', 'changeps1', 'true')

        assert stdout == stderr == ''

        assert _read_test_condarc() == """\
channels:
  - mychannel
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: true

# Here is a comment
always_yes: 'yes'
"""

        os.unlink(test_condarc)

        # 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 open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
                                           '--add', 'disallow', 'perl')
        assert stdout == stderr == ''
        assert _read_test_condarc() == condarc + """\
disallow:
  - perl
"""
        os.unlink(test_condarc)

    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #50
0
def test_config_command_basics():

    # Test that creating the file adds the defaults channel
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
                                           'channels', 'test')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""
        print(_read_test_condarc(rc))
        print(_read_test_condarc(rc))
        print(_read_test_condarc(rc))

    with make_temp_condarc() as rc:
        # When defaults is explicitly given, it should not be added
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
                                           'channels', 'test', '--add',
                                           'channels', 'defaults')
        assert stdout == ''
        assert stderr == "Warning: 'defaults' already in 'channels' list, moving to the top"
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""
    # Duplicate keys should not be added twice
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
                                           'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
                                           'channels', 'test')
        assert stdout == ''
        assert stderr == "Warning: 'test' already in 'channels' list, moving to the top"
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""

    # Test append
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--add',
                                           'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', rc, '--append',
                                           'channels', 'test')
        assert stdout == ''
        assert stderr == "Warning: 'test' already in 'channels' list, moving to the bottom"
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""

    # Test duoble remove of defaults
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--remove',
                                           'channels', 'defaults')
        assert stdout == stderr == ''
        stdout, stderr = run_conda_command('config', '--file', rc, '--remove',
                                           'channels', 'defaults')
        assert stdout == ''
        assert stderr == "CondaKeyError: Error with key 'channels': 'defaults' is not in the 'channels'\
 key of the config file"

    # Test creating a new file with --set
    with make_temp_condarc() as rc:
        stdout, stderr = run_conda_command('config', '--file', rc, '--set',
                                           'always_yes', 'true')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
예제 #51
0
파일: test_config.py 프로젝트: conda/conda
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
"""
        )
예제 #52
0
파일: test_config.py 프로젝트: 3kwa/conda
def test_config_command_parser():
    try:
        # 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: yes
"""
        # First verify that this itself is valid YAML
        assert yaml.load(condarc, Loader=yaml.RoundTripLoader) == {'channels': ['test', 'defaults'],
            'create_default_packages': ['ipython', 'numpy'], 'changeps1':
            False, 'always_yes': 'yes'}

        with open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--get')

        assert stdout == """\
--set always_yes yes
--set changeps1 False
--add channels 'defaults'
--add channels 'test'
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'\
"""

        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
            'channels', 'mychannel')
        assert stdout == stderr == ''

        assert _read_test_condarc() == """\
channels:
  - mychannel
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: false

# Here is a comment
always_yes: 'yes'
"""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--set', 'changeps1', 'true')

        assert stdout == stderr == ''

        assert _read_test_condarc() == """\
channels:
  - mychannel
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: true

# Here is a comment
always_yes: 'yes'
"""

        os.unlink(test_condarc)

        # 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 open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
            'disallow', 'perl')
        assert stdout == stderr == ''
        assert _read_test_condarc() == condarc + """\
disallow:
  - perl
"""
        os.unlink(test_condarc)


    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #53
0
파일: test_config.py 프로젝트: AvdN/conda
def test_config_command_parser():
    try:
        # Now test the YAML "parser"
        condarc = """\
 channels : \n\
   -  test
   -  defaults \n\

 create_default_packages:
    - ipython
    - numpy

 changeps1 :  no

# Here is a comment
 always_yes: yes \n\
"""
        # 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 open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--get')

        assert stdout == """\
--set always_yes True
--set changeps1 False
--add channels 'defaults'
--add channels 'test'
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'
"""
        assert stderr == ''

        # List keys with nonstandard whitespace are not yet supported. For
        # now, just test that it doesn't muck up the file.
        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
            'create_default_packages', 'sympy')
        assert stdout == ''
        assert stderr == """\
Error: Could not parse the yaml file. Use -f to use the
yaml parser (this will remove any structure or comments from the existing
.condarc file). Reason: modified yaml doesn't match what it should be
"""
        assert _read_test_condarc() == condarc

#         assert _read_test_condarc() == """\
#  channels : \n\
#    -  test
#    -  defaults \n\
#
#  create_default_packages:
#     - sympy
#     - ipython
#     - numpy
#
#  changeps1 :  no
#
# # Here is a comment
#  always_yes: yes \n\
# """

        # New keys when the keys are indented are not yet supported either.
        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
            'disallow', 'perl')
        assert stdout == ''
        assert stderr == """\
Error: Could not parse the yaml file. Use -f to use the
yaml parser (this will remove any structure or comments from the existing
.condarc file). Reason: couldn't parse modified yaml
"""
        assert _read_test_condarc() == condarc

#         assert _read_test_condarc() == """\
#  channels : \n\
#    -  test
#    -  defaults \n\
#
#  create_default_packages:
#     - sympy
#     - ipython
#     - numpy
#
#  changeps1 :  no
#
# # Here is a comment
#  always_yes: yes \n\
#  disallow:
#    - perl
# """

        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
            'channels', 'mychannel')
        assert stdout == stderr == ''

        assert _read_test_condarc() == """\
 channels : \n\
   - mychannel
   -  test
   -  defaults \n\

 create_default_packages:
    - ipython
    - numpy

 changeps1 :  no

# Here is a comment
 always_yes: yes \n\
"""

        stdout, stderr = run_conda_command('config', '--file', test_condarc,
            '--set', 'changeps1', 'yes')

        assert stdout == stderr == ''

        assert _read_test_condarc() == """\
 channels : \n\
   - mychannel
   -  test
   -  defaults \n\

 create_default_packages:
    - ipython
    - numpy

 changeps1 :  yes

# Here is a comment
 always_yes: yes \n\
"""

        os.unlink(test_condarc)


        # 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: yes
"""

        with open(test_condarc, 'w') as f:
            f.write(condarc)

        stdout, stderr = run_conda_command('config', '--file', test_condarc, '--add',
            'disallow', 'perl')
        assert stdout == stderr == ''
        assert _read_test_condarc() == condarc + """\

disallow:
  - perl
"""
        os.unlink(test_condarc)


    finally:
        try:
            pass
            os.unlink(test_condarc)
        except OSError:
            pass
예제 #54
0
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 + """\