mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-14 14:50:51 +01:00
#1 s/last_script/last_command/, s/last_fixed_script/last_fixed_command/
This commit is contained in:
parent
dd1861955c
commit
2acfea3350
@ -27,16 +27,16 @@ class TestHistory(object):
|
|||||||
|
|
||||||
def test_set(self, db):
|
def test_set(self, db):
|
||||||
history = History()
|
history = History()
|
||||||
history.update(last_script='ls',
|
history.update(last_command='ls',
|
||||||
last_fixed_script=None)
|
last_fixed_command=None)
|
||||||
assert db == {'1-last_script': 'ls',
|
assert db == {'1-last_command': 'ls',
|
||||||
'1-last_fixed_script': None}
|
'1-last_fixed_command': None}
|
||||||
|
|
||||||
def test_get(self, db):
|
def test_get(self, db):
|
||||||
history = History()
|
history = History()
|
||||||
db['1-last_script'] = 'cd ..'
|
db['1-last_command'] = 'cd ..'
|
||||||
assert history.last_script == 'cd ..'
|
assert history.last_command == 'cd ..'
|
||||||
|
|
||||||
def test_get_without_value(self):
|
def test_get_without_value(self):
|
||||||
history = History()
|
history = History()
|
||||||
assert history.last_script is None
|
assert history.last_command is None
|
||||||
|
@ -62,13 +62,13 @@ class TestGetCommand(object):
|
|||||||
|
|
||||||
@pytest.mark.parametrize('history, args, result', [
|
@pytest.mark.parametrize('history, args, result', [
|
||||||
(Mock(), [''], None),
|
(Mock(), [''], None),
|
||||||
(Mock(last_script='ls', last_fixed_script='ls -la'),
|
(Mock(last_command='ls', last_fixed_command='ls -la'),
|
||||||
['thefuck', 'fuck'], 'ls -la'),
|
['thefuck', 'fuck'], 'ls -la'),
|
||||||
(Mock(last_script='ls', last_fixed_script='ls -la'),
|
(Mock(last_command='ls', last_fixed_command='ls -la'),
|
||||||
['thefuck', 'ls'], 'ls -la'),
|
['thefuck', 'ls'], 'ls -la'),
|
||||||
(Mock(last_script='ls', last_fixed_script=''),
|
(Mock(last_command='ls', last_fixed_command=''),
|
||||||
['thefuck', 'ls'], 'ls'),
|
['thefuck', 'ls'], 'ls'),
|
||||||
(Mock(last_script='ls', last_fixed_script=''),
|
(Mock(last_command='ls', last_fixed_command=''),
|
||||||
['thefuck', 'fuck'], 'ls')])
|
['thefuck', 'fuck'], 'ls')])
|
||||||
def test_get_command_script(self, history, args, result):
|
def test_get_command_script(self, history, args, result):
|
||||||
if result:
|
if result:
|
||||||
@ -127,8 +127,8 @@ class TestRunRule(object):
|
|||||||
history = Mock()
|
history = Mock()
|
||||||
main.run_rule(Rule(get_new_command=lambda *_: 'ls -lah'),
|
main.run_rule(Rule(get_new_command=lambda *_: 'ls -lah'),
|
||||||
Command('ls'), history, None)
|
Command('ls'), history, None)
|
||||||
history.update.assert_called_once_with(last_script='ls',
|
history.update.assert_called_once_with(last_command='ls',
|
||||||
last_fixed_script='ls -lah')
|
last_fixed_command='ls -lah')
|
||||||
|
|
||||||
def test_when_not_comfirmed(self, capsys, confirm):
|
def test_when_not_comfirmed(self, capsys, confirm):
|
||||||
confirm.return_value = False
|
confirm.return_value = False
|
||||||
|
@ -67,14 +67,14 @@ def get_command(settings, history, args):
|
|||||||
else:
|
else:
|
||||||
script = ' '.join(args[1:])
|
script = ' '.join(args[1:])
|
||||||
|
|
||||||
if script == 'fuck' or script == history.last_script:
|
if script == 'fuck' or script == history.last_command:
|
||||||
script = history.last_fixed_script or history.last_script
|
script = history.last_fixed_command or history.last_command
|
||||||
|
|
||||||
if not script:
|
if not script:
|
||||||
return
|
return
|
||||||
|
|
||||||
history.update(last_script=script,
|
history.update(last_command=script,
|
||||||
last_fixed_script=None)
|
last_fixed_command=None)
|
||||||
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE,
|
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE,
|
||||||
env=dict(os.environ, LANG='C'))
|
env=dict(os.environ, LANG='C'))
|
||||||
if wait_output(settings, result):
|
if wait_output(settings, result):
|
||||||
@ -113,8 +113,8 @@ def run_rule(rule, command, history, settings):
|
|||||||
if confirm(new_command, rule.side_effect, settings):
|
if confirm(new_command, rule.side_effect, settings):
|
||||||
if rule.side_effect:
|
if rule.side_effect:
|
||||||
rule.side_effect(command, settings)
|
rule.side_effect(command, settings)
|
||||||
history.update(last_script=command.script,
|
history.update(last_command=command.script,
|
||||||
last_fixed_script=new_command)
|
last_fixed_command=new_command)
|
||||||
print(new_command)
|
print(new_command)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user