1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 10:11:14 +00:00

refact(rules.no_command): do not add TF_ALIAS to the “callables” list

Fix #234, #245 and #251

Ref #221
This commit is contained in:
Pablo Santiago Blum de Aguiar 2015-06-10 20:53:35 -03:00
parent c08d9125e4
commit 96fe1e77b3
2 changed files with 35 additions and 16 deletions

View File

@ -1,19 +1,36 @@
from mock import patch, Mock from mock import patch, Mock
from thefuck.rules.no_command import match, get_new_command from thefuck.rules.no_command import match, get_new_command, _get_all_callables
def test_match(): @patch('thefuck.rules.no_command._safe', return_value=[])
with patch('thefuck.rules.no_command._get_all_callables', @patch('thefuck.rules.no_command.get_aliases',
return_value=['vim', 'apt-get']): return_value=['vim', 'apt-get', 'fsck', 'fuck'])
assert match(Mock(stderr='vom: not found', script='vom file.py'), None) def test_get_all_callables(*args):
assert not match(Mock(stderr='qweqwe: not found', script='qweqwe'), None) all_callables = _get_all_callables()
assert not match(Mock(stderr='some text', script='vom file.py'), None) assert 'vim' in all_callables
assert 'fsck' in all_callables
assert 'fuck' not in all_callables
def test_get_new_command(): @patch('thefuck.rules.no_command._safe', return_value=[])
with patch('thefuck.rules.no_command._get_all_callables', @patch('thefuck.rules.no_command.get_aliases',
return_value=['vim', 'apt-get']): return_value=['vim', 'apt-get', 'fsck', 'fuck'])
assert get_new_command( def test_match(*args):
Mock(stderr='vom: not found', assert match(Mock(stderr='vom: not found', script='vom file.py'), None)
script='vom file.py'), assert match(Mock(stderr='fucck: not found', script='fucck'), None)
None) == 'vim file.py' assert not match(Mock(stderr='qweqwe: not found', script='qweqwe'), None)
assert not match(Mock(stderr='some text', script='vom file.py'), None)
@patch('thefuck.rules.no_command._safe', return_value=[])
@patch('thefuck.rules.no_command.get_aliases',
return_value=['vim', 'apt-get', 'fsck', 'fuck'])
def test_get_new_command(*args):
assert get_new_command(
Mock(stderr='vom: not found',
script='vom file.py'),
None) == 'vim file.py'
assert get_new_command(
Mock(stderr='fucck: not found',
script='fucck'),
None) == 'fsck'

View File

@ -2,7 +2,7 @@ from difflib import get_close_matches
import os import os
from pathlib import Path from pathlib import Path
from thefuck.utils import sudo_support from thefuck.utils import sudo_support
from thefuck.shells import get_aliases from thefuck.shells import thefuck_alias, get_aliases
def _safe(fn, fallback): def _safe(fn, fallback):
@ -13,10 +13,12 @@ def _safe(fn, fallback):
def _get_all_callables(): def _get_all_callables():
tf_alias = thefuck_alias()
return [exe.name return [exe.name
for path in os.environ.get('PATH', '').split(':') for path in os.environ.get('PATH', '').split(':')
for exe in _safe(lambda: list(Path(path).iterdir()), []) for exe in _safe(lambda: list(Path(path).iterdir()), [])
if not _safe(exe.is_dir, True)] + get_aliases() if not _safe(exe.is_dir, True)] + [
alias for alias in get_aliases() if alias != tf_alias]
@sudo_support @sudo_support