mirror of
https://github.com/nvbn/thefuck.git
synced 2026-02-08 00:32:18 +00:00
Add excluded_search_path_prefixes setting (#1165)
Improves performance in WSL Fix #1036 * Add excluded_search_path_prefixes setting Allows filtering the paths used to search for commands Can be useful to filter out /mnt/ in WSL for performance * Add test for excluded_search_path_prefixes * Apply suggestions from code review Co-authored-by: Pablo Aguiar <scorphus@gmail.com> Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
This commit is contained in:
@@ -54,7 +54,8 @@ class TestSettingsFromEnv(object):
|
||||
'THEFUCK_PRIORITY': 'bash=10:lisp=wrong:vim=15',
|
||||
'THEFUCK_WAIT_SLOW_COMMAND': '999',
|
||||
'THEFUCK_SLOW_COMMANDS': 'lein:react-native:./gradlew',
|
||||
'THEFUCK_NUM_CLOSE_MATCHES': '359'})
|
||||
'THEFUCK_NUM_CLOSE_MATCHES': '359',
|
||||
'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': '/media/:/mnt/'})
|
||||
settings.init()
|
||||
assert settings.rules == ['bash', 'lisp']
|
||||
assert settings.exclude_rules == ['git', 'vim']
|
||||
@@ -65,6 +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 == ['/media/', '/mnt/']
|
||||
|
||||
def test_from_env_with_DEFAULT(self, os_environ, settings):
|
||||
os_environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'})
|
||||
|
||||
@@ -94,6 +94,20 @@ def test_get_all_executables_pathsep(path, pathsep):
|
||||
Path_mock.assert_has_calls([call(p) for p in path.split(pathsep)], True)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('no_memoize', 'os_environ_pathsep')
|
||||
@pytest.mark.parametrize('path, pathsep, excluded', [
|
||||
('/foo:/bar:/baz:/foo/bar:/mnt/foo', ':', '/mnt/foo'),
|
||||
(r'C:\\foo;C:\\bar;C:\\baz;C:\\foo\\bar;Z:\\foo', ';', r'Z:\\foo')])
|
||||
def test_get_all_executables_exclude_paths(path, pathsep, excluded, settings):
|
||||
settings.init()
|
||||
settings.excluded_search_path_prefixes = [excluded]
|
||||
with patch('thefuck.utils.Path') as Path_mock:
|
||||
get_all_executables()
|
||||
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', [
|
||||
(('apt-get instol vim', 'instol', 'install'), 'apt-get install vim'),
|
||||
(('git brnch', 'brnch', 'branch'), 'git branch')])
|
||||
|
||||
Reference in New Issue
Block a user