2015-07-10 17:58:41 +03:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.history import match, get_new_command
|
|
|
|
from tests.utils import Command
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def history(mocker):
|
|
|
|
return mocker.patch('thefuck.rules.history.get_history',
|
2015-07-20 01:53:32 +03:00
|
|
|
return_value=['le cat', 'fuck', 'ls cat',
|
|
|
|
'diff x', 'nocommand x'])
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def alias(mocker):
|
|
|
|
return mocker.patch('thefuck.rules.history.thefuck_alias',
|
|
|
|
return_value='fuck')
|
2015-07-10 17:58:41 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def callables(mocker):
|
2015-07-20 21:04:49 +03:00
|
|
|
return mocker.patch('thefuck.rules.history.get_all_executables',
|
2015-07-10 17:58:41 +03:00
|
|
|
return_value=['diff', 'ls'])
|
|
|
|
|
|
|
|
|
2015-07-20 01:53:32 +03:00
|
|
|
@pytest.mark.usefixtures('history', 'callables', 'no_memoize', 'alias')
|
2015-07-10 17:58:41 +03:00
|
|
|
@pytest.mark.parametrize('script', ['ls cet', 'daff x'])
|
|
|
|
def test_match(script):
|
2015-09-07 13:00:29 +03:00
|
|
|
assert match(Command(script=script))
|
2015-07-10 17:58:41 +03:00
|
|
|
|
|
|
|
|
2015-07-20 01:53:32 +03:00
|
|
|
@pytest.mark.usefixtures('history', 'callables', 'no_memoize', 'alias')
|
2015-07-10 17:58:41 +03:00
|
|
|
@pytest.mark.parametrize('script', ['apt-get', 'nocommand y'])
|
|
|
|
def test_not_match(script):
|
2015-09-07 13:00:29 +03:00
|
|
|
assert not match(Command(script=script))
|
2015-07-10 17:58:41 +03:00
|
|
|
|
|
|
|
|
2015-07-20 01:53:32 +03:00
|
|
|
@pytest.mark.usefixtures('history', 'callables', 'no_memoize', 'alias')
|
2015-07-10 17:58:41 +03:00
|
|
|
@pytest.mark.parametrize('script, result', [
|
|
|
|
('ls cet', 'ls cat'),
|
|
|
|
('daff x', 'diff x')])
|
|
|
|
def test_get_new_command(script, result):
|
2015-09-07 13:00:29 +03:00
|
|
|
assert get_new_command(Command(script)) == result
|