def test_PackageNotFoundError(self): package = "Potato" with env_var("CONDA_JSON", "yes", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: exc = PackagesNotFoundError((package, )) conda_exception_handler(_raise_helper, exc) json_obj = json.loads(c.stdout) assert not c.stderr assert json_obj[ 'exception_type'] == "<class 'conda.exceptions.PackagesNotFoundError'>" assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) with env_var("CONDA_JSON", "no", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" PackagesNotFoundError: The following packages are missing from the target environment: - Potato """).strip()
def setUp(self): string = dals(""" custom_channels: darwin: https://some.url.somewhere/stuff chuck: http://another.url:8080/with/path custom_multichannels: michele: - https://do.it.with/passion - learn_from_every_thing steve: - more-downloads migrated_custom_channels: darwin: s3://just/cant chuck: file:///var/lib/repo/ migrated_channel_aliases: - https://conda.anaconda.org channel_alias: ftp://new.url:8082 conda-build: root-dir: /some/test/path proxy_servers: http: http://user:[email protected]:8080 https: none ftp: sftp: '' ftps: false rsync: 'false' aggressive_update_packages: [] channel_priority: false """) reset_context(()) rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) context._set_raw_data(rd)
def test_seq_simple(): test_string = dals(""" a_seq: - 1 - 2 - 3 """) assert test_string == yaml_round_trip_dump({'a_seq': [1, 2, 3]})
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_round_trip_load(string))) context._set_raw_data(rd) pytest.raises(ValidationError, context.validate_configuration)
def test_signing_metadata_url_base_empty_default_channels(self): string = dals(""" default_channels: [] """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) context._set_raw_data(rd) assert len(context.default_channels) is 0 assert context.signing_metadata_url_base is None
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_round_trip_load(string))) config = SampleConfiguration()._set_raw_data(data) raises(InvalidTypeError, config.validate_all)
def test_channels_defaults_condarc(self): """ Test when no channels provided in cli, but some in condarc """ reset_context(()) string = dals(""" channels: ['defaults', 'conda-forge'] """) rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) context._set_raw_data(rd) assert context.channels == ('defaults', 'conda-forge')
def test_specify_channels_cli_condarc(self): """ When the channel have been specified in condarc, these channels should be used along with the one specified """ reset_context((), argparse_args=AttrDict(channel=['conda-forge'])) string = dals(""" channels: ['defaults', 'conda-forge'] """) rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) context._set_raw_data(rd) assert context.channels == ('defaults', 'conda-forge')
def test_token_replace_big_string(): test_string = dals(""" 555.123.4567 +1-(800)-555-2468 [email protected] [email protected] www.demo.com http://foo.co.uk/t/tk-abkdehc1n38cCBDHN-cje/more/stuf/like/this.html?q=bar http://regexr.com/t/tk-abkdehc1n38cCBDHN-cje/more/stuf/like/this.html?q=bar https://mediatemple.net/t/tk-abkdehc1n38cCBDHN-cje/more/stuf/like/this.html?q=bar http://132.154.8.8:1010/t/tk-abkdehc1n38cCBDHN-cje/more/stuf/like/this.html?q=bar /t/tk-abkdehc1n38cCBDHN-cje/more/stuf/like/this.html?q=bar /t/tk-abkdehc1n38cCBDHN-cje/more/stuf/like/this.html?q=bar https://mediatemple.net/t/tk-abkdehc1n38cCBDHN-cje/more/stuf/like/this.html?q=bar http://foo.co.uk:8080/t/tk-abkdehc1n38cCBDHN-cje/more/stuf/like/this.html?q=bar """) result_string = dals(""" 555.123.4567 +1-(800)-555-2468 [email protected] [email protected] www.demo.com http://foo.co.uk/t/<TOKEN>/more/stuf/like/this.html?q=bar http://regexr.com/t/<TOKEN>/more/stuf/like/this.html?q=bar https://mediatemple.net/t/<TOKEN>/more/stuf/like/this.html?q=bar http://132.154.8.8:1010/t/<TOKEN>/more/stuf/like/this.html?q=bar /t/<TOKEN>/more/stuf/like/this.html?q=bar /t/<TOKEN>/more/stuf/like/this.html?q=bar https://mediatemple.net/t/<TOKEN>/more/stuf/like/this.html?q=bar http://foo.co.uk:8080/t/<TOKEN>/more/stuf/like/this.html?q=bar """) print(TR(test_string)) assert TR(test_string) == result_string
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_round_trip_load(test_string) assert python_structure == loaded_from_string dumped_from_load = yaml_round_trip_dump(loaded_from_string) print(dumped_from_load) assert dumped_from_load == test_string
def test_make_entry_point(self): with tempdir() as conda_temp_prefix: conda_prefix = abspath(sys.prefix) if on_win: conda_exe_path = join(conda_temp_prefix, 'Scripts', 'conda-script.py') else: conda_exe_path = join(conda_temp_prefix, 'bin', 'conda') result = make_entry_point(conda_exe_path, conda_prefix, 'conda.entry.point', 'run') assert result == Result.MODIFIED with open(conda_exe_path) as fh: ep_contents = fh.read() if on_win: assert ep_contents == dals(""" # -*- coding: utf-8 -*- import sys if __name__ == '__main__': from conda.entry.point import run sys.exit(run()) """) else: assert ep_contents == dals(""" #!%s/bin/python # -*- coding: utf-8 -*- import sys if __name__ == '__main__': from conda.entry.point import run sys.exit(run()) """) % conda_prefix result = make_entry_point(conda_exe_path, conda_prefix, 'conda.entry.point', 'run') assert result == Result.NO_CHANGE
def test_specify_same_channels_cli_as_in_condarc(self): """ When the channel have been specified in condarc, these channels should be used along with the one specified In this test, the given channel in cli is the same as in condarc 'defaults' should not be added See https://github.com/conda/conda/issues/10732 """ reset_context((), argparse_args=AttrDict(channel=['conda-forge'])) string = dals(""" channels: ['conda-forge'] """) rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) context._set_raw_data(rd) assert context.channels == ('conda-forge',)
def test_BasicClobberError(self): source_path = "some/path/on/goodwin.ave" target_path = "some/path/to/wright.st" exc = BasicClobberError(source_path, target_path, context) t = repr(exc) with env_var("CONDA_PATH_CONFLICT", "prevent", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" ClobberError: Conda was asked to clobber an existing path. source path: some/path/on/goodwin.ave target path: some/path/to/wright.st """).strip()
def test_SharedLinkPathClobberError(self): target_path = "some/where/in/shampoo/banana" incompatible_package_dists = "Groot" exc = SharedLinkPathClobberError(target_path, incompatible_package_dists, context) with env_var("CONDA_PATH_CONFLICT", "prevent", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" ClobberError: This transaction has incompatible packages due to a shared path. packages: G, r, o, o, t path: 'some/where/in/shampoo/banana' """).strip()
def test_BinaryPrefixReplacementError(self): new_data_length = 1104 original_data_length = 1404 new_prefix = "some/where/on/goodwin.ave" path = "some/where/by/boneyard/creek" placeholder = "save/my/spot/in/374" exc = BinaryPrefixReplacementError(path, placeholder, new_prefix, original_data_length, new_data_length) with env_var("CONDA_JSON", "yes", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) json_obj = json.loads(c.stdout) assert not c.stderr assert json_obj[ 'exception_type'] == "<class 'conda.exceptions.BinaryPrefixReplacementError'>" assert json_obj['exception_name'] == 'BinaryPrefixReplacementError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['new_data_length'] == 1104 assert json_obj['original_data_length'] == 1404 assert json_obj['new_prefix'] == new_prefix assert json_obj['path'] == path assert json_obj['placeholder'] == placeholder with env_var("CONDA_JSON", "no", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" BinaryPrefixReplacementError: Refusing to replace mismatched data length in binary file. path: some/where/by/boneyard/creek placeholder: save/my/spot/in/374 new prefix: some/where/on/goodwin.ave original data Length: 1404 new data length: 1104 """).strip()
def test_UnknownPackageClobberError(self): target_path = "siebel/center/for/c.s" colliding_dist_being_linked = "Groot" exc = UnknownPackageClobberError(target_path, colliding_dist_being_linked, context) with env_var("CONDA_PATH_CONFLICT", "prevent", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" ClobberError: The package 'Groot' cannot be installed due to a path collision for 'siebel/center/for/c.s'. This path already exists in the target prefix, and it won't be removed by an uninstall action in this transaction. The path is one that conda doesn't recognize. It may have been created by another package manager. """).strip()
def test_KnownPackageClobberError(self): target_path = "some/where/on/goodwin.ave" colliding_dist_being_linked = "Groot" colliding_linked_dist = "Liquid" exc = KnownPackageClobberError(target_path, colliding_dist_being_linked, colliding_linked_dist, context) with env_var("CONDA_PATH_CONFLICT", "prevent", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" ClobberError: The package 'Groot' cannot be installed due to a path collision for 'some/where/on/goodwin.ave'. This path already exists in the target prefix, and it won't be removed by an uninstall action in this transaction. The path appears to be coming from the package 'Liquid', which is already installed in the prefix. """).strip()
def test_CondaHTTPError(self): msg = "Potato" url = "https://download.url/path/to/Potato.tar.gz" status_code = "Potato" reason = "COULD NOT CONNECT" elapsed_time = 1.24 exc = CondaHTTPError(msg, url, status_code, reason, elapsed_time) with env_var("CONDA_JSON", "yes", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) json_obj = json.loads(c.stdout) assert not c.stderr assert json_obj[ 'exception_type'] == "<class 'conda.exceptions.CondaHTTPError'>" assert json_obj['exception_name'] == 'CondaHTTPError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['url'] == url assert json_obj['status_code'] == status_code assert json_obj['reason'] == reason assert json_obj['elapsed_time'] == elapsed_time with env_var("CONDA_JSON", "no", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert dals(""" CondaHTTPError: HTTP Potato COULD NOT CONNECT for url <https://download.url/path/to/Potato.tar.gz> Elapsed: 1.24 Potato """).strip() in c.stderr.strip()
def test_MD5MismatchError(self): url = "https://download.url/path/to/file.tar.bz2" target_full_path = "/some/path/on/disk/another-name.tar.bz2" expected_md5sum = "abc123" actual_md5sum = "deadbeef" exc = ChecksumMismatchError(url, target_full_path, "md5", expected_md5sum, actual_md5sum) with env_var("CONDA_JSON", "yes", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) json_obj = json.loads(c.stdout) assert not c.stderr assert json_obj[ 'exception_type'] == "<class 'conda.exceptions.ChecksumMismatchError'>" assert json_obj['exception_name'] == 'ChecksumMismatchError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['url'] == url assert json_obj['target_full_path'] == target_full_path assert json_obj['expected_checksum'] == expected_md5sum assert json_obj['actual_checksum'] == actual_md5sum with env_var("CONDA_JSON", "no", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" ChecksumMismatchError: Conda detected a mismatch between the expected content and downloaded content for url 'https://download.url/path/to/file.tar.bz2'. download saved to: /some/path/on/disk/another-name.tar.bz2 expected md5: abc123 actual md5: deadbeef """).strip()
from os import environ, mkdir from os.path import join from pytest import raises from shutil import rmtree from tempfile import mkdtemp from unittest import TestCase test_yaml_raw = { 'file1': dals(""" always_yes: no proxy_servers: http: taz https: sly s3: pepé channels_altname: - bugs - daffy - tweety """), 'file2': dals(""" always_yes: yes changeps1: no proxy_servers: http: marv https: sam
def test_map(): test_string = dals(""" a_map: a_key: a_value """) assert test_string == yaml_round_trip_dump({'a_map': {'a_key': 'a_value'}})
def test_init_sh_user_unix(self): with tempdir() as conda_temp_prefix: target_path = join(conda_temp_prefix, '.bashrc') initial_content = dals(""" export PATH="/some/other/conda/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" # >>> conda initialize >>> __conda_setup="$('%(prefix)s/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then fi unset __conda_setup # <<< conda initialize <<< . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh \t source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } with open(target_path, 'w') as fh: fh.write(initial_content) init_sh_user(target_path, conda_temp_prefix, 'bash') with open(target_path) as fh: new_content = fh.read() expected_new_content = dals(""" export PATH="/some/other/conda/bin:$PATH" # export PATH="%(prefix)s/bin:$PATH" # commented out by conda initialize # export PATH="%(prefix)s/bin:$PATH" # commented out by conda initialize # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('%(prefix)s/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "%(prefix)s/etc/profile.d/conda.sh" ]; then . "%(prefix)s/etc/profile.d/conda.sh" else export PATH="%(prefix)s/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<< # . etc/profile.d/conda.sh # commented out by conda initialize . etc/profile.d/coda.sh # . /somewhere/etc/profile.d/conda.sh # commented out by conda initialize # source /etc/profile.d/conda.sh # commented out by conda initialize # source %(prefix)s/etc/profile.d/conda.sh # commented out by conda initialize """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } print(new_content) assert new_content == expected_new_content expected_reversed_content = dals(""" export PATH="/some/other/conda/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } init_sh_user(target_path, conda_temp_prefix, 'bash', reverse=True) with open(target_path) as fh: reversed_content = fh.read() print(reversed_content) assert reversed_content == expected_reversed_content
def test_init_sh_user_windows(self): with tempdir() as conda_temp_prefix: target_path = join(conda_temp_prefix, '.bashrc') conda_prefix = "c:\\Users\\Lars\\miniconda" cygpath_conda_prefix = "/c/Users/Lars/miniconda" initial_content = dals(""" source /c/conda/Scripts/activate root . $(cygpath 'c:\\conda\\Scripts\\activate') root # >>> conda initialize >>> __conda_setup="$('%(prefix)s/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then fi unset __conda_setup # <<< conda initialize <<< . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh \t source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_ok(abspath(conda_prefix)), } with open(target_path, 'w') as fh: fh.write(initial_content) init_sh_user(target_path, conda_prefix, 'bash') with open(target_path) as fh: new_content = fh.read() print(new_content) expected_new_content = dals(""" # source /c/conda/Scripts/activate root # commented out by conda initialize # . $(cygpath 'c:\\conda\\Scripts\\activate') root # commented out by conda initialize # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! eval "$('%(cygpath_conda_prefix)s/Scripts/conda.exe' 'shell.bash' 'hook')" # <<< conda initialize <<< # . etc/profile.d/conda.sh # commented out by conda initialize . etc/profile.d/coda.sh # . /somewhere/etc/profile.d/conda.sh # commented out by conda initialize # source /etc/profile.d/conda.sh # commented out by conda initialize # source %(prefix)s/etc/profile.d/conda.sh # commented out by conda initialize """) % { 'prefix': win_path_ok(abspath(conda_prefix)), 'cygpath_conda_prefix': cygpath_conda_prefix, } assert new_content == expected_new_content expected_reversed_content = dals(""" source /c/conda/Scripts/activate root . $(cygpath 'c:\\conda\\Scripts\\activate') root . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_ok(abspath(conda_prefix)), } init_sh_user(target_path, conda_temp_prefix, 'bash', reverse=True) with open(target_path) as fh: reversed_content = fh.read() print(reversed_content) assert reversed_content == expected_reversed_content