1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-10-30 14:44:05 +00:00

Pass settings to the rules

This commit is contained in:
nvbn
2015-04-08 21:08:35 +02:00
parent 173a4300b4
commit 9ed022d67f
8 changed files with 50 additions and 47 deletions

View File

@@ -14,11 +14,11 @@ To push the current branch and set the remote as upstream, use
def test_match(stderr):
assert match(Command('git push master', '', stderr))
assert not match(Command('git push master', '', ''))
assert not match(Command('ls', '', stderr))
assert match(Command('git push master', '', stderr), None)
assert not match(Command('git push master', '', ''), None)
assert not match(Command('ls', '', stderr), None)
def test_get_new_command(stderr):
assert get_new_command(Command('', '', stderr))\
assert get_new_command(Command('', '', stderr), None)\
== "git push --set-upstream origin master"

View File

@@ -1,4 +1,4 @@
from unittest.mock import patch
from unittest.mock import patch, Mock
import pytest
from subprocess import PIPE
from thefuck.rules.no_command import match, get_new_command
@@ -22,23 +22,24 @@ vom: command not found
def test_match(command_found, command_not_found):
with patch('thefuck.rules.no_command.Popen') as Popen:
Popen.return_value.stderr.read.return_value = command_found
assert match(Command('aptget install vim', '', ''))
assert match(Command('aptget install vim', '', ''), None)
Popen.assert_called_once_with('/usr/lib/command-not-found aptget',
shell=True, stderr=PIPE)
Popen.return_value.stderr.read.return_value = command_not_found
assert not match(Command('ls', '', ''))
assert not match(Command('ls', '', ''), None)
with patch('thefuck.rules.no_command.Popen') as Popen:
Popen.return_value.stderr.read.return_value = command_found
assert match(Command('sudo aptget install vim', '', ''))
Popen.assert_called_once_with('/usr/lib/command-not-found aptget',
assert match(Command('sudo aptget install vim', '', ''),
Mock(command_not_found='test'))
Popen.assert_called_once_with('test aptget',
shell=True, stderr=PIPE)
def test_get_new_command(command_found):
with patch('thefuck.rules.no_command._get_output',
return_value=command_found.decode()):
assert get_new_command(Command('aptget install vim', '', ''))\
assert get_new_command(Command('aptget install vim', '', ''), None)\
== 'apt-get install vim'
assert get_new_command(Command('sudo aptget install vim', '', '')) \
assert get_new_command(Command('sudo aptget install vim', '', ''), None) \
== 'sudo apt-get install vim'

View File

@@ -3,11 +3,11 @@ from thefuck.rules.sudo import match, get_new_command
def test_match():
assert match(Command('', '', 'Permission denied'))
assert match(Command('', '', 'permission denied'))
assert match(Command('', '', "npm ERR! Error: EACCES, unlink"))
assert not match(Command('', '', ''))
assert match(Command('', '', 'Permission denied'), None)
assert match(Command('', '', 'permission denied'), None)
assert match(Command('', '', "npm ERR! Error: EACCES, unlink"), None)
assert not match(Command('', '', ''), None)
def test_get_new_command():
assert get_new_command(Command('ls', '', '')) == 'sudo ls'
assert get_new_command(Command('ls', '', ''), None) == 'sudo ls'