Skip to content

Commit 89c6ab9

Browse files
Apply suggestions from code review
Co-authored-by: Pablo Aguiar <[email protected]>
1 parent 95f624b commit 89c6ab9

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

tests/test_conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_from_env(self, os_environ, settings):
5555
'THEFUCK_WAIT_SLOW_COMMAND': '999',
5656
'THEFUCK_SLOW_COMMANDS': 'lein:react-native:./gradlew',
5757
'THEFUCK_NUM_CLOSE_MATCHES': '359',
58-
'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': '/mnt/'})
58+
'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': '/media/:/mnt/'})
5959
settings.init()
6060
assert settings.rules == ['bash', 'lisp']
6161
assert settings.exclude_rules == ['git', 'vim']
@@ -66,7 +66,7 @@ def test_from_env(self, os_environ, settings):
6666
assert settings.wait_slow_command == 999
6767
assert settings.slow_commands == ['lein', 'react-native', './gradlew']
6868
assert settings.num_close_matches == 359
69-
assert settings.excluded_search_path_prefixes == ['/mnt/']
69+
assert settings.excluded_search_path_prefixes == ['/media/', '/mnt/']
7070

7171
def test_from_env_with_DEFAULT(self, os_environ, settings):
7272
os_environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'})

tests/test_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ def test_get_all_executables_exclude_paths(path, pathsep, excluded, settings):
103103
settings.excluded_search_path_prefixes = [excluded]
104104
with patch('thefuck.utils.Path') as Path_mock:
105105
get_all_executables()
106-
assert call(excluded) not in Path_mock.mock_calls
107-
assert call(path.split(pathsep)[0]) in Path_mock.mock_calls
106+
path_list = path.split(pathsep)
107+
assert call(path_list[-1]) not in Path_mock.mock_calls
108+
assert all(call(p) in Path_mock.mock_calls for p in path_list[:-1])
108109

109110

110111
@pytest.mark.parametrize('args, result', [

thefuck/utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ def get_close_matches(word, possibilities, n=None, cutoff=0.6):
105105

106106

107107
def include_path_in_search(path):
108-
for exclude_path in settings.excluded_search_path_prefixes:
109-
if path.startswith(exclude_path):
110-
return False
111-
return True
108+
return not any(path.startswith(x) for x in settings.excluded_search_path_prefixes)
112109

113110

114111
@memoize
@@ -125,7 +122,8 @@ def _safe(fn, fallback):
125122
tf_entry_points = ['thefuck', 'fuck']
126123

127124
bins = [exe.name.decode('utf8') if six.PY2 else exe.name
128-
for path in os.environ.get('PATH', '').split(os.pathsep) if include_path_in_search(path)
125+
for path in os.environ.get('PATH', '').split(os.pathsep)
126+
if include_path_in_search(path)
129127
for exe in _safe(lambda: list(Path(path).iterdir()), [])
130128
if not _safe(exe.is_dir, True)
131129
and exe.name not in tf_entry_points]

0 commit comments

Comments
 (0)