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_CondaHTTPError(self): msg = "Potato" url = "https://download.url/path/to/Potato.tar.gz" status_code = "Potato" reason = "COULD NOT CONNECT" elapsed_time = 1.24 exc = CondaHTTPError(msg, url, status_code, reason, elapsed_time) with env_var("CONDA_JSON", "yes", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) json_obj = json.loads(c.stdout) assert not c.stderr assert json_obj['exception_type'] == "<class 'conda.exceptions.CondaHTTPError'>" assert json_obj['exception_name'] == 'CondaHTTPError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['url'] == url assert json_obj['status_code'] == status_code assert json_obj['reason'] == reason assert json_obj['elapsed_time'] == elapsed_time with env_var("CONDA_JSON", "no", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert dals(""" CondaHTTPError: HTTP Potato COULD NOT CONNECT for url <https://download.url/path/to/Potato.tar.gz> Elapsed: 1.24 Potato """).strip() in c.stderr.strip()
def test_MD5MismatchError(self): url = "https://download.url/path/to/file.tar.bz2" target_full_path = "/some/path/on/disk/another-name.tar.bz2" expected_md5sum = "abc123" actual_md5sum = "deadbeef" exc = 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_CondaKeyError(self): key = "Potato" message = "Potato is not a key." exc = CondaKeyError(key, 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.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", 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( ) == "CondaKeyError: 'Potato': Potato is not a key."
def test_TooFewArgumentsError(self): expected = 5 received = 2 exc = TooFewArgumentsError(expected, received) 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.TooFewArgumentsError'>" assert json_obj['exception_name'] == 'TooFewArgumentsError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['expected'] == 5 assert json_obj['received'] == 2 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( ) == "TooFewArgumentsError: Too few arguments: Got 2 arguments but expected 5."
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_CommandNotFoundError_activate(self): cmd = "activate" exc = CommandNotFoundError(cmd) 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.CommandNotFoundError'>" 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, replace_log_streams(): conda_exception_handler(_raise_helper, exc) assert not c.stdout if on_win: message = "CommandNotFoundError: Conda could not find the command: 'activate'" else: message = ( "CommandNotFoundError: 'activate is not a conda command.\n" "Did you mean 'source activate'?") assert c.stderr.strip() == message
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_TooManyArgumentsError(self): expected = 2 received = 5 offending_arguments = "groot" exc = TooManyArgumentsError(expected, received, offending_arguments) 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.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", reset_context): with captured() as c, replace_log_streams(): conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip( ) == "TooManyArgumentsError: Too many arguments: Got 5 arguments (g, r, o, o, t) but expected 2."
def test_TooFewArgumentsError(self): expected = 5 received = 2 exc = TooFewArgumentsError(expected, received) 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.TooFewArgumentsError'>" assert json_obj['exception_name'] == 'TooFewArgumentsError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['expected'] == 5 assert json_obj['received'] == 2 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( ) == "TooFewArgumentsError: Got 2 arguments but expected 5."
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 test_key_value_features_match(self): dst = Dist('defaults::foo-1.2.3-4.tar.bz2') a = MatchSpec(features='test') assert text_type(a) == "*[provides_features='test=true']" assert not a.match(DPkg(dst)) assert not a.match(DPkg(dst, track_features='')) assert a.match(DPkg(dst, track_features='test')) assert not a.match(DPkg(dst, track_features='test2')) assert a.match(DPkg(dst, track_features='test me')) assert a.match(DPkg(dst, track_features='you test')) assert a.match(DPkg(dst, track_features='you test me')) assert a.get_exact_value('provides_features') == frozendict({'test': 'true'}) b = MatchSpec(features='mkl') assert not b.match(DPkg(dst)) assert b.match(DPkg(dst, track_features='mkl')) assert b.match(DPkg(dst, track_features='blas=mkl')) assert b.match(DPkg(dst, track_features='blas=mkl debug')) assert not b.match(DPkg(dst, track_features='debug')) c = MatchSpec(features='nomkl') assert not c.match(DPkg(dst)) assert not c.match(DPkg(dst, track_features='mkl')) assert c.match(DPkg(dst, track_features='nomkl')) assert c.match(DPkg(dst, track_features='blas=nomkl debug'))
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_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_DirectoryNotFoundError(self): directory = "Groot" exc = DirectoryNotFoundError(directory) 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.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", 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() == "DirectoryNotFoundError: Groot"
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_matchspec_errors(self): with pytest.raises(ValueError): MatchSpec('blas [optional') with pytest.raises(ValueError): MatchSpec('blas [test=]') with pytest.raises(ValueError): MatchSpec('blas[invalid="1"]') if not on_win: # skipping on Windows for now. don't feel like dealing with the windows url path crud assert text_type(MatchSpec("/some/file/on/disk/package-1.2.3-2.tar.bz2")) == '*[url=file:///some/file/on/disk/package-1.2.3-2.tar.bz2]'
def test_BinaryPrefixReplacementError(self): new_data_length = 1104 original_data_length = 1404 new_prefix = "some/where/on/goodwin.ave" path = "some/where/by/boneyard/creek" placeholder = "save/my/spot/in/374" exc = BinaryPrefixReplacementError(path, placeholder, new_prefix, original_data_length, new_data_length) with env_var("CONDA_JSON", "yes", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) json_obj = json.loads(c.stdout) assert not c.stderr assert json_obj[ 'exception_type'] == "<class 'conda.exceptions.BinaryPrefixReplacementError'>" assert json_obj['exception_name'] == 'BinaryPrefixReplacementError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['new_data_length'] == 1104 assert json_obj['original_data_length'] == 1404 assert json_obj['new_prefix'] == new_prefix assert json_obj['path'] == path assert json_obj['placeholder'] == placeholder with env_var("CONDA_JSON", "no", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" BinaryPrefixReplacementError: Refusing to replace mismatched data length in binary file. path: some/where/by/boneyard/creek placeholder: save/my/spot/in/374 new prefix: some/where/on/goodwin.ave original data Length: 1404 new data length: 1104 """).strip()
def test_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'] == "<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", reset_context): 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_CondaRevisionError(self): message = "Potato" exc = CondaRevisionError(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.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", reset_context): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == "CondaRevisionError: Potato."
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_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_CommandNotFoundError_simple(self): cmd = "instate" exc = CommandNotFoundError(cmd) 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.CommandNotFoundError'>" 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() == "CommandNotFoundError: 'instate'"
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 PackageNotFoundError(self): package = "Groot" exc = PackageNotFoundError(package) 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.PackageNotFoundError'>" assert json_obj['message'] == text_type(exc) assert json_obj['package_name'] == package assert json_obj['error'] == repr(exc) 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( ) == "Package not found: Conda could not find Groot"
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_CommandNotFoundError_conda_build(self): cmd = "build" exc = CommandNotFoundError(cmd) 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.CommandNotFoundError'>" 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, replace_log_streams(): conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == ("CommandNotFoundError: You need to install conda-build in order to\n" \ "use the 'conda build' command.")
def test_DirectoryNotFoundError(self): directory = "Groot" exc = DirectoryNotFoundError(directory) 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.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, replace_log_streams(): conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == "DirectoryNotFoundError: Groot"
def test_TooFewArgumentsError(self): expected = 5 received = 2 exc = TooFewArgumentsError(expected, received) 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.TooFewArgumentsError'>" assert json_obj['exception_name'] == 'TooFewArgumentsError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['expected'] == 5 assert json_obj['received'] == 2 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() == "TooFewArgumentsError: Got 2 arguments but expected 5."
def test_track_features_match(self): dst = Dist('defaults::foo-1.2.3-4.tar.bz2') a = MatchSpec(features='test') assert text_type(a) == "*[features=test]" assert not a.match(DPkg(dst)) assert not a.match(DPkg(dst, track_features='')) a = MatchSpec(track_features='test') assert a.match(DPkg(dst, track_features='test')) assert not a.match(DPkg(dst, track_features='test2')) assert not a.match(DPkg(dst, track_features='test me')) assert not a.match(DPkg(dst, track_features='you test')) assert not a.match(DPkg(dst, track_features='you test me')) assert a.get_exact_value('track_features') == frozenset(('test', )) b = MatchSpec(track_features='mkl') assert not b.match(DPkg(dst)) assert b.match(DPkg(dst, track_features='mkl')) assert b.match(DPkg(dst, track_features='mkl')) assert not b.match(DPkg(dst, track_features='mkl debug')) assert not b.match(DPkg(dst, track_features='debug')) c = MatchSpec(track_features='nomkl') assert not c.match(DPkg(dst)) assert not c.match(DPkg(dst, track_features='mkl')) assert c.match(DPkg(dst, track_features='nomkl')) assert not c.match(DPkg(dst, track_features='nomkl debug')) # regression test for #6860 d = MatchSpec(track_features='') assert d.get_exact_value('track_features') == frozenset() d = MatchSpec(track_features=' ') assert d.get_exact_value('track_features') == frozenset() d = MatchSpec(track_features=('', '')) assert d.get_exact_value('track_features') == frozenset() d = MatchSpec(track_features=('', '', 'test')) assert d.get_exact_value('track_features') == frozenset(('test', ))
def test_track_features_match(self): dst = Dist('defaults::foo-1.2.3-4.tar.bz2') a = MatchSpec(features='test') assert text_type(a) == "*[features=test]" assert not a.match(DPkg(dst)) assert not a.match(DPkg(dst, track_features='')) a = MatchSpec(track_features='test') assert a.match(DPkg(dst, track_features='test')) assert not a.match(DPkg(dst, track_features='test2')) assert not a.match(DPkg(dst, track_features='test me')) assert not a.match(DPkg(dst, track_features='you test')) assert not a.match(DPkg(dst, track_features='you test me')) assert a.get_exact_value('track_features') == frozenset(('test',)) b = MatchSpec(track_features='mkl') assert not b.match(DPkg(dst)) assert b.match(DPkg(dst, track_features='mkl')) assert b.match(DPkg(dst, track_features='mkl')) assert not b.match(DPkg(dst, track_features='mkl debug')) assert not b.match(DPkg(dst, track_features='debug')) c = MatchSpec(track_features='nomkl') assert not c.match(DPkg(dst)) assert not c.match(DPkg(dst, track_features='mkl')) assert c.match(DPkg(dst, track_features='nomkl')) assert not c.match(DPkg(dst, track_features='nomkl debug')) # regression test for #6860 d = MatchSpec(track_features='') assert d.get_exact_value('track_features') == frozenset() d = MatchSpec(track_features=' ') assert d.get_exact_value('track_features') == frozenset() d = MatchSpec(track_features=('', '')) assert d.get_exact_value('track_features') == frozenset() d = MatchSpec(track_features=('', '', 'test')) assert d.get_exact_value('track_features') == frozenset(('test',))
def test_BinaryPrefixReplacementError(self): new_data_length = 1104 original_data_length = 1404 new_prefix = "some/where/on/goodwin.ave" path = "some/where/by/boneyard/creek" placeholder = "save/my/spot/in/374" exc = BinaryPrefixReplacementError(path, placeholder, new_prefix, original_data_length, new_data_length) with env_var("CONDA_JSON", "yes", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) json_obj = json.loads(c.stdout) assert not c.stderr assert json_obj['exception_type'] == "<class 'conda.exceptions.BinaryPrefixReplacementError'>" assert json_obj['exception_name'] == 'BinaryPrefixReplacementError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['new_data_length'] == 1104 assert json_obj['original_data_length'] == 1404 assert json_obj['new_prefix'] == new_prefix assert json_obj['path'] == path assert json_obj['placeholder'] == placeholder with env_var("CONDA_JSON", "no", stack_callback=conda_tests_ctxt_mgmt_def_pol): with captured() as c: conda_exception_handler(_raise_helper, exc) assert not c.stdout assert c.stderr.strip() == dals(""" BinaryPrefixReplacementError: Refusing to replace mismatched data length in binary file. path: some/where/by/boneyard/creek placeholder: save/my/spot/in/374 new prefix: some/where/on/goodwin.ave original data Length: 1404 new data length: 1104 """).strip()
def test_CondaKeyError(self): key = "Groot" message = "Groot is not a key." exc = CondaKeyError(key, message) 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.CondaKeyError'>" assert json_obj['exception_name'] == 'CondaKeyError' assert json_obj['message'] == text_type(exc) assert json_obj['error'] == repr(exc) assert json_obj['key'] == "Groot" 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( ) == "CondaKeyError: Error with key 'Groot': Groot is not a key."
def main(): from conda.base.context import context from conda.base.constants import ROOT_ENV_NAME from conda.utils import shells # possible cases: # > conda ..activate <SHELL> <ENV> # > conda ..checkenv <SHELL> <ENV> # > conda ..changeps1 received = len(sys.argv) if received >= 2: mode = sys.argv[1].strip() if received >= 3: shell = sys.argv[2].strip() if received >= 4: env = sys.argv[3].strip() if '-h' in sys.argv or '--help' in sys.argv: # all unknown values will be listed after the -h/--help flag try: i = sys.argv.index("-h") except ValueError: i = sys.argv.index("--help") unknown = list(map(lambda s: s.strip(), sys.argv[i+1:])) help(mode, shell, unknown) # note: will never return from the help method if mode == '..activate': # conda ..activate <SHELL> <ENV> # don't count conda and ..activate received -= 2 if received != 2: expected = 2 offset = sys.argv[2:] opt_msg = "..activate expected exactly two arguments: SHELL and ENV" if received < 2: raise TooFewArgumentsError(expected, received, opt_msg) if received > 2: raise TooManyArgumentsError(expected, received, offset, opt_msg) binpath = binpath_from_arg(sys.argv[3], shelldict=shells[shell]) # prepend our new entries onto the existing path and make sure that # the separator is native path = shells[shell]['path_delim'].join(binpath) # deactivation is handled completely in shell scripts - it restores backups # of env variables it is done in shell scripts because they handle state # much better than we can here elif mode == '..checkenv': # conda ..checkenv <SHELL> <ENV> # dont't count conda and ..checkenv received -= 2 if received != 2: expected = 2 offset = sys.argv[2:] opt_msg = "..checkenv expected exactly two arguments: SHELL and ENV" if received < 2: raise TooFewArgumentsError(expected, received, opt_msg) if received > 2: raise TooManyArgumentsError(expected, received, offset, opt_msg) if env.lower() == ROOT_ENV_NAME.lower(): # no need to check root env and try to install a symlink there sys.exit(0) # raise CondaSystemExit # this should throw an error and exit if the env or path can't be found. try: prefix = prefix_from_arg(env, shelldict=shells[shell]) except ValueError as e: raise CondaValueError(text_type(e)) # Make sure an env always has the conda symlink try: import conda.install conda.install.symlink_conda(prefix, context.root_dir, shell) except (IOError, OSError) as e: if e.errno == errno.EPERM or e.errno == errno.EACCES: raise CondaEnvironmentError(dedent("""\ Cannot activate environment {env} User does not have write access for conda symlinks """).format(env=env)) raise sys.exit(0) # raise CondaSystemExit elif mode == '..changeps1': from conda.base.context import context path = int(context.changeps1) else: # This means there is a bug in main.py raise CondaValueError("unexpected command") # This print is actually what sets the PATH or PROMPT variable. The shell # script gets this value, and finishes the job. # # Must use sys.stdout.write(str(path)) to properly write to the console # cross platform, print(path) incorrectly prints integers on Windows sys.stdout.write(str(path))
def test_legacy_features_canonical_string_forms(self): assert m("mkl@") == "*[track_features=mkl]" # assert m("@mkl") == "*[features=mkl]" assert text_type(MatchSpec(features="mkl")) == "*[features=mkl]"
def m(string): return text_type(MatchSpec(string))
def main(): from conda.base.context import context from conda.base.constants import ROOT_ENV_NAME from conda.utils import shells if '-h' in sys.argv or '--help' in sys.argv: # all execution paths sys.exit at end. help(sys.argv[1], sys.argv[2]) if len(sys.argv) > 2: shell = sys.argv[2] shelldict = shells[shell] if sys.argv[1] == '..activate': arg_num = len(sys.argv) if arg_num != 4: num_expected = 2 if arg_num < 4: raise TooFewArgumentsError( num_expected, arg_num - num_expected, "..activate expected exactly two arguments:\ shell and env name") if arg_num > 4: raise TooManyArgumentsError( num_expected, arg_num - num_expected, sys.argv[2:], "..activate expected exactly two arguments:\ shell and env name") binpath = binpath_from_arg(sys.argv[3], shelldict=shelldict) # prepend our new entries onto the existing path and make sure that the separator is native path = shelldict['pathsep'].join(binpath) # deactivation is handled completely in shell scripts - it restores backups of env variables. # It is done in shell scripts because they handle state much better than we can here. elif sys.argv[1] == '..checkenv': if len(sys.argv) < 4: raise ArgumentError( "Invalid arguments to checkenv. Need shell and env name/path") if len(sys.argv) > 4: raise ArgumentError("did not expect more than one argument.") if sys.argv[3].lower() == ROOT_ENV_NAME.lower(): # no need to check root env and try to install a symlink there sys.exit(0) # raise CondaSystemExit # this should throw an error and exit if the env or path can't be found. try: prefix = prefix_from_arg(sys.argv[3], shelldict=shelldict) except ValueError as e: raise CondaValueError(text_type(e)) # Make sure an env always has the conda symlink try: import conda.install conda.install.symlink_conda(prefix, context.root_dir, shell) except (IOError, OSError) as e: if e.errno == errno.EPERM or e.errno == errno.EACCES: msg = ("Cannot activate environment {0}.\n" "User does not have write access for conda symlinks.". format(sys.argv[2])) raise CondaEnvironmentError(msg) raise sys.exit(0) # raise CondaSystemExit elif sys.argv[1] == '..changeps1': from conda.base.context import context path = int(context.changeps1) else: # This means there is a bug in main.py raise CondaValueError("unexpected command") # This print is actually what sets the PATH or PROMPT variable. The shell # script gets this value, and finishes the job. print(path)
def execute(args, parser): try: execute_search(args, parser) except NoPackagesFoundError as e: raise PackageNotFoundError('', text_type(e))
def main(): from conda.base.context import context from conda.base.constants import ROOT_ENV_NAME from conda.utils import shells if '-h' in sys.argv or '--help' in sys.argv: # all execution paths sys.exit at end. help(sys.argv[1], sys.argv[2]) if len(sys.argv) > 2: shell = sys.argv[2] shelldict = shells[shell] if sys.argv[1] == '..activate': arg_num = len(sys.argv) if arg_num != 4: num_expected = 2 if arg_num < 4: raise TooFewArgumentsError(num_expected, arg_num - num_expected, "..activate expected exactly two arguments:\ shell and env name") if arg_num > 4: raise TooManyArgumentsError(num_expected, arg_num - num_expected, sys.argv[2:], "..activate expected exactly two arguments:\ shell and env name") binpath = binpath_from_arg(sys.argv[3], shelldict=shelldict) # prepend our new entries onto the existing path and make sure that the separator is native path = shelldict['pathsep'].join(binpath) # deactivation is handled completely in shell scripts - it restores backups of env variables. # It is done in shell scripts because they handle state much better than we can here. elif sys.argv[1] == '..checkenv': if len(sys.argv) < 4: raise ArgumentError("Invalid arguments to checkenv. Need shell and env name/path") if len(sys.argv) > 4: raise ArgumentError("did not expect more than one argument.") if sys.argv[3].lower() == ROOT_ENV_NAME.lower(): # no need to check root env and try to install a symlink there sys.exit(0) # raise CondaSystemExit # this should throw an error and exit if the env or path can't be found. try: prefix = prefix_from_arg(sys.argv[3], shelldict=shelldict) except ValueError as e: raise CondaValueError(text_type(e)) # Make sure an env always has the conda symlink try: import conda.install conda.install.symlink_conda(prefix, context.root_dir, shell) except (IOError, OSError) as e: if e.errno == errno.EPERM or e.errno == errno.EACCES: msg = ("Cannot activate environment {0}.\n" "User does not have write access for conda symlinks." .format(sys.argv[2])) raise CondaEnvironmentError(msg) raise sys.exit(0) # raise CondaSystemExit elif sys.argv[1] == '..changeps1': from conda.base.context import context path = int(context.changeps1) else: # This means there is a bug in main.py raise CondaValueError("unexpected command") # This print is actually what sets the PATH or PROMPT variable. The shell # script gets this value, and finishes the job. print(path)