mirror of
https://github.com/nvbn/thefuck.git
synced 2025-10-30 06:34:09 +00:00
#614: Add --repeat option
This commit is contained in:
@@ -33,6 +33,9 @@ class TestBash(object):
|
||||
def test_and_(self, shell):
|
||||
assert shell.and_('ls', 'cd') == 'ls && cd'
|
||||
|
||||
def test_or_(self, shell):
|
||||
assert shell.or_('ls', 'cd') == 'ls || cd'
|
||||
|
||||
def test_get_aliases(self, shell):
|
||||
assert shell.get_aliases() == {'fuck': 'eval $(thefuck $(fc -ln -1))',
|
||||
'l': 'ls -CF',
|
||||
|
||||
@@ -55,6 +55,9 @@ class TestFish(object):
|
||||
def test_and_(self, shell):
|
||||
assert shell.and_('foo', 'bar') == 'foo; and bar'
|
||||
|
||||
def test_or_(self, shell):
|
||||
assert shell.or_('foo', 'bar') == 'foo; or bar'
|
||||
|
||||
def test_get_aliases(self, shell):
|
||||
assert shell.get_aliases() == {'fish_config': 'fish_config',
|
||||
'fuck': 'fuck',
|
||||
|
||||
@@ -18,6 +18,9 @@ class TestGeneric(object):
|
||||
def test_and_(self, shell):
|
||||
assert shell.and_('ls', 'cd') == 'ls && cd'
|
||||
|
||||
def test_or_(self, shell):
|
||||
assert shell.or_('ls', 'cd') == 'ls || cd'
|
||||
|
||||
def test_get_aliases(self, shell):
|
||||
assert shell.get_aliases() == {}
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ class TestTcsh(object):
|
||||
def test_and_(self, shell):
|
||||
assert shell.and_('ls', 'cd') == 'ls && cd'
|
||||
|
||||
def test_or_(self, shell):
|
||||
assert shell.or_('ls', 'cd') == 'ls || cd'
|
||||
|
||||
def test_get_aliases(self, shell):
|
||||
assert shell.get_aliases() == {'fuck': 'eval $(thefuck $(fc -ln -1))',
|
||||
'l': 'ls -CF',
|
||||
|
||||
@@ -32,6 +32,9 @@ class TestZsh(object):
|
||||
def test_and_(self, shell):
|
||||
assert shell.and_('ls', 'cd') == 'ls && cd'
|
||||
|
||||
def test_or_(self, shell):
|
||||
assert shell.or_('ls', 'cd') == 'ls || cd'
|
||||
|
||||
def test_get_aliases(self, shell):
|
||||
assert shell.get_aliases() == {
|
||||
'fuck': 'eval $(thefuck $(fc -ln -1 | tail -n 1))',
|
||||
|
||||
@@ -3,29 +3,27 @@ from thefuck.argument_parser import Parser
|
||||
from thefuck.const import ARGUMENT_PLACEHOLDER
|
||||
|
||||
|
||||
def _args(**override):
|
||||
args = {'alias': None, 'command': [], 'yes': False,
|
||||
'help': False, 'version': False, 'debug': False,
|
||||
'force_command': None, 'repeat': False}
|
||||
args.update(override)
|
||||
return args
|
||||
|
||||
|
||||
@pytest.mark.parametrize('argv, result', [
|
||||
(['thefuck'], {'alias': None, 'command': [], 'yes': False,
|
||||
'help': False, 'version': False, 'debug': False}),
|
||||
(['thefuck', '-a'],
|
||||
{'alias': 'fuck', 'command': [], 'yes': False,
|
||||
'help': False, 'version': False, 'debug': False}),
|
||||
(['thefuck', '-a', 'fix'],
|
||||
{'alias': 'fix', 'command': [], 'yes': False,
|
||||
'help': False, 'version': False, 'debug': False}),
|
||||
(['thefuck'], _args()),
|
||||
(['thefuck', '-a'], _args(alias='fuck')),
|
||||
(['thefuck', '-a', 'fix'], _args(alias='fix')),
|
||||
(['thefuck', 'git', 'branch', ARGUMENT_PLACEHOLDER, '-y'],
|
||||
{'alias': None, 'command': ['git', 'branch'], 'yes': True,
|
||||
'help': False, 'version': False, 'debug': False}),
|
||||
_args(command=['git', 'branch'], yes=True)),
|
||||
(['thefuck', 'git', 'branch', '-a', ARGUMENT_PLACEHOLDER, '-y'],
|
||||
{'alias': None, 'command': ['git', 'branch', '-a'], 'yes': True,
|
||||
'help': False, 'version': False, 'debug': False}),
|
||||
(['thefuck', ARGUMENT_PLACEHOLDER, '-v'],
|
||||
{'alias': None, 'command': [], 'yes': False, 'help': False,
|
||||
'version': True, 'debug': False}),
|
||||
(['thefuck', ARGUMENT_PLACEHOLDER, '--help'],
|
||||
{'alias': None, 'command': [], 'yes': False, 'help': True,
|
||||
'version': False, 'debug': False}),
|
||||
_args(command=['git', 'branch', '-a'], yes=True)),
|
||||
(['thefuck', ARGUMENT_PLACEHOLDER, '-v'], _args(version=True)),
|
||||
(['thefuck', ARGUMENT_PLACEHOLDER, '--help'], _args(help=True)),
|
||||
(['thefuck', 'git', 'branch', '-a', ARGUMENT_PLACEHOLDER, '-y', '-d'],
|
||||
{'alias': None, 'command': ['git', 'branch', '-a'], 'yes': True,
|
||||
'help': False, 'version': False, 'debug': True})])
|
||||
_args(command=['git', 'branch', '-a'], yes=True, debug=True)),
|
||||
(['thefuck', 'git', 'branch', '-a', ARGUMENT_PLACEHOLDER, '-r', '-d'],
|
||||
_args(command=['git', 'branch', '-a'], repeat=True, debug=True))])
|
||||
def test_parse(argv, result):
|
||||
assert vars(Parser().parse(argv)) == result
|
||||
|
||||
@@ -80,9 +80,10 @@ class TestSettingsFromEnv(object):
|
||||
|
||||
|
||||
def test_settings_from_args(settings):
|
||||
settings.init(Mock(yes=True, debug=True))
|
||||
settings.init(Mock(yes=True, debug=True, repeat=True))
|
||||
assert not settings.require_confirmation
|
||||
assert settings.debug
|
||||
assert settings.repeat
|
||||
|
||||
|
||||
class TestInitializeSettingsFile(object):
|
||||
|
||||
@@ -28,6 +28,20 @@ class TestCorrectedCommand(object):
|
||||
assert u'{}'.format(CorrectedCommand(u'echo café', None, 100)) == \
|
||||
u'CorrectedCommand(script=echo café, side_effect=None, priority=100)'
|
||||
|
||||
@pytest.mark.parametrize('script, printed, override_settings', [
|
||||
('git branch', 'git branch', {'repeat': False, 'debug': False}),
|
||||
('git brunch',
|
||||
"git brunch || fuck --repeat --force-command 'git brunch'",
|
||||
{'repeat': True, 'debug': False}),
|
||||
('git brunch',
|
||||
"git brunch || fuck --repeat --debug --force-command 'git brunch'",
|
||||
{'repeat': True, 'debug': True})])
|
||||
def test_run(self, capsys, settings, script, printed, override_settings):
|
||||
settings.update(override_settings)
|
||||
CorrectedCommand(script, None, 1000).run(Command())
|
||||
out, _ = capsys.readouterr()
|
||||
assert out[:-1] == printed
|
||||
|
||||
|
||||
class TestRule(object):
|
||||
def test_from_path(self, mocker):
|
||||
|
||||
Reference in New Issue
Block a user