2015-04-23 15:25:12 +09:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.pip_unknown_command import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2015-04-23 15:25:12 +09:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2020-02-29 19:19:38 -06:00
|
|
|
def pip_unknown_cmd_without_recommend():
|
|
|
|
return '''ERROR: unknown command "i"'''
|
2015-04-23 15:25:12 +09:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2020-02-29 19:19:38 -06:00
|
|
|
def broken():
|
|
|
|
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)
|
2015-04-23 15:25:12 +09:00
|
|
|
|
|
|
|
|
|
|
|
def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend):
|
2017-08-31 17:58:56 +02:00
|
|
|
assert match(Command('pip instatl', pip_unknown_cmd))
|
2015-04-25 02:35:26 +02:00
|
|
|
assert not match(Command('pip i',
|
2017-08-31 17:58:56 +02:00
|
|
|
pip_unknown_cmd_without_recommend))
|
2015-04-23 15:25:12 +09:00
|
|
|
|
|
|
|
|
2020-02-29 19:19:38 -06:00
|
|
|
@pytest.mark.parametrize('script, broken, suggested, new_cmd', [
|
|
|
|
('pip un+install thefuck', 'un+install', 'uninstall', 'pip uninstall thefuck'),
|
|
|
|
('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
|