mirror of
https://github.com/nvbn/thefuck.git
synced 2025-10-30 06:34:09 +00:00
Add information about writting yourself rules, revert no_command changes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from subprocess import PIPE
|
||||
from mock import patch, Mock
|
||||
import pytest
|
||||
from thefuck.rules.no_command_apt import match, get_new_command
|
||||
from thefuck.rules.no_command import match, get_new_command
|
||||
from thefuck.main import Command
|
||||
|
||||
|
||||
@@ -21,23 +21,30 @@ vom: command not found
|
||||
|
||||
@pytest.fixture
|
||||
def bins_exists(request):
|
||||
p = patch('thefuck.rules.no_command_apt.which',
|
||||
p = patch('thefuck.rules.no_command.which',
|
||||
return_value=True)
|
||||
p.start()
|
||||
request.addfinalizer(p.stop)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def settings():
|
||||
class _Settings(object):
|
||||
pass
|
||||
return _Settings
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('bins_exists')
|
||||
def test_match(command_found, command_not_found):
|
||||
with patch('thefuck.rules.no_command_apt.Popen') as Popen:
|
||||
def test_match(command_found, command_not_found, settings):
|
||||
with patch('thefuck.rules.no_command.Popen') as Popen:
|
||||
Popen.return_value.stderr.read.return_value = command_found
|
||||
assert match(Command('aptget install vim', '', ''), None)
|
||||
assert match(Command('aptget install vim', '', ''), settings)
|
||||
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', '', ''), None)
|
||||
assert not match(Command('ls', '', ''), settings)
|
||||
|
||||
with patch('thefuck.rules.no_command_apt.Popen') as Popen:
|
||||
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', '', ''),
|
||||
Mock(command_not_found='test'))
|
||||
@@ -47,9 +54,9 @@ def test_match(command_found, command_not_found):
|
||||
|
||||
@pytest.mark.usefixtures('bins_exists')
|
||||
def test_get_new_command(command_found):
|
||||
with patch('thefuck.rules.no_command_apt._get_output',
|
||||
with patch('thefuck.rules.no_command._get_output',
|
||||
return_value=command_found.decode()):
|
||||
assert get_new_command(Command('aptget install vim', '', ''), None)\
|
||||
assert get_new_command(Command('aptget install vim', '', ''), settings)\
|
||||
== 'apt-get install vim'
|
||||
assert get_new_command(Command('sudo aptget install vim', '', ''), None) \
|
||||
assert get_new_command(Command('sudo aptget install vim', '', ''), settings) \
|
||||
== 'sudo apt-get install vim'
|
||||
Reference in New Issue
Block a user