2015-07-10 17:58:41 +03:00
|
|
|
import pytest
|
2015-07-20 21:04:49 +03:00
|
|
|
from thefuck.rules.no_command import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2015-04-08 19:00:03 +02:00
|
|
|
|
|
|
|
|
2015-07-10 17:58:41 +03:00
|
|
|
@pytest.fixture(autouse=True)
|
2015-07-20 21:04:49 +03:00
|
|
|
def get_all_executables(mocker):
|
|
|
|
mocker.patch('thefuck.rules.no_command.get_all_executables',
|
2019-05-27 18:23:06 +02:00
|
|
|
return_value=['vim', 'fsck', 'git', 'go', 'python'])
|
2016-03-13 15:10:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def history_without_current(mocker):
|
|
|
|
return mocker.patch(
|
|
|
|
'thefuck.rules.no_command.get_valid_history_without_current',
|
|
|
|
return_value=['git commit'])
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('no_memoize')
|
2017-08-31 17:58:56 +02:00
|
|
|
@pytest.mark.parametrize('script, output', [
|
2016-03-13 15:10:37 +03:00
|
|
|
('vom file.py', 'vom: not found'),
|
|
|
|
('fucck', 'fucck: not found'),
|
2019-05-27 18:23:06 +02:00
|
|
|
('puthon', "'puthon' is not recognized as an internal or external command"),
|
2022-06-14 00:29:15 +03:00
|
|
|
('got commit', 'got: command not found'),
|
|
|
|
('gti commit -m "new commit"', 'gti: command not found')])
|
2017-08-31 17:58:56 +02:00
|
|
|
def test_match(mocker, script, output):
|
2016-08-13 15:39:42 +03:00
|
|
|
mocker.patch('thefuck.rules.no_command.which', return_value=None)
|
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
assert match(Command(script, output))
|
2015-04-08 19:00:03 +02:00
|
|
|
|
|
|
|
|
2015-07-10 17:58:41 +03:00
|
|
|
@pytest.mark.usefixtures('no_memoize')
|
2017-08-31 17:58:56 +02:00
|
|
|
@pytest.mark.parametrize('script, output, which', [
|
2016-08-13 15:39:42 +03:00
|
|
|
('qweqwe', 'qweqwe: not found', None),
|
|
|
|
('vom file.py', 'some text', None),
|
|
|
|
('vim file.py', 'vim: not found', 'vim')])
|
2017-08-31 17:58:56 +02:00
|
|
|
def test_not_match(mocker, script, output, which):
|
2016-08-13 15:39:42 +03:00
|
|
|
mocker.patch('thefuck.rules.no_command.which', return_value=which)
|
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
assert not match(Command(script, output))
|
2015-06-10 20:53:35 -03:00
|
|
|
|
|
|
|
|
2015-07-10 17:58:41 +03:00
|
|
|
@pytest.mark.usefixtures('no_memoize')
|
2016-03-13 15:10:37 +03:00
|
|
|
@pytest.mark.parametrize('script, result', [
|
|
|
|
('vom file.py', ['vim file.py']),
|
|
|
|
('fucck', ['fsck']),
|
2022-06-14 00:29:15 +03:00
|
|
|
('got commit', ['git commit', 'go commit']),
|
|
|
|
('gti commit -m "new commit"', ['git commit -m "new commit"'])])
|
2016-03-13 15:10:37 +03:00
|
|
|
def test_get_new_command(script, result):
|
2017-08-31 17:58:56 +02:00
|
|
|
assert get_new_command(Command(script, '')) == result
|