mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 18:21:10 +00:00
179839c32f
Signed-off-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
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
|