mirror of
https://github.com/nvbn/thefuck.git
synced 2025-09-28 08:02:33 +01:00
test(rules): test other rules involving shells.and_()
Signed-off-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
This commit is contained in:
53
tests/rules/test_pacman.py
Normal file
53
tests/rules/test_pacman.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
from mock import patch
|
||||
from thefuck.rules import pacman
|
||||
from thefuck.rules.pacman import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
pacman_cmd = getattr(pacman, 'pacman', 'pacman')
|
||||
|
||||
|
||||
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
|
||||
reason='Skip if pacman is not available')
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='vim', stderr='vim: command not found')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, return_value', [
|
||||
(Command(script='vim', stderr='vim: command not found'), 'vim foo bar')])
|
||||
@patch('thefuck.rules.pacman.subprocess')
|
||||
@patch.multiple(pacman, create=True, pacman=pacman_cmd)
|
||||
def test_match_mocked(subp_mock, command, return_value):
|
||||
subp_mock.check_output.return_value = return_value
|
||||
assert match(command, None)
|
||||
assert subp_mock.check_output.called
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='vim', stderr=''), Command()])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
|
||||
reason='Skip if pacman is not available')
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('vim'), '{} -S vim && vim'.format(pacman_cmd)),
|
||||
(Command('convert'), '{} -S imagemagick && convert'.format(pacman_cmd))])
|
||||
def test_get_new_command(command, new_command, mocker):
|
||||
assert get_new_command(command, None) == new_command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command, return_value', [
|
||||
(Command('vim'), '{} -S vim && vim'.format(pacman_cmd), 'vim foo bar'),
|
||||
(Command('convert'), '{} -S imagemagick && convert'.format(pacman_cmd),
|
||||
'imagemagick foo bar')])
|
||||
@patch('thefuck.rules.pacman.subprocess')
|
||||
@patch.multiple(pacman, create=True, pacman=pacman_cmd)
|
||||
def test_get_new_command_mocked(subp_mock, command, new_command, return_value):
|
||||
subp_mock.check_output.return_value = return_value
|
||||
assert get_new_command(command, None) == new_command
|
||||
assert subp_mock.check_output.called
|
Reference in New Issue
Block a user