1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 06:38:32 +00:00

Apply suggestions from code review

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
This commit is contained in:
Stuart Leeks 2021-04-17 06:57:49 +01:00
parent 98c96a8734
commit de02df1a08
3 changed files with 8 additions and 9 deletions

View File

@ -55,7 +55,7 @@ class TestSettingsFromEnv(object):
'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 @@ class TestSettingsFromEnv(object):
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'})

View File

@ -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', [

View File

@ -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 get_all_executables():
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]