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_TooManyArgumentsError(self): expected = 2 received = 5 offending_arguments = "groot" exc = TooManyArgumentsError(expected, received, offending_arguments) 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.TooManyArgumentsError'>" assert json_obj['exception_name'] == 'TooManyArgumentsError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['expected'] == 2 assert json_obj['received'] == 5 assert json_obj['offending_arguments'] == "groot" 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() == "TooManyArgumentsError: Got 5 arguments (g, r, o, o, t) but expected 2."
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_get_index_no_platform_with_offline_cache(self): import conda.core.subdir_data with env_var('CONDA_REPODATA_TIMEOUT_SECS', '0', stack_callback=conda_tests_ctxt_mgmt_def_pol): with patch.object(conda.core.subdir_data, 'read_mod_and_etag') as read_mod_and_etag: read_mod_and_etag.return_value = {} channel_urls = ('https://repo.anaconda.com/pkgs/pro',) with env_var('CONDA_REPODATA_TIMEOUT_SECS', '0', stack_callback=conda_tests_ctxt_mgmt_def_pol): this_platform = context.subdir index = get_index(channel_urls=channel_urls, prepend=False) for dist, record in iteritems(index): assert platform_in_record(this_platform, record), (this_platform, record.url) # When unknown=True (which is implicity engaged when context.offline is # True), there may be additional items in the cache that are included in # the index. But where those items coincide with entries already in the # cache, they must not change the record in any way. TODO: add one or # more packages to the cache so these tests affirmatively exercise # supplement_index_from_cache on CI? for unknown in (None, False, True): with env_var('CONDA_OFFLINE', 'yes', stack_callback=conda_tests_ctxt_mgmt_def_pol): with patch.object(conda.core.subdir_data, 'fetch_repodata_remote_request') as remote_request: index2 = get_index(channel_urls=channel_urls, prepend=False, unknown=unknown) assert all(index2.get(k) == rec for k, rec in iteritems(index)) assert unknown is not False or len(index) == len(index2) assert remote_request.call_count == 0 for unknown in (False, True): with env_var('CONDA_REPODATA_TIMEOUT_SECS', '0', stack_callback=conda_tests_ctxt_mgmt_def_pol): with patch.object(conda.core.subdir_data, 'fetch_repodata_remote_request') as remote_request: remote_request.side_effect = Response304ContentUnchanged() index3 = get_index(channel_urls=channel_urls, prepend=False, unknown=unknown) assert all(index3.get(k) == rec for k, rec in iteritems(index)) assert unknown or len(index) == len(index3)
def test_fetchrepodate_connectionerror(self): with env_var('CONDA_REMOTE_CONNECT_TIMEOUT_SECS', 1, conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_READ_TIMEOUT_SECS', 1, conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_MAX_RETRIES', 1, conda_tests_ctxt_mgmt_def_pol): with pytest.raises(CondaHTTPError) as execinfo: url = "http://240.0.0.0/channel/osx-64" msg = "Connection error:" fetch_repodata_remote_request(url, None, None) assert msg in str(execinfo)
def test_download_connectionerror(self): with env_var('CONDA_REMOTE_CONNECT_TIMEOUT_SECS', 1, conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_READ_TIMEOUT_SECS', 1, conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_MAX_RETRIES', 1, conda_tests_ctxt_mgmt_def_pol): with pytest.raises(CondaHTTPError) as execinfo: url = "http://240.0.0.0/" msg = "Connection error:" download(url, mktemp()) assert msg in str(execinfo)
def test_print_unexpected_error_message_upload_2(self, post_mock): with env_var('CONDA_JSON', 'true', stack_callback=conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_YES', 'yes', stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: ExceptionHandler()(_raise_helper, AssertionError()) assert post_mock.call_count == 3 assert len(json.loads(c.stdout)['conda_info']['channels']) >= 2 assert not c.stderr
def test_fetchrepodate_connectionerror(self): with env_var('CONDA_REMOTE_CONNECT_TIMEOUT_SECS', 1, reset_context): with env_var('CONDA_REMOTE_READ_TIMEOUT_SECS', 1, reset_context): with env_var('CONDA_REMOTE_MAX_RETRIES', 1, reset_context): with pytest.raises(CondaHTTPError) as execinfo: url = "http://240.0.0.0/channel/osx-64" msg = "Connection error:" fetch_repodata(url) assert msg in str(execinfo)
def test_local_build_root_custom_rc(self): assert context.local_build_root == "C:\\some\\test\\path" if on_win else "/some/test/path" test_path_1 = join(os.getcwd(), 'test_path_1') with env_var("CONDA_CROOT", test_path_1, stack_callback=conda_tests_ctxt_mgmt_def_pol): assert context.local_build_root == test_path_1 test_path_2 = join(os.getcwd(), 'test_path_2') with env_var("CONDA_BLD_PATH", test_path_2, stack_callback=conda_tests_ctxt_mgmt_def_pol): assert context.local_build_root == test_path_2
def test_local_build_root_custom_rc(self): assert context.local_build_root == "C:\\some\\test\\path" if on_win else "/some/test/path" test_path_1 = join(os.getcwd(), 'test_path_1') with env_var("CONDA_CROOT", test_path_1, reset_context): assert context.local_build_root == test_path_1 test_path_2 = join(os.getcwd(), 'test_path_2') with env_var("CONDA_BLD_PATH", test_path_2, reset_context): assert context.local_build_root == test_path_2
def test_tmpDownload(self): with env_var('CONDA_REMOTE_CONNECT_TIMEOUT_SECS', 1, conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_READ_TIMEOUT_SECS', 1, conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_MAX_RETRIES', 1, conda_tests_ctxt_mgmt_def_pol): url = "https://repo.anaconda.com/pkgs/free/osx-64/appscript-1.0.1-py27_0.tar.bz2" with TmpDownload(url) as dst: assert exists(dst) assert isfile(dst) msg = "Rock and Roll Never Die" with TmpDownload(msg) as result: assert result == msg
def test_subdirs_env_var(self): subdirs = ('linux-highest', 'linux-64', 'noarch') def _channel_urls(channels=None): for channel in channels or DEFAULT_CHANNELS: channel = Channel(channel) for subdir in subdirs: yield join_url(channel.base_url, subdir) with env_var('CONDA_SUBDIRS', ','.join(subdirs), reset_context): c = Channel('defaults') assert c.urls() == list(_channel_urls()) c = Channel('conda-forge') assert c.urls() == list(_channel_urls(('conda-forge',))) channels = ('bioconda', 'conda-forge') prioritized = prioritize_channels(channels) assert prioritized == OrderedDict(( ("https://conda.anaconda.org/bioconda/linux-highest", ("bioconda", 0)), ("https://conda.anaconda.org/bioconda/linux-64", ("bioconda", 0)), ("https://conda.anaconda.org/bioconda/noarch", ("bioconda", 0)), ("https://conda.anaconda.org/conda-forge/linux-highest", ("conda-forge", 1)), ("https://conda.anaconda.org/conda-forge/linux-64", ("conda-forge", 1)), ("https://conda.anaconda.org/conda-forge/noarch", ("conda-forge", 1)), )) prioritized = prioritize_channels(channels, subdirs=('linux-again', 'noarch')) assert prioritized == OrderedDict(( ("https://conda.anaconda.org/bioconda/linux-again", ("bioconda", 0)), ("https://conda.anaconda.org/bioconda/noarch", ("bioconda", 0)), ("https://conda.anaconda.org/conda-forge/linux-again", ("conda-forge", 1)), ("https://conda.anaconda.org/conda-forge/noarch", ("conda-forge", 1)), ))
def test_toolz_cytoolz_package_cache_regression(self): with make_temp_env("python=3.5") as prefix: pkgs_dir = join(prefix, 'pkgs') with env_var('CONDA_PKGS_DIRS', pkgs_dir, reset_context): assert context.pkgs_dirs == (pkgs_dir,) run_command(Commands.INSTALL, prefix, "-c conda-forge toolz cytoolz") assert_package_is_installed(prefix, 'toolz-')
def test_local_channel(self): conda_bld_path = join(gettempdir(), 'conda-bld') mkdir_p(conda_bld_path) try: with env_var('CONDA_CROOT', conda_bld_path, reset_context): Channel._reset_state() channel = Channel('local') assert channel._channels[0].name.rsplit('/', 1)[-1] == 'conda-bld' assert channel.channel_name == "local" assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme is None assert channel.canonical_name == "local" local_channel_first_subchannel = channel._channels[0].name channel = Channel(local_channel_first_subchannel) assert channel.channel_name == local_channel_first_subchannel assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme == "file" assert channel.canonical_name == "local" assert channel.urls() == Channel(local_channel_first_subchannel).urls() assert channel.urls()[0].startswith('file:///') finally: rm_rf(conda_bld_path)
def test_channel_order_channel_priority_true(self): with env_var("CONDA_PINNED_PACKAGES", "python=3.5", reset_context): with make_temp_env("pycosat==0.6.1") as prefix: assert_package_is_installed(prefix, 'python-3.5') assert_package_is_installed(prefix, 'pycosat') # add conda-forge channel o, e = run_command(Commands.CONFIG, prefix, "--prepend channels conda-forge", '--json') assert context.channels == ("conda-forge", "defaults"), o + e # update --all update_stdout, _ = run_command(Commands.UPDATE, prefix, '--all') # this assertion works with the pinned_packages config to make sure # conda update --all still respects the pinned python version assert_package_is_installed(prefix, 'python-3.5') # pycosat should be in the SUPERSEDED list # after the 4.4 solver work, looks like it's in the DOWNGRADED list # This language needs changed anyway here. # For packages that CHANGE because they're being moved to a higher-priority channel # the message should be # # The following packages will be UPDATED to a higher-priority channel: # installed_str, x = update_stdout.split('UPDATED') updated_str, downgraded_str = x.split('DOWNGRADED') assert 'pycosat:' in updated_str # python sys.version should show conda-forge python python_tuple = get_conda_list_tuple(prefix, "python") assert python_tuple[3] == 'conda-forge' # conda list should show pycosat coming from conda-forge pycosat_tuple = get_conda_list_tuple(prefix, "pycosat") assert pycosat_tuple[3] == 'conda-forge'
def test_config_resets(self): appname = "myapp" config = SampleConfiguration(app_name=appname) assert config.changeps1 is True with env_var("MYAPP_CHANGEPS1", "false"): config.__init__(app_name=appname) assert config.changeps1 is False
def test_target_prefix(self): with tempdir() as prefix: mkdir_p(join(prefix, 'first', 'envs')) mkdir_p(join(prefix, 'second', 'envs')) create_package_cache_directory(join(prefix, 'first', 'pkgs')) create_package_cache_directory(join(prefix, 'second', 'pkgs')) envs_dirs = (join(prefix, 'first', 'envs'), join(prefix, 'second', 'envs')) with env_var('CONDA_ENVS_DIRS', os.pathsep.join(envs_dirs), reset_context): # with both dirs writable, choose first reset_context((), argparse_args=AttrDict(name='blarg', func='create')) assert context.target_prefix == join(envs_dirs[0], 'blarg') # with first dir read-only, choose second PackageCacheData._cache_.clear() make_read_only(join(envs_dirs[0], '.conda_envs_dir_test')) reset_context((), argparse_args=AttrDict(name='blarg', func='create')) assert context.target_prefix == join(envs_dirs[1], 'blarg') # if first dir is read-only but environment exists, choose first PackageCacheData._cache_.clear() mkdir_p(join(envs_dirs[0], 'blarg')) touch(join(envs_dirs[0], 'blarg', 'history')) reset_context((), argparse_args=AttrDict(name='blarg', func='create')) assert context.target_prefix == join(envs_dirs[0], 'blarg')
def test_print_unexpected_error_message_upload_1(self, post_mock): with env_var('CONDA_REPORT_ERRORS', 'true', stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: ExceptionHandler()(_raise_helper, AssertionError()) assert post_mock.call_count == 2 assert c.stdout == '' assert "conda version" in c.stderr
def test_dry_run_exit(self): with env_var('CONDA_DRY_RUN', 'true', reset_context): from conda.cli.common import confirm_yn with pytest.raises(DryRunExit): confirm_yn() from conda.cli.common import confirm with pytest.raises(DryRunExit): confirm()
def test_prefix_cli_flag(self): envs_dirs = (join(self.prefix, 'first-envs-dir'), join(self.prefix, 'seconds-envs-dir')) with env_var('CONDA_ENVS_DIRS', os.pathsep.join(envs_dirs), conda_tests_ctxt_mgmt_def_pol): # even if prefix doesn't exist, it can be a target prefix reset_context((), argparse_args=AttrDict(prefix='./blarg', func='create')) target_prefix = join(os.getcwd(), 'blarg') assert context.target_prefix == target_prefix assert not isdir(target_prefix)
def test_dry_run_exit(self): with env_var('CONDA_DRY_RUN', 'true', conda_tests_ctxt_mgmt_def_pol): from conda.cli.common import confirm_yn with pytest.raises(DryRunExit): confirm_yn() from conda.cli.common import confirm with pytest.raises(DryRunExit): confirm()
def test_CondaFileNotFoundError(self): filename = "Groot" exc = PathNotFoundError(filename) 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.PathNotFoundError'>" assert json_obj['exception_name'] == 'PathNotFoundError' 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() == "PathNotFoundError: Groot"
def test_CondaRevisionError(self): message = "Potato" exc = CondaRevisionError(message) 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.CondaRevisionError'>" assert json_obj['exception_name'] == 'CondaRevisionError' 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() == "CondaRevisionError: Potato."
def test_CommandNotFoundError_conda_build(self): cmd = "build" exc = CommandNotFoundError(cmd) 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.CommandNotFoundError'>" 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() == ("CommandNotFoundError: To use 'conda build', install conda-build.")
def test_print_unexpected_error_message_opt_out_1(self, input_mock, post_mock): with env_var('CONDA_REPORT_ERRORS', 'false', stack_callback=conda_tests_ctxt_mgmt_def_pol): e = AssertionError() with captured() as c: ExceptionHandler()(_raise_helper, AssertionError()) assert input_mock.call_count == 0 assert post_mock.call_count == 0 assert c.stdout == '' print(c.stderr, file=sys.stderr) assert "conda version" in c.stderr
def test_DirectoryNotFoundError(self): directory = "Groot" exc = DirectoryNotFoundError(directory) with env_var("CONDA_JSON", "yes", reset_context): 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.DirectoryNotFoundError'>" assert json_obj['exception_name'] == 'DirectoryNotFoundError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['path'] == "Groot" with env_var("CONDA_JSON", "no", reset_context): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == "DirectoryNotFoundError: Groot"
def test_CommandNotFoundError_simple(self): cmd = "instate" exc = CommandNotFoundError(cmd) 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.CommandNotFoundError'>" 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() == ("CommandNotFoundError: No command 'conda instate'.\n" "Did you mean 'conda install'?")
def test_init_cmd_exe_registry(self): def _read_windows_registry_mock(target_path, value=None): if not value: value = "yada\\yada\\conda_hook.bat" return 'echo hello & "{}" & echo "world"'.format(value), None from conda.core import initialize orig_read_windows_registry = initialize._read_windows_registry initialize._read_windows_registry = _read_windows_registry_mock orig_join = initialize.join initialize.join = ntpath.join try: target_path = r'HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun' conda_prefix = "c:\\Users\\Lars\\miniconda" with env_var('CONDA_DRY_RUN', 'true', conda_tests_ctxt_mgmt_def_pol): with captured() as c: initialize.init_cmd_exe_registry(target_path, conda_prefix) finally: initialize._read_windows_registry = orig_read_windows_registry initialize.join = orig_join expected = "echo hello & \"c:\\Users\\Lars\\miniconda\\condabin\\conda_hook.bat\" & echo \"world\"" assert c.stdout.strip().splitlines()[-1][1:] == expected # test the reverse (remove the key) initialize._read_windows_registry = lambda x: _read_windows_registry_mock(x, value=join(conda_prefix, 'condabin', 'conda_hook.bat')) initialize.join = ntpath.join try: target_path = r'HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun' conda_prefix = "c:\\Users\\Lars\\miniconda" with env_var('CONDA_DRY_RUN', 'true', conda_tests_ctxt_mgmt_def_pol): with captured() as c: initialize.init_cmd_exe_registry(target_path, conda_prefix, reverse=True) finally: initialize._read_windows_registry = orig_read_windows_registry initialize.join = orig_join expected = "echo hello & echo \"world\"" assert c.stdout.strip().splitlines()[-1][1:] == expected
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_CondaKeyError(self): key = "Potato" message = "Potato is not a key." exc = CondaKeyError(key, message) with env_var("CONDA_JSON", "yes", reset_context): 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.CondaKeyError'>" assert json_obj['exception_name'] == 'CondaKeyError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['key'] == "Potato" with env_var("CONDA_JSON", "no", reset_context): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == "CondaKeyError: 'Potato': Potato is not a key."
def get_index_r_4(subdir=context.subdir): with open(join(dirname(__file__), 'data', 'index4.json')) as fi: packages = json.load(fi) repodata = { "info": { "subdir": subdir, "arch": context.arch_name, "platform": context.platform, }, "packages": packages, } channel = Channel('https://conda.anaconda.org/channel-4/%s' % subdir) sd = SubdirData(channel) with env_var("CONDA_ADD_PIP_AS_PYTHON_DEPENDENCY", "false", reset_context): sd._process_raw_repodata_str(json.dumps(repodata)) sd._loaded = True SubdirData._cache_[channel.url(with_credentials=True)] = sd index = {prec: prec for prec in sd._package_records} r = Resolve(index, channels=(channel, )) return index, r
def test_channel_order_channel_priority_true(self): with env_var("CONDA_PINNED_PACKAGES", "python=3.5", reset_context): with make_temp_env("pycosat==0.6.1") as prefix: assert package_is_installed(prefix, 'python=3.5') assert package_is_installed(prefix, 'pycosat') # add conda-forge channel o, e = run_command(Commands.CONFIG, prefix, "--prepend channels conda-forge", '--json') assert context.channels == ("conda-forge", "defaults"), o + e # update --all update_stdout, _ = run_command(Commands.UPDATE, prefix, '--all') # this assertion works with the pinned_packages config to make sure # conda update --all still respects the pinned python version assert package_is_installed(prefix, 'python=3.5') # pycosat should be in the SUPERSEDED list # after the 4.4 solver work, looks like it's in the DOWNGRADED list # This language needs changed anyway here. # For packages that CHANGE because they're being moved to a higher-priority channel # the message should be # # The following packages will be UPDATED to a higher-priority channel: # installed_str, x = update_stdout.split('UPDATED') updated_str, downgraded_str = x.split('SUPERSEDED') assert 'pycosat' in updated_str # python sys.version should show conda-forge python python_tuple = get_conda_list_tuple(prefix, "python") assert python_tuple[3] == 'conda-forge' # conda list should show pycosat coming from conda-forge pycosat_tuple = get_conda_list_tuple(prefix, "pycosat") assert pycosat_tuple[3] == 'conda-forge'
def test_create_update(self): with make_temp_envs_dir() as envs_dir: with env_var('CONDA_ENVS_DIRS', envs_dir, stack_callback=conda_tests_ctxt_mgmt_def_pol): env_name = str(uuid4())[:8] prefix = join(envs_dir, env_name) python_path = join(prefix, PYTHON_BINARY) run_command(Commands.CREATE, env_name, support_file('example/environment_pinned.yml')) assert exists(python_path) assert package_is_installed(prefix, 'flask=0.12.2') env_vars = get_env_vars(prefix) assert env_vars['FIXED'] == 'fixed' assert env_vars['CHANGES'] == 'original_value' assert env_vars[ 'GETS_DELETED'] == 'not_actually_removed_though' assert env_vars.get('NEW_VAR') is None run_command( Commands.UPDATE, env_name, support_file('example/environment_pinned_updated.yml')) assert package_is_installed(prefix, 'flask=1.0.2') assert not package_is_installed(prefix, 'flask=0.12.2') env_vars = get_env_vars(prefix) assert env_vars['FIXED'] == 'fixed' assert env_vars['CHANGES'] == 'updated_value' assert env_vars['NEW_VAR'] == 'new_var' # This ends up sticking around since there is no real way of knowing that an environment # variable _used_ to be in the variables dict, but isn't any more. assert env_vars[ 'GETS_DELETED'] == 'not_actually_removed_though'
def test_leased_paths(self): with env_var('CONDA_ROOT_PREFIX', self.prefix, reset_context): alamos_env = EnvsDirectory.preferred_env_to_prefix('alamos') lpe_1 = LeasedPathEntry( _path='bin/alamos', target_path=join(alamos_env, 'bin', 'alamos'), target_prefix=alamos_env, leased_path=join(context.root_prefix, 'bin', 'alamos'), package_name='alamos', leased_path_type=LeasedPathType.application_entry_point, ) ed = EnvsDirectory(join(context.root_prefix, 'envs')) ed.add_leased_path(lpe_1) with pytest.raises(CondaError): ed.add_leased_path(lpe_1) lpe_2 = LeasedPathEntry( _path='bin/itsamalbec', target_path=join(alamos_env, 'bin', 'itsamalbec'), target_prefix=alamos_env, leased_path=join(context.root_prefix, 'bin', 'itsamalbec'), package_name='alamos', leased_path_type=LeasedPathType.application_entry_point, ) ed.add_leased_path(lpe_2) assert len(ed.get_leased_path_entries_for_package('alamos')) == 2 assert ed.get_leased_path_entry('bin/itsamalbec') == lpe_2 ed.remove_leased_paths_for_package('alamos') assert len(ed.get_leased_path_entries_for_package('alamos')) == 0 assert ed.get_leased_path_entry('bin/itsamalbec') is None
def test_unexpanded_variables(self): with env_var('EXPANDED_PWD', 'pass44'): channel = Channel('unexpanded') assert channel.auth == 'user1:$UNEXPANDED_PWD'
def test_expanded_variables(self): with env_var('EXPANDED_PWD', 'pass44'): channel = Channel('expanded') assert channel.auth == 'user33:pass44' assert context.channels[0] == 'http://*****:*****@some.url:8080' assert context.whitelist_channels[0] == 'http://*****:*****@some.url:8080'
def test_restore_free_channel(self): assert 'https://repo.anaconda.com/pkgs/free' not in context.default_channels with env_var("CONDA_RESTORE_FREE_CHANNEL", 'true', stack_callback=conda_tests_ctxt_mgmt_def_pol): assert context.default_channels.index('https://repo.anaconda.com/pkgs/free') == 1
def test_subdir_env_var(self): with env_var('CONDA_SUBDIR', 'osx-1012-x84_64', reset_context): channel = Channel('https://conda.anaconda.org/msarahan/osx-1012-x84_64/clangxx_osx-1012-x86_64-10.12-h0bb54af_0.tar.bz2') assert channel.base_url == 'https://conda.anaconda.org/msarahan' assert channel.package_filename == 'clangxx_osx-1012-x86_64-10.12-h0bb54af_0.tar.bz2' assert channel.platform == 'osx-1012-x84_64' # the platform attribute is misnamed here in conda 4.3; conda 4.4 code can correctly use the channel.subdir attribute
def test_windows_sort_orders_2(): # This test makes sure the windows-specific parts of _toposort_prepare_graph # are behaving correctly. with env_var('CONDA_ALLOW_CYCLES', 'false', stack_callback=conda_tests_ctxt_mgmt_def_pol): old_on_win = conda.models.prefix_graph.on_win conda.models.prefix_graph.on_win = False try: records, specs = get_windows_conda_build_record_set() graph = PrefixGraph(records, specs) python_node = graph.get_node_by_name('python') pip_node = graph.get_node_by_name('pip') assert pip_node in graph.graph[python_node] assert python_node in graph.graph[pip_node] nodes = tuple(rec.name for rec in graph.records) pprint(nodes) order = ( 'ca-certificates', 'conda-env', 'vs2015_runtime', 'vc', 'openssl', 'python', 'yaml', 'affine', 'asn1crypto', 'beautifulsoup4', 'certifi', 'chardet', 'colour', 'cryptography-vectors', 'filelock', 'glob2', 'idna', 'markupsafe', 'pkginfo', 'psutil', 'pycosat', 'pycparser', 'pywin32', 'pyyaml', 'ruamel_yaml', 'six', 'spiffy-test-app', 'win_inet_pton', 'wincertstore', 'cffi', 'menuinst', # not on_win, menuinst isn't changed 'pysocks', 'setuptools', 'uses-spiffy-test-app', 'cryptography', 'jinja2', 'wheel', 'pip', # pip always comes after python 'pyopenssl', 'urllib3', 'requests', 'conda', # not on_win, no special treatment for noarch: python packages (affine, colour, spiffy-test-app, uses-spiffy-test-app) 'conda-build', ) assert nodes == order finally: conda.models.prefix_graph.on_win = old_on_win
def test_check_non_admin_enabled_true(): with env_var('CONDA_NON_ADMIN_ENABLED', 'true', reset_context): check_non_admin() assert True
def test_aggressive_update_packages(self): assert context.aggressive_update_packages == tuple() specs = ['certifi', 'openssl>=1.1'] with env_var('CONDA_AGGRESSIVE_UPDATE_PACKAGES', ','.join(specs), stack_callback=conda_tests_ctxt_mgmt_def_pol): assert context.aggressive_update_packages == tuple(MatchSpec(s) for s in specs)
def test_clobber_enum(self): with env_var("CONDA_PATH_CONFLICT", 'prevent', stack_callback=conda_tests_ctxt_mgmt_def_pol): assert context.path_conflict == PathConflict.prevent
def test_dist_with_channel_url(self): # standard named channel url = "https://repo.anaconda.com/pkgs/free/win-64/spyder-app-2.3.8-py27_0.tar.bz2" d = Dist(url) assert d.channel == 'defaults' assert d.name == 'spyder-app' assert d.version == '2.3.8' assert d.build_string == 'py27_0' assert d.to_url() == url assert d.is_channel is True # standard url channel url = "https://not.real.continuum.io/pkgs/free/win-64/spyder-app-2.3.8-py27_0.tar.bz2" d = Dist(url) assert d.channel == 'defaults' # because pkgs/anaconda is in defaults assert d.name == 'spyder-app' assert d.version == '2.3.8' assert d.build_string == 'py27_0' assert d.to_url() == url assert d.is_channel is True # another standard url channel url = "https://not.real.continuum.io/not/anaconda/win-64/spyder-app-2.3.8-py27_0.tar.bz2" d = Dist(url) assert d.channel == 'https://not.real.continuum.io/not/anaconda' assert d.name == 'spyder-app' assert d.version == '2.3.8' assert d.build_string == 'py27_0' assert d.to_url() == url assert d.is_channel is True # local file url that is a named channel conda_bld_path = join(gettempdir(), 'conda-bld') try: mkdir_p(conda_bld_path) with env_var('CONDA_BLD_PATH', conda_bld_path, reset_context): url = path_to_url( join_url(context.croot, 'osx-64', 'bcrypt-3.1.1-py35_2.tar.bz2')) d = Dist(url) assert d.channel == 'local' assert d.name == 'bcrypt' assert d.version == '3.1.1' assert d.build_string == 'py35_2' assert d.to_url() == url assert d.is_channel is True finally: rm_rf(conda_bld_path) # local file url that is not a named channel url = join_url('file:///some/location/on/disk', 'osx-64', 'bcrypt-3.1.1-py35_2.tar.bz2') d = Dist(url) assert d.channel == 'file:///some/location/on/disk' assert d.name == 'bcrypt' assert d.version == '3.1.1' assert d.build_string == 'py35_2' assert d.to_url() == url assert d.is_channel is True
def test_always_yes(self): with env_var('CONDA_ALWAYS_YES', 'true', reset_context): with env_var('CONDA_DRY_RUN', 'false', reset_context): from conda.cli.common import confirm_yn choice = confirm_yn() assert choice is True
def test_clobber_enum(self): with env_var("CONDA_PATH_CONFLICT", 'prevent', reset_context): assert context.path_conflict == PathConflict.prevent
def test_sort_without_prep(): # Test the _toposort_prepare_graph method, here by not running it at all. # The method is invoked in every other test. This is what happens when it's not invoked. with patch.object(conda.models.prefix_graph.PrefixGraph, '_toposort_prepare_graph', return_value=None): records, specs = get_windows_conda_build_record_set() graph = PrefixGraph(records, specs) python_node = graph.get_node_by_name('python') pip_node = graph.get_node_by_name('pip') assert pip_node in graph.graph[python_node] assert python_node in graph.graph[pip_node] nodes = tuple(rec.dist_str() for rec in graph.records) print(nodes) order = ( 'channel-5::ca-certificates-2017.08.26-h94faf87_0', 'channel-5::conda-env-2.6.0-h36134e3_1', 'channel-5::vs2015_runtime-14.0.25123-3', 'channel-5::vc-14-h0510ff6_3', 'channel-5::openssl-1.0.2n-h74b6da3_0', 'channel-5::yaml-0.1.7-hc54c509_2', 'channel-5::affine-2.1.0-pyh128a3a6_1', 'channel-5::asn1crypto-0.24.0-py36_0', 'channel-5::beautifulsoup4-4.6.0-py36hd4cc5e8_1', 'channel-5::certifi-2018.1.18-py36_0', 'channel-5::chardet-3.0.4-py36h420ce6e_1', 'channel-5::colour-0.1.4-pyhd67b51d_0', 'channel-5::filelock-3.0.4-py36_0', 'channel-5::glob2-0.6-py36hdf76b57_0', 'channel-5::idna-2.6-py36h148d497_1', 'channel-5::markupsafe-1.0-py36h0e26971_1', 'channel-5::pkginfo-1.4.1-py36hb0f9cfa_1', 'channel-5::psutil-5.4.3-py36hfa6e2cd_0', 'channel-5::pycosat-0.6.3-py36h413d8a4_0', 'channel-5::pycparser-2.18-py36hd053e01_1', 'channel-5::cffi-1.11.4-py36hfa6e2cd_0', 'channel-5::python-3.6.4-h6538335_1', 'channel-5::pywin32-222-py36hfa6e2cd_0', 'channel-5::pyyaml-3.12-py36h1d1928f_1', 'channel-5::ruamel_yaml-0.15.35-py36hfa6e2cd_1', 'channel-5::six-1.11.0-py36h4db2310_1', 'channel-5::spiffy-test-app-0.5-pyh6afbcc8_0', 'channel-5::win_inet_pton-1.0.1-py36he67d7fd_1', 'channel-5::wincertstore-0.2-py36h7fe50ca_0', 'channel-5::conda-verify-2.0.0-py36h065de53_0', 'channel-5::cryptography-2.1.4-py36he1d7878_0', 'channel-5::menuinst-1.4.11-py36hfa6e2cd_0', 'channel-5::pysocks-1.6.8-py36_0', 'channel-5::setuptools-38.5.1-py36_0', 'channel-5::uses-spiffy-test-app-2.0-pyh18698f2_0', 'channel-5::jinja2-2.10-py36h292fed1_0', 'channel-5::pyopenssl-17.5.0-py36h5b7d817_0', 'channel-5::wheel-0.30.0-py36h6c3ec14_1', 'channel-5::pip-9.0.1-py36h226ae91_4', 'channel-5::urllib3-1.22-py36h276f60a_0', 'channel-5::requests-2.18.4-py36h4371aae_1', 'channel-5::conda-4.4.11-py36_0', 'channel-5::conda-build-3.5.1-py36_0', ) assert nodes == order with env_var('CONDA_ALLOW_CYCLES', 'false', reset_context): records, specs = get_windows_conda_build_record_set() with pytest.raises(CyclicalDependencyError): graph = PrefixGraph(records, specs)
def test_subdirs(self): assert context.subdirs == (context.subdir, 'noarch') subdirs = ('linux-highest', 'linux-64', 'noarch') with env_var('CONDA_SUBDIRS', ','.join(subdirs), stack_callback=conda_tests_ctxt_mgmt_def_pol): assert context.subdirs == subdirs
def test_cuda_override_none(self): with env_var('CONDA_OVERRIDE_CUDA', ''): version = context.cuda_version assert version is None
def test_windows_sort_orders_2(): # This test makes sure the windows-specific parts of _toposort_prepare_graph # are behaving correctly. with env_var('CONDA_ALLOW_CYCLES', 'false', reset_context): old_on_win = conda.models.prefix_graph.on_win conda.models.prefix_graph.on_win = False try: records, specs = get_windows_conda_build_record_set() graph = PrefixGraph(records, specs) python_node = graph.get_node_by_name('python') pip_node = graph.get_node_by_name('pip') assert pip_node in graph.graph[python_node] assert python_node in graph.graph[pip_node] nodes = tuple(rec.dist_str() for rec in graph.records) print(nodes) order = ( 'channel-5::ca-certificates-2017.08.26-h94faf87_0', 'channel-5::conda-env-2.6.0-h36134e3_1', 'channel-5::vs2015_runtime-14.0.25123-3', 'channel-5::vc-14-h0510ff6_3', 'channel-5::openssl-1.0.2n-h74b6da3_0', 'channel-5::python-3.6.4-h6538335_1', 'channel-5::yaml-0.1.7-hc54c509_2', 'channel-5::affine-2.1.0-pyh128a3a6_1', 'channel-5::asn1crypto-0.24.0-py36_0', 'channel-5::beautifulsoup4-4.6.0-py36hd4cc5e8_1', 'channel-5::certifi-2018.1.18-py36_0', 'channel-5::chardet-3.0.4-py36h420ce6e_1', 'channel-5::colour-0.1.4-pyhd67b51d_0', 'channel-5::filelock-3.0.4-py36_0', 'channel-5::glob2-0.6-py36hdf76b57_0', 'channel-5::idna-2.6-py36h148d497_1', 'channel-5::markupsafe-1.0-py36h0e26971_1', 'channel-5::pkginfo-1.4.1-py36hb0f9cfa_1', 'channel-5::psutil-5.4.3-py36hfa6e2cd_0', 'channel-5::pycosat-0.6.3-py36h413d8a4_0', 'channel-5::pycparser-2.18-py36hd053e01_1', 'channel-5::pywin32-222-py36hfa6e2cd_0', 'channel-5::pyyaml-3.12-py36h1d1928f_1', 'channel-5::ruamel_yaml-0.15.35-py36hfa6e2cd_1', 'channel-5::six-1.11.0-py36h4db2310_1', 'channel-5::spiffy-test-app-0.5-pyh6afbcc8_0', 'channel-5::win_inet_pton-1.0.1-py36he67d7fd_1', 'channel-5::wincertstore-0.2-py36h7fe50ca_0', 'channel-5::cffi-1.11.4-py36hfa6e2cd_0', 'channel-5::conda-verify-2.0.0-py36h065de53_0', 'channel-5::menuinst-1.4.11-py36hfa6e2cd_0', # not on_win, menuinst isn't changed 'channel-5::pysocks-1.6.8-py36_0', 'channel-5::setuptools-38.5.1-py36_0', 'channel-5::uses-spiffy-test-app-2.0-pyh18698f2_0', 'channel-5::cryptography-2.1.4-py36he1d7878_0', 'channel-5::jinja2-2.10-py36h292fed1_0', 'channel-5::wheel-0.30.0-py36h6c3ec14_1', 'channel-5::pip-9.0.1-py36h226ae91_4', # pip always comes after python 'channel-5::pyopenssl-17.5.0-py36h5b7d817_0', 'channel-5::urllib3-1.22-py36h276f60a_0', 'channel-5::requests-2.18.4-py36h4371aae_1', 'channel-5::conda-4.4.11-py36_0', # not on_win, no special treatment for noarch: python packages (affine, colour, spiffy-test-app, uses-spiffy-test-app) 'channel-5::conda-build-3.5.1-py36_0', ) assert nodes == order finally: conda.models.prefix_graph.on_win = old_on_win
def test_sort_without_prep(): # Test the _toposort_prepare_graph method, here by not running it at all. # The method is invoked in every other test. This is what happens when it's not invoked. with patch.object(conda.models.prefix_graph.PrefixGraph, '_toposort_prepare_graph', return_value=None): records, specs = get_windows_conda_build_record_set() graph = PrefixGraph(records, specs) python_node = graph.get_node_by_name('python') pip_node = graph.get_node_by_name('pip') assert pip_node in graph.graph[python_node] assert python_node in graph.graph[pip_node] nodes = tuple(rec.name for rec in graph.records) pprint(nodes) order = ( 'ca-certificates', 'conda-env', 'vs2015_runtime', 'vc', 'openssl', 'yaml', 'affine', 'asn1crypto', 'beautifulsoup4', 'certifi', 'chardet', 'colour', 'cryptography-vectors', 'filelock', 'glob2', 'idna', 'markupsafe', 'pkginfo', 'psutil', 'pycosat', 'pycparser', 'cffi', 'python', 'pywin32', 'pyyaml', 'ruamel_yaml', 'six', 'spiffy-test-app', 'win_inet_pton', 'wincertstore', 'cryptography', 'menuinst', 'pysocks', 'setuptools', 'uses-spiffy-test-app', 'jinja2', 'pyopenssl', 'wheel', 'pip', 'urllib3', 'requests', 'conda', 'conda-build', ) assert nodes == order with env_var('CONDA_ALLOW_CYCLES', 'false', stack_callback=conda_tests_ctxt_mgmt_def_pol): records, specs = get_windows_conda_build_record_set() with pytest.raises(CyclicalDependencyError): graph = PrefixGraph(records, specs)
def get_index_must_unfreeze(subdir=context.subdir): repodata = { "info": { "subdir": subdir, "arch": context.arch_name, "platform": context.platform, }, "packages": { "foobar-1.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": ["libbar 2.0.*", "libfoo 1.0.*"], "md5": "11ec1194bcc56b9a53c127142a272772", "name": "foobar", "timestamp": 1562861325613, "version": "1.0" }, "foobar-2.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": ["libbar 2.0.*", "libfoo 2.0.*"], "md5": "f8eb5a7fa1ff6dead4e360631a6cd048", "name": "foobar", "version": "2.0" }, "libbar-1.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": [], "md5": "f51f4d48a541b7105b5e343704114f0f", "name": "libbar", "timestamp": 1562858881022, "version": "1.0" }, "libbar-2.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": [], "md5": "27f4e717ed263f909074f64d9cbf935d", "name": "libbar", "timestamp": 1562858881748, "version": "2.0" }, "libfoo-1.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": [], "md5": "ad7c088566ffe2389958daedf8ff312c", "name": "libfoo", "timestamp": 1562858763881, "version": "1.0" }, "libfoo-2.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": [], "md5": "daf7af7086d8f22be49ae11bdc41f332", "name": "libfoo", "timestamp": 1562858836924, "version": "2.0" }, "qux-1.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": ["libbar 2.0.*", "libfoo 1.0.*"], "md5": "18604cbe4f789fe853232eef4babd4f9", "name": "qux", "timestamp": 1562861393808, "version": "1.0" }, "qux-2.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": ["libbar 1.0.*", "libfoo 2.0.*"], "md5": "892aa4b9ec64b67045a46866ef1ea488", "name": "qux", "timestamp": 1562861394828, "version": "2.0" } } } channel = Channel('https://conda.anaconda.org/channel-freeze/%s' % subdir) sd = SubdirData(channel) with env_var("CONDA_ADD_PIP_AS_PYTHON_DEPENDENCY", "false", stack_callback=conda_tests_ctxt_mgmt_def_pol): sd._process_raw_repodata_str(json.dumps(repodata)) sd._loaded = True SubdirData._cache_[channel.url(with_credentials=True)] = sd index = {prec: prec for prec in sd._package_records} r = Resolve(index, channels=(channel, )) return index, r
def test_check_non_admin_enabled_true(): with env_var('CONDA_NON_ADMIN_ENABLED', 'true', stack_callback=conda_tests_ctxt_mgmt_def_pol): check_non_admin() assert True
def test_subdirs(self): assert context.subdirs == (context.subdir, 'noarch') subdirs = ('linux-highest', 'linux-64', 'noarch') with env_var('CONDA_SUBDIRS', ','.join(subdirs), reset_context): assert context.subdirs == subdirs