Skip to content

Commit 760677d

Browse files
committed
#1047: Fix pip_unknown_command by using a less restrictive regex
Fix #1047
1 parent 2ced7a7 commit 760677d

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

tests/rules/test_pip_unknown_command.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44

55

66
@pytest.fixture
7-
def pip_unknown_cmd():
8-
return '''ERROR: unknown command "instatl" - maybe you meant "install"'''
7+
def pip_unknown_cmd_without_recommend():
8+
return '''ERROR: unknown command "i"'''
99

1010

1111
@pytest.fixture
12-
def pip_unknown_cmd_without_recommend():
13-
return '''ERROR: unknown command "i"'''
12+
def broken():
13+
return 'instatl'
14+
15+
16+
@pytest.fixture
17+
def suggested():
18+
return 'install'
19+
20+
21+
@pytest.fixture
22+
def pip_unknown_cmd(broken, suggested):
23+
return 'ERROR: unknown command "{}" - maybe you meant "{}"'.format(broken, suggested)
1424

1525

1626
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):
1929
pip_unknown_cmd_without_recommend))
2030

2131

22-
def test_get_new_command(pip_unknown_cmd):
23-
assert get_new_command(Command('pip instatl',
24-
pip_unknown_cmd)) == 'pip install'
32+
@pytest.mark.parametrize('script, broken, suggested, new_cmd', [
33+
('pip un+install thefuck', 'un+install', 'uninstall', 'pip uninstall thefuck'),
34+
('pip instatl', 'instatl', 'install', 'pip install')])
35+
def test_get_new_command(script, new_cmd, pip_unknown_cmd):
36+
assert get_new_command(Command(script,
37+
pip_unknown_cmd)) == new_cmd

thefuck/rules/pip_unknown_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def match(command):
1212

1313

1414
def get_new_command(command):
15-
broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"',
15+
broken_cmd = re.findall(r'ERROR: unknown command "([^"]+)"',
1616
command.output)[0]
17-
new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.output)[0]
17+
new_cmd = re.findall(r'maybe you meant "([^"]+)"', command.output)[0]
1818

1919
return replace_argument(command.script, broken_cmd, new_cmd)

0 commit comments

Comments
 (0)