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_xonsh_basic(self): activator = Activator('xonsh') self.make_dot_d_files(activator.script_extension) activate_result = activator.activate(self.prefix) with open(activate_result) as fh: activate_data = fh.read() rm_rf(activate_result) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" $CONDA_DEFAULT_ENV = "%(prefix)s" $CONDA_PREFIX = "%(prefix)s" $CONDA_PROMPT_MODIFIER = "(%(prefix)s) " $CONDA_PYTHON_EXE = "%(sys_executable)s" $CONDA_SHLVL = "1" $PATH = "%(new_path)s" source "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.xsh') } with env_var('CONDA_PREFIX', self.prefix): with env_var('CONDA_SHLVL', '1'): with env_var('PATH', os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],)))): reactivate_result = activator.reactivate() with open(reactivate_result) as fh: reactivate_data = fh.read() rm_rf(reactivate_result) assert reactivate_data == dals(""" source "%(deactivate1)s" source "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.xsh'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.xsh'), } deactivate_result = activator.deactivate() with open(deactivate_result) as fh: deactivate_data = fh.read() rm_rf(deactivate_result) new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" del $CONDA_DEFAULT_ENV del $CONDA_PREFIX del $CONDA_PROMPT_MODIFIER del $CONDA_PYTHON_EXE $CONDA_SHLVL = "0" $PATH = "%(new_path)s" source "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.xsh'), }
def test_cmd_exe_basic(self): activator = Activator('cmd.exe') self.make_dot_d_files(activator.script_extension) activate_result = activator.activate(self.prefix) with open(activate_result) as fh: activate_data = fh.read() rm_rf(activate_result) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" @SET "CONDA_DEFAULT_ENV=%(prefix)s" @SET "CONDA_PREFIX=%(prefix)s" @SET "CONDA_PROMPT_MODIFIER=(%(prefix)s) " @SET "CONDA_PYTHON_EXE=%(sys_executable)s" @SET "CONDA_SHLVL=1" @SET "PATH=%(new_path)s" @CALL "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.bat') } with env_var('CONDA_PREFIX', self.prefix): with env_var('CONDA_SHLVL', '1'): with env_var('PATH', os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],)))): reactivate_result = activator.reactivate() with open(reactivate_result) as fh: reactivate_data = fh.read() rm_rf(reactivate_result) assert reactivate_data == dals(""" @CALL "%(deactivate1)s" @CALL "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.bat'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.bat'), } deactivate_result = activator.deactivate() with open(deactivate_result) as fh: deactivate_data = fh.read() rm_rf(deactivate_result) new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" @SET CONDA_DEFAULT_ENV= @SET CONDA_PREFIX= @SET CONDA_PROMPT_MODIFIER= @SET CONDA_PYTHON_EXE= @SET "CONDA_SHLVL=0" @SET "PATH=%(new_path)s" @CALL "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.bat'), }
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
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
def test_fish_basic(self): activator = Activator('fish') self.make_dot_d_files(activator.script_extension) activate_data = activator.activate(self.prefix) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" set -gx CONDA_DEFAULT_ENV "%(prefix)s" set -gx CONDA_PREFIX "%(prefix)s" set -gx CONDA_PROMPT_MODIFIER "(%(prefix)s) " set -gx CONDA_PYTHON_EXE "%(sys_executable)s" set -gx CONDA_SHLVL "1" set -gx PATH "%(new_path)s" source "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.fish') } with env_var('CONDA_PREFIX', self.prefix): with env_var('CONDA_SHLVL', '1'): with env_var('PATH', os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],)))): reactivate_data = activator.reactivate() assert reactivate_data == dals(""" source "%(deactivate1)s" source "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.fish'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.fish'), } deactivate_data = activator.deactivate() new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" set -e CONDA_DEFAULT_ENV set -e CONDA_PREFIX set -e CONDA_PROMPT_MODIFIER set -e CONDA_PYTHON_EXE set -gx CONDA_SHLVL "0" set -gx PATH "%(new_path)s" source "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.fish'), }
def test_powershell_basic(self): activator = Activator('powershell') self.make_dot_d_files(activator.script_extension) activate_data = activator.activate(self.prefix) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" $env:CONDA_DEFAULT_ENV = "%(prefix)s" $env:CONDA_PREFIX = "%(prefix)s" $env:CONDA_PROMPT_MODIFIER = "(%(prefix)s) " $env:CONDA_PYTHON_EXE = "%(sys_executable)s" $env:CONDA_SHLVL = "1" $env:PATH = "%(new_path)s" . "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.ps1') } with env_var('CONDA_PREFIX', self.prefix): with env_var('CONDA_SHLVL', '1'): with env_var('PATH', os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],)))): reactivate_data = activator.reactivate() assert reactivate_data == dals(""" . "%(deactivate1)s" . "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.ps1'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.ps1'), } deactivate_data = activator.deactivate() new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" Remove-Variable CONDA_DEFAULT_ENV Remove-Variable CONDA_PREFIX Remove-Variable CONDA_PROMPT_MODIFIER Remove-Variable CONDA_PYTHON_EXE $env:CONDA_SHLVL = "0" $env:PATH = "%(new_path)s" . "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.ps1'), }
def setUp(cls): string = dals(""" custom_channels: darwin: https://some.url.somewhere/stuff chuck: http://user1:[email protected]:8080/t/tk-1234/with/path pkgs/anaconda: http://192.168.0.15:8080 migrated_custom_channels: darwin: s3://just/cant chuck: file:///var/lib/repo/ pkgs/anaconda: https://repo.continuum.io migrated_channel_aliases: - https://conda.anaconda.org channel_alias: ftp://new.url:8082 default_channels: - http://192.168.0.15:8080/pkgs/anaconda - http://192.168.0.15:8080/pkgs/pro - http://192.168.0.15:8080/pkgs/msys2 """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._set_raw_data(rd) Channel._reset_state() cls.platform = context.subdir cls.DEFAULT_URLS = ['http://192.168.0.15:8080/pkgs/anaconda/%s' % cls.platform, 'http://192.168.0.15:8080/pkgs/anaconda/noarch', 'http://192.168.0.15:8080/pkgs/pro/%s' % cls.platform, 'http://192.168.0.15:8080/pkgs/pro/noarch', 'http://192.168.0.15:8080/pkgs/msys2/%s' % cls.platform, 'http://192.168.0.15:8080/pkgs/msys2/noarch', ]
def setUpClass(cls): string = dals(""" custom_channels: darwin: https://some.url.somewhere/stuff chuck: http://user1:[email protected]:8080/t/tk-1234/with/path pkgs/free: http://192.168.0.15:8080 migrated_custom_channels: darwin: s3://just/cant chuck: file:///var/lib/repo/ pkgs/free: https://repo.continuum.io migrated_channel_aliases: - https://conda.anaconda.org channel_alias: ftp://new.url:8082 default_channels: - http://192.168.0.15:8080/pkgs/free - http://192.168.0.15:8080/pkgs/pro - http://192.168.0.15:8080/pkgs/msys2 """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._add_raw_data(rd) Channel._reset_state() cls.platform = context.subdir cls.DEFAULT_URLS = ['http://192.168.0.15:8080/pkgs/free/%s' % cls.platform, 'http://192.168.0.15:8080/pkgs/free/noarch', 'http://192.168.0.15:8080/pkgs/pro/%s' % cls.platform, 'http://192.168.0.15:8080/pkgs/pro/noarch', 'http://192.168.0.15:8080/pkgs/msys2/%s' % cls.platform, 'http://192.168.0.15:8080/pkgs/msys2/noarch', ]
def setUp(self): string = dals(""" custom_channels: darwin: https://some.url.somewhere/stuff chuck: http://another.url:8080/with/path custom_multichannels: michele: - https://do.it.with/passion - learn_from_every_thing steve: - more-downloads migrated_custom_channels: darwin: s3://just/cant chuck: file:///var/lib/repo/ migrated_channel_aliases: - https://conda.anaconda.org channel_alias: ftp://new.url:8082 conda-build: root-dir: /some/test/path proxy_servers: http: http://user:[email protected]:8080 https: none ftp: sftp: '' ftps: false rsync: 'false' aggressive_update_packages: [] """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._set_raw_data(rd)
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 test_CondaHTTPError(self): msg = "Groot" url = "https://download.url/path/to/groot.tar.gz" status_code = "Groot" reason = "COULD NOT CONNECT" elapsed_time = 1.24 exc = CondaHTTPError(msg, url, status_code, reason, elapsed_time) with env_var("CONDA_JSON", "yes", reset_context): with captured() as c, replace_log_streams(): 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", reset_context): with captured() as c, replace_log_streams(): conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" CondaHTTPError: HTTP Groot COULD NOT CONNECT for url <https://download.url/path/to/groot.tar.gz> Elapsed: 1.24 Groot """).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 = MD5MismatchError(url, target_full_path, expected_md5sum, actual_md5sum) with env_var("CONDA_JSON", "yes", reset_context): with captured() as c, replace_log_streams(): conda_exception_handler(_raise_helper, exc) json_obj = json.loads(c.stdout) assert not c.stderr assert json_obj[ 'exception_type'] == "<class 'conda.exceptions.MD5MismatchError'>" assert json_obj['exception_name'] == 'MD5MismatchError' 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_md5sum'] == expected_md5sum assert json_obj['actual_md5sum'] == actual_md5sum with env_var("CONDA_JSON", "no", reset_context): with captured() as c, replace_log_streams(): conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" MD5MismatchError: 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 sum: abc123 actual md5 sum: deadbeef """).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: [] """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters( 'testdata', yaml_load(string))) context._set_raw_data(rd)
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 = MD5MismatchError(url, target_full_path, 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.MD5MismatchError'>" assert json_obj['exception_name'] == 'MD5MismatchError' 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_sum'] == expected_md5sum assert json_obj['actual_sum'] == actual_md5sum assert json_obj['checksum_type'] == 'md5' 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(""" MD5MismatchError: 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 sum: abc123 actual md5 sum: deadbeef """).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_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", 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", 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_seq_simple(): test_string = dals(""" a_seq: - 1 - 2 - 3 """) assert test_string == yaml_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_load(string))) context._set_raw_data(rd) pytest.raises(ValidationError, context.validate_configuration)
def __init__(self, message, url, status_code, reason): message = dals(""" HTTP %(status_code)s %(reason)s for url <%(url)s> """) + message super(CondaHTTPError, self).__init__(message, url=url, status_code=status_code, reason=reason)
def test_client_ssl_cert(self): string = dals(""" client_ssl_cert_key: /some/key/path """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._add_raw_data(rd) pytest.raises(ValidationError, context.validate_configuration)
def test_map_parameter_must_be_map(self): # regression test for conda/conda#3467 string = dals(""" proxy_servers: bad values """) data = odict(s1=YamlRawParameter.make_raw_parameters('s1', yaml_load(string))) config = SampleConfiguration()._set_raw_data(data) raises(InvalidTypeError, config.validate_all)
def test_map_parameter_must_be_map(self): # regression test for conda/conda#3467 string = dals(""" proxy_servers: bad values """) data = odict( s1=YamlRawParameter.make_raw_parameters('s1', yaml_load(string))) config = SampleConfiguration()._set_raw_data(data) raises(InvalidTypeError, config.validate_all)
def test_channels_defaults_condarc(self): # no channels provided in cli reset_context(()) string = dals(""" channels: ['defaults', 'conda-forge'] """) rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) context._set_raw_data(rd) assert context.channels == ('defaults', 'conda-forge')
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_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_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 path_to_url(path): if not path: message = dals(""" Empty argument to `path_to_url()` not allowed. path cannot be '%r' """ % path) raise CondaValueError(message) if path.startswith('file:/'): return path path = abspath(expanduser(path)) url = urljoin('file:', pathname2url(path)) return url
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 setUpClass(cls): string = dals(""" default_channels: - http://test/conda/anaconda channels: - http://test/conda/anaconda-cluster """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._set_raw_data(rd) Channel._reset_state() cls.platform = context.subdir
def setUpClass(cls): string = dals(""" channel_alias: https://10.2.3.4:8080/conda/t/tk-123-45 migrated_channel_aliases: - https://conda.anaconda.org - http://10.2.3.4:7070/conda """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._set_raw_data(rd) Channel._reset_state() cls.platform = context.subdir
def setUpClass(cls): string = dals(""" channel_alias: https://10.2.3.4:8080/conda/t/tk-123-45 migrated_channel_aliases: - https://conda.anaconda.org - http://10.2.3.4:7070/conda """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._add_raw_data(rd) Channel._reset_state() cls.platform = context.subdir
def 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_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_specify_different_channels_cli_condarc(self): """ When the channel have been specified in condarc, these channels should be used along with the one specified In this test, the given channel in cli is different from condarc 'defaults' should not be added """ reset_context((), argparse_args=AttrDict(channel=['other'])) string = dals(""" channels: ['conda-forge'] """) rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_round_trip_load(string))) context._set_raw_data(rd) assert context.channels == ('conda-forge', 'other')
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) with env_var("CONDA_PATH_CONFLICT", "prevent", reset_context): 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_BasicClobberError(self): source_path = "some/path/on/goodwin.ave" target_path = "some/path/to/wright.st" exc = BasicClobberError(source_path, target_path, context) with env_var("CONDA_PATH_CONFLICT", "prevent", reset_context): with captured() as c, replace_log_streams(): 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", reset_context): 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_yaml_complex(): test_string = dals(""" single_bool: false single_str: no # comment here a_seq_1: - 1 - 2 - 3 a_seq_2: - 1 # with comment - two: 2 - 3 a_map: # comment field1: true field2: yes # final comment """) python_structure = { 'single_bool': False, 'single_str': 'no', 'a_seq_1': [ 1, 2, 3, ], 'a_seq_2': [ 1, {'two': 2}, 3, ], 'a_map': { 'field1': True, 'field2': 'yes', }, } loaded_from_string = yaml_load(test_string) assert python_structure == loaded_from_string dumped_from_load = yaml_dump(loaded_from_string) print(dumped_from_load) assert dumped_from_load == test_string
def setUp(self): string = dals(""" custom_channels: darwin: https://some.url.somewhere/stuff chuck: http://another.url:8080/with/path migrated_custom_channels: darwin: s3://just/cant chuck: file:///var/lib/repo/ migrated_channel_aliases: - https://conda.anaconda.org channel_alias: ftp://new.url:8082 """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._add_raw_data(rd)
def setUpClass(cls): channels_config = dals(""" channels: - http://user22:[email protected]:8080 whitelist_channels: - http://user22:[email protected]:8080 custom_channels: unexpanded: http://user1:[email protected]:8080/with/path/t/tk-1234 expanded: http://user33:[email protected]:8080/with/path/t/tk-1234 """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(channels_config))) context._set_raw_data(rd)
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 run_script(prefix, dist, action='post-link', env_prefix=None): """ call the post-link (or pre-unlink) script, and return True on success, False on failure """ if action == 'pre-link': warnings.warn(dals(""" Package %s uses a pre-link script. Pre-link scripts are potentially dangerous. This is because pre-link scripts have the ability to change the package contents in the package cache, and therefore modify the underlying files for already-created conda environments. Future versions of conda may deprecate and ignore pre-link scripts. """ % dist)) path = join(prefix, 'Scripts' if on_win else 'bin', '.%s-%s.%s' % ( dist.dist_name, action, 'bat' if on_win else 'sh')) if not isfile(path): return True if on_win: try: args = [os.environ['COMSPEC'], '/c', path] except KeyError: return False else: shell_path = '/bin/sh' if 'bsd' in sys.platform else '/bin/bash' args = [shell_path, path] env = os.environ.copy() name, version, _, _ = dist.quad build_number = dist.build_number() env[str('ROOT_PREFIX')] = sys.prefix env[str('PREFIX')] = str(env_prefix or prefix) env[str('PKG_NAME')] = name env[str('PKG_VERSION')] = version env[str('PKG_BUILDNUM')] = build_number if action == 'pre-link': env[str('SOURCE_DIR')] = str(prefix) try: check_call(args, env=env) except CalledProcessError: return False else: return True finally: messages(prefix)
def setUpClass(cls): string = dals(""" custom_channels: chuck: http://user1:[email protected]:8080/with/path/t/tk-1234 chuck/subchan: http://user33:[email protected]:8080/with/path/t/tk-1234 channel_alias: ftp://nm:[email protected]:8082/t/zyx-wvut/ channels: - mickey - https://conda.anaconda.cloud/t/tk-12-token/minnie - http://dont-do:[email protected]/daffy/label/main default_channels: - http://192.168.0.15:8080/pkgs/free - donald/label/main - http://us:[email protected]:8080/t/tkn-123/pkgs/r """) reset_context() rd = odict(testdata=YamlRawParameter.make_raw_parameters('testdata', yaml_load(string))) context._add_raw_data(rd) Channel._reset_state() cls.platform = context.subdir
def test_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 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()
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 channels:
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_map(): test_string = dals(""" a_map: a_key: a_value """) assert test_string == yaml_dump({'a_map': {'a_key': 'a_value'}})
from conda.common.configuration import ValidationError 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 channels:
from conda.common.compat import (string_types, odict) from conda.common.configuration import (Configuration, SequenceParameter, PrimitiveParameter, MapParameter, YamlRawParameter, load_raw_configs, ParameterFlag, ValidationError) from conda.common.yaml import yaml_load from conda.exceptions import ValidationError as CondaValidationError 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 channels: