mirror of
https://github.com/nvbn/thefuck.git
synced 2025-10-30 14:44:05 +00:00
#N/A Add history rule
This commit is contained in:
6
tests/conftest.py
Normal file
6
tests/conftest.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def no_memoize(monkeypatch):
|
||||
monkeypatch.setattr('thefuck.utils.memoize.disabled', True)
|
||||
35
tests/rules/test_history.py
Normal file
35
tests/rules/test_history.py
Normal file
@@ -0,0 +1,35 @@
|
||||
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',
|
||||
return_value=['ls cat', 'diff x', 'nocommand x'])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def callables(mocker):
|
||||
return mocker.patch('thefuck.rules.history.get_all_callables',
|
||||
return_value=['diff', 'ls'])
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('history', 'callables', 'no_memoize')
|
||||
@pytest.mark.parametrize('script', ['ls cet', 'daff x'])
|
||||
def test_match(script):
|
||||
assert match(Command(script=script), None)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('history', 'callables', 'no_memoize')
|
||||
@pytest.mark.parametrize('script', ['apt-get', 'nocommand y'])
|
||||
def test_not_match(script):
|
||||
assert not match(Command(script=script), None)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('history', 'callables', 'no_memoize')
|
||||
@pytest.mark.parametrize('script, result', [
|
||||
('ls cet', 'ls cat'),
|
||||
('daff x', 'diff x')])
|
||||
def test_get_new_command(script, result):
|
||||
assert get_new_command(Command(script), None) == result
|
||||
@@ -1,36 +1,42 @@
|
||||
from mock import patch, Mock
|
||||
from thefuck.rules.no_command import match, get_new_command, _get_all_callables
|
||||
import pytest
|
||||
from thefuck.rules.no_command import match, get_new_command, get_all_callables
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@patch('thefuck.rules.no_command._safe', return_value=[])
|
||||
@patch('thefuck.rules.no_command.get_aliases',
|
||||
return_value=['vim', 'apt-get', 'fsck', 'fuck'])
|
||||
@pytest.fixture(autouse=True)
|
||||
def _safe(mocker):
|
||||
mocker.patch('thefuck.rules.no_command._safe', return_value=[])
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def get_aliases(mocker):
|
||||
mocker.patch('thefuck.rules.no_command.get_aliases',
|
||||
return_value=['vim', 'apt-get', 'fsck', 'fuck'])
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('no_memoize')
|
||||
def test_get_all_callables(*args):
|
||||
all_callables = _get_all_callables()
|
||||
all_callables = get_all_callables()
|
||||
assert 'vim' in all_callables
|
||||
assert 'fsck' in all_callables
|
||||
assert 'fuck' not in all_callables
|
||||
|
||||
|
||||
@patch('thefuck.rules.no_command._safe', return_value=[])
|
||||
@patch('thefuck.rules.no_command.get_aliases',
|
||||
return_value=['vim', 'apt-get', 'fsck', 'fuck'])
|
||||
@pytest.mark.usefixtures('no_memoize')
|
||||
def test_match(*args):
|
||||
assert match(Mock(stderr='vom: not found', script='vom file.py'), None)
|
||||
assert match(Mock(stderr='fucck: not found', script='fucck'), None)
|
||||
assert not match(Mock(stderr='qweqwe: not found', script='qweqwe'), None)
|
||||
assert not match(Mock(stderr='some text', script='vom file.py'), None)
|
||||
assert match(Command(stderr='vom: not found', script='vom file.py'), None)
|
||||
assert match(Command(stderr='fucck: not found', script='fucck'), None)
|
||||
assert not match(Command(stderr='qweqwe: not found', script='qweqwe'), None)
|
||||
assert not match(Command(stderr='some text', script='vom file.py'), None)
|
||||
|
||||
|
||||
@patch('thefuck.rules.no_command._safe', return_value=[])
|
||||
@patch('thefuck.rules.no_command.get_aliases',
|
||||
return_value=['vim', 'apt-get', 'fsck', 'fuck'])
|
||||
@pytest.mark.usefixtures('no_memoize')
|
||||
def test_get_new_command(*args):
|
||||
assert get_new_command(
|
||||
Mock(stderr='vom: not found',
|
||||
script='vom file.py'),
|
||||
Command(stderr='vom: not found',
|
||||
script='vom file.py'),
|
||||
None) == 'vim file.py'
|
||||
assert get_new_command(
|
||||
Mock(stderr='fucck: not found',
|
||||
script='fucck'),
|
||||
None) == 'fsck'
|
||||
Command(stderr='fucck: not found',
|
||||
script='fucck'),
|
||||
Command) == 'fsck'
|
||||
|
||||
@@ -2,7 +2,7 @@ import pytest
|
||||
from mock import Mock
|
||||
from thefuck.utils import sudo_support, wrap_settings, memoize, get_closest
|
||||
from thefuck.types import Settings
|
||||
from tests.utils import Command, no_memoize
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('override, old, new', [
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import pytest
|
||||
from thefuck import types
|
||||
from thefuck.conf import DEFAULT_PRIORITY
|
||||
|
||||
@@ -15,7 +14,3 @@ def Rule(name='', match=lambda *_: True,
|
||||
return types.Rule(name, match, get_new_command,
|
||||
enabled_by_default, side_effect,
|
||||
priority)
|
||||
|
||||
@pytest.fixture
|
||||
def no_memoize(monkeypatch):
|
||||
monkeypatch.setattr('thefuck.utils.memoize.disabled', True)
|
||||
|
||||
Reference in New Issue
Block a user