diff --git a/tests/test_conf.py b/tests/test_conf.py index 6e96b9da5..e03473ab5 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -55,7 +55,7 @@ def test_from_env(self, os_environ, settings): 'THEFUCK_WAIT_SLOW_COMMAND': '999', 'THEFUCK_SLOW_COMMANDS': 'lein:react-native:./gradlew', 'THEFUCK_NUM_CLOSE_MATCHES': '359', - 'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': '/mnt/'}) + 'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': '/media/:/mnt/'}) settings.init() assert settings.rules == ['bash', 'lisp'] assert settings.exclude_rules == ['git', 'vim'] @@ -66,7 +66,7 @@ def test_from_env(self, os_environ, settings): assert settings.wait_slow_command == 999 assert settings.slow_commands == ['lein', 'react-native', './gradlew'] assert settings.num_close_matches == 359 - assert settings.excluded_search_path_prefixes == ['/mnt/'] + assert settings.excluded_search_path_prefixes == ['/media/', '/mnt/'] def test_from_env_with_DEFAULT(self, os_environ, settings): os_environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'}) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0c1b55780..b32f695ad 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -103,8 +103,9 @@ def test_get_all_executables_exclude_paths(path, pathsep, excluded, settings): settings.excluded_search_path_prefixes = [excluded] with patch('thefuck.utils.Path') as Path_mock: get_all_executables() - assert call(excluded) not in Path_mock.mock_calls - assert call(path.split(pathsep)[0]) in Path_mock.mock_calls + path_list = path.split(pathsep) + assert call(path_list[-1]) not in Path_mock.mock_calls + assert all(call(p) in Path_mock.mock_calls for p in path_list[:-1]) @pytest.mark.parametrize('args, result', [ diff --git a/thefuck/utils.py b/thefuck/utils.py index 8beae4d72..1df113420 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -105,10 +105,7 @@ def get_close_matches(word, possibilities, n=None, cutoff=0.6): def include_path_in_search(path): - for exclude_path in settings.excluded_search_path_prefixes: - if path.startswith(exclude_path): - return False - return True + return not any(path.startswith(x) for x in settings.excluded_search_path_prefixes) @memoize @@ -125,7 +122,8 @@ def _safe(fn, fallback): tf_entry_points = ['thefuck', 'fuck'] bins = [exe.name.decode('utf8') if six.PY2 else exe.name - for path in os.environ.get('PATH', '').split(os.pathsep) if include_path_in_search(path) + for path in os.environ.get('PATH', '').split(os.pathsep) + if include_path_in_search(path) for exe in _safe(lambda: list(Path(path).iterdir()), []) if not _safe(exe.is_dir, True) and exe.name not in tf_entry_points]