1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 20:11:17 +00:00

#1047: Fix pip_unknown_command by using a less restrictive regex

Fix #1047
This commit is contained in:
Caplinja 2020-02-29 19:19:38 -06:00 committed by Pablo Aguiar
parent 2ced7a7f33
commit 444908ce1c
2 changed files with 22 additions and 9 deletions

View File

@ -4,13 +4,23 @@ from thefuck.types import Command
@pytest.fixture @pytest.fixture
def pip_unknown_cmd(): def pip_unknown_cmd_without_recommend():
return '''ERROR: unknown command "instatl" - maybe you meant "install"''' return '''ERROR: unknown command "i"'''
@pytest.fixture @pytest.fixture
def pip_unknown_cmd_without_recommend(): def broken():
return '''ERROR: unknown command "i"''' return 'instatl'
@pytest.fixture
def suggested():
return 'install'
@pytest.fixture
def pip_unknown_cmd(broken, suggested):
return 'ERROR: unknown command "{}" - maybe you meant "{}"'.format(broken, suggested)
def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend): def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend):
@ -19,6 +29,9 @@ def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend):
pip_unknown_cmd_without_recommend)) pip_unknown_cmd_without_recommend))
def test_get_new_command(pip_unknown_cmd): @pytest.mark.parametrize('script, broken, suggested, new_cmd', [
assert get_new_command(Command('pip instatl', ('pip un+install thefuck', 'un+install', 'uninstall', 'pip uninstall thefuck'),
pip_unknown_cmd)) == 'pip install' ('pip instatl', 'instatl', 'install', 'pip install')])
def test_get_new_command(script, new_cmd, pip_unknown_cmd):
assert get_new_command(Command(script,
pip_unknown_cmd)) == new_cmd

View File

@ -12,8 +12,8 @@ def match(command):
def get_new_command(command): def get_new_command(command):
broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"', broken_cmd = re.findall(r'ERROR: unknown command "([^"]+)"',
command.output)[0] command.output)[0]
new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.output)[0] new_cmd = re.findall(r'maybe you meant "([^"]+)"', command.output)[0]
return replace_argument(command.script, broken_cmd, new_cmd) return replace_argument(command.script, broken_cmd, new_cmd)