From fa92f60d21e6370d568007ffc3dc04db419f1423 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Wed, 10 Jun 2015 20:53:35 -0300 Subject: [PATCH] =?UTF-8?q?refact(rules.no=5Fcommand):=20do=20not=20add=20?= =?UTF-8?q?TF=5FALIAS=20to=20the=20=E2=80=9Ccallables=E2=80=9D=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #234, #245 and #251 Ref #221 --- tests/rules/test_no_command.py | 45 +++++++++++++++++++++++----------- thefuck/rules/no_command.py | 6 +++-- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/tests/rules/test_no_command.py b/tests/rules/test_no_command.py index 68ccf3f71..167deca17 100644 --- a/tests/rules/test_no_command.py +++ b/tests/rules/test_no_command.py @@ -1,19 +1,36 @@ 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(): - with patch('thefuck.rules.no_command._get_all_callables', - return_value=['vim', 'apt-get']): - assert match(Mock(stderr='vom: not found', script='vom file.py'), None) - 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_all_callables(*args): + all_callables = _get_all_callables() + assert 'vim' in all_callables + assert 'fsck' in all_callables + assert 'fuck' not in all_callables -def test_get_new_command(): - with patch('thefuck.rules.no_command._get_all_callables', - return_value=['vim', 'apt-get']): - assert get_new_command( - Mock(stderr='vom: not found', - script='vom file.py'), - None) == 'vim file.py' +@patch('thefuck.rules.no_command._safe', return_value=[]) +@patch('thefuck.rules.no_command.get_aliases', + return_value=['vim', 'apt-get', 'fsck', 'fuck']) +def test_match(*args): + assert match(Mock(stderr='vom: not found', script='vom file.py'), None) + assert match(Mock(stderr='fucck: not found', script='fucck'), None) + 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' diff --git a/thefuck/rules/no_command.py b/thefuck/rules/no_command.py index 3b310495e..2f6337b89 100644 --- a/thefuck/rules/no_command.py +++ b/thefuck/rules/no_command.py @@ -2,7 +2,7 @@ import os from pathlib import Path from thefuck.utils import sudo_support -from thefuck.shells import get_aliases +from thefuck.shells import thefuck_alias, get_aliases def _safe(fn, fallback): @@ -13,10 +13,12 @@ def _safe(fn, fallback): def _get_all_callables(): + tf_alias = thefuck_alias() return [exe.name for path in os.environ.get('PATH', '').split(':') 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