From ca787a1cba3cc9b26b43919c5e60acb40ebcd919 Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Sat, 13 Aug 2016 15:39:42 +0300 Subject: [PATCH] #N/A: Ensure that command doesn't exists in `no_command` rule --- tests/rules/test_no_command.py | 15 ++++++++++----- thefuck/rules/no_command.py | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/rules/test_no_command.py b/tests/rules/test_no_command.py index 5249c2b4..5e5aab94 100644 --- a/tests/rules/test_no_command.py +++ b/tests/rules/test_no_command.py @@ -21,15 +21,20 @@ def history_without_current(mocker): ('vom file.py', 'vom: not found'), ('fucck', 'fucck: not found'), ('got commit', 'got: command not found')]) -def test_match(script, stderr): +def test_match(mocker, script, stderr): + mocker.patch('thefuck.rules.no_command.which', return_value=None) + assert match(Command(script, stderr=stderr)) @pytest.mark.usefixtures('no_memoize') -@pytest.mark.parametrize('script, stderr', [ - ('qweqwe', 'qweqwe: not found'), - ('vom file.py', 'some text')]) -def test_not_match(script, stderr): +@pytest.mark.parametrize('script, stderr, which', [ + ('qweqwe', 'qweqwe: not found', None), + ('vom file.py', 'some text', None), + ('vim file.py', 'vim: not found', 'vim')]) +def test_not_match(mocker, script, stderr, which): + mocker.patch('thefuck.rules.no_command.which', return_value=which) + assert not match(Command(script, stderr=stderr)) diff --git a/thefuck/rules/no_command.py b/thefuck/rules/no_command.py index 34b7a4bf..174ee780 100644 --- a/thefuck/rules/no_command.py +++ b/thefuck/rules/no_command.py @@ -1,12 +1,12 @@ from difflib import get_close_matches from thefuck.utils import get_all_executables, \ - get_valid_history_without_current, get_closest + get_valid_history_without_current, get_closest, which from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return (command.script_parts + return (not which(command.script_parts[0]) and 'not found' in command.stderr and bool(get_close_matches(command.script_parts[0], get_all_executables())))