Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'] == ""
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:
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
def test_create_advanced_pip(self):
with make_temp_envs_dir() as envs_dir:
with env_var('CONDA_ENVS_DIRS', envs_dir, reset_context):
env_name = str(uuid4())[:8]
prefix = join(envs_dir, env_name)
python_path = join(prefix, PYTHON_BINARY)
run_command(Commands.CREATE, env_name,
utils.support_file('advanced-pip/environment.yml'))
assert exists(python_path)
assert_package_is_installed(prefix, 'argh', exact=False, pip=True)
assert_package_is_installed(prefix, 'module-to-install-in-editable-mode', exact=False, pip=True)
try:
assert_package_is_installed(prefix, 'six', exact=False, pip=True)
except AssertionError:
# six may now be conda-installed because of packaging changes
assert_package_is_installed(prefix, 'six', exact=False, pip=False)
assert_package_is_installed(prefix, 'xmltodict-0.10.2-', exact=True, pip=True)
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), stack_callback=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_pinned_specs():
# Test pinned specs environment variable
specs_str_1 = ("numpy 1.11", "python >3")
specs_1 = tuple(MatchSpec(spec_str, optional=True) for spec_str in specs_str_1)
with env_var('CONDA_PINNED_PACKAGES', '&'.join(specs_str_1), reset_context):
pinned_specs = get_pinned_specs("/none")
assert pinned_specs == specs_1
assert pinned_specs != specs_str_1
# Test pinned specs conda environment file
specs_str_2 = ("scipy ==0.14.2", "openjdk >=8")
specs_2 = tuple(MatchSpec(spec_str, optional=True) for spec_str in specs_str_2)
with tempdir() as td:
mkdir_p(join(td, 'conda-meta'))
with open(join(td, 'conda-meta', 'pinned'), 'w') as fh:
fh.write("\n".join(specs_str_2))
fh.write("\n")
pinned_specs = get_pinned_specs(td)
assert pinned_specs == specs_2
assert pinned_specs != specs_str_2
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:
conda_exception_handler(_raise_helper, exc)
json_obj = json.loads(c.stdout)
assert not c.stderr
assert json_obj['exception_type'] == ""
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:
def test_simple_install_uninstall(self, prefix_specified):
prefix_specified.__get__ = Mock(return_value=False)
# >> simple progression install then uninstall <<
run_command(Commands.INSTALL, self.prefix, "-c conda-test spiffy-test-app")
assert not package_is_installed(self.prefix, "spiffy-test-app")
assert isfile(self.exe_file(self.prefix, 'spiffy-test-app'))
assert package_is_installed(self.preferred_env_prefix, "spiffy-test-app")
with env_var('YABBA-DABBA', 'doo'):
stdout, stderr, rc = subprocess_call(self.exe_file(self.prefix, 'spiffy-test-app'))
assert not stderr
assert rc == 0
json_d = json.loads(stdout)
assert json_d['YABBA-DABBA'] == 'doo'
run_command(Commands.INSTALL, self.prefix, "-c conda-test uses-spiffy-test-app")
assert not package_is_installed(self.prefix, "uses-spiffy-test-app")
assert package_is_installed(self.preferred_env_prefix, "uses-spiffy-test-app")
run_command(Commands.REMOVE, self.prefix, "uses-spiffy-test-app")
assert not package_is_installed(self.preferred_env_prefix, "uses-spiffy-test-app")
run_command(Commands.REMOVE, self.prefix, "spiffy-test-app")
assert not package_is_installed(self.prefix, "spiffy-test-app")
assert not isfile(self.exe_file(self.prefix, 'spiffy-test-app'))
def test_dont_remove_conda_2(self):
# regression test for #6904
pkgs_dirs = context.pkgs_dirs
prefix = make_temp_prefix()
with env_var('CONDA_ROOT_PREFIX', prefix, reset_context):
with env_var('CONDA_PKGS_DIRS', ','.join(pkgs_dirs), reset_context):
with make_temp_env(prefix=prefix):
stdout, stderr = run_command(Commands.INSTALL, prefix, "conda")
assert package_is_installed(prefix, "conda")
assert package_is_installed(prefix, "pycosat")
with pytest.raises(CondaMultiError) as exc:
run_command(Commands.REMOVE, prefix, 'pycosat')
assert any(isinstance(e, RemoveError) for e in exc.value.errors)
assert package_is_installed(prefix, "conda")
assert package_is_installed(prefix, "pycosat")
with pytest.raises(CondaMultiError) as exc:
run_command(Commands.REMOVE, prefix, 'conda')
assert any(isinstance(e, RemoveError) for e in exc.value.errors)
def get_index_cuda(subdir=context.subdir):
with open(join(dirname(__file__), 'data', 'index.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-1/%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}
add_feature_records_legacy(index)
r = Resolve(index, channels=(channel,))
return index, r
def test_dont_remove_conda_2(self):
# regression test for #6904
pkgs_dirs = context.pkgs_dirs
prefix = make_temp_prefix()
with env_var('CONDA_ROOT_PREFIX', prefix, reset_context):
with env_var('CONDA_PKGS_DIRS', ','.join(pkgs_dirs), reset_context):
with make_temp_env(prefix=prefix):
stdout, stderr = run_command(Commands.INSTALL, prefix, "conda")
assert package_is_installed(prefix, "conda")
assert package_is_installed(prefix, "pycosat")
with pytest.raises(CondaMultiError) as exc:
run_command(Commands.REMOVE, prefix, 'pycosat')
assert any(isinstance(e, RemoveError) for e in exc.value.errors)
assert package_is_installed(prefix, "conda")
assert package_is_installed(prefix, "pycosat")
with pytest.raises(CondaMultiError) as exc:
run_command(Commands.REMOVE, prefix, 'conda')
def test_CondaFileNotFoundError(self):
filename = "Groot"
exc = PathNotFoundError(filename)
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'] == ""
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", reset_context):
with captured() as c:
conda_exception_handler(_raise_helper, exc)
assert not c.stdout
assert c.stderr.strip() == "PathNotFoundError: Groot"