2015-05-14 17:34:40 -03:00
|
|
|
import pytest
|
|
|
|
from mock import patch
|
|
|
|
from thefuck.rules import pacman
|
|
|
|
from thefuck.rules.pacman import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2015-05-14 17:34:40 -03:00
|
|
|
|
|
|
|
|
|
|
|
pacman_cmd = getattr(pacman, 'pacman', 'pacman')
|
|
|
|
|
2015-08-12 17:13:32 +02:00
|
|
|
PKGFILE_OUTPUT_SUDO = 'core/sudo 1.8.13-13/usr/bin/sudo'
|
2015-07-31 21:41:49 +02:00
|
|
|
PKGFILE_OUTPUT_CONVERT = 'extra/imagemagick 6.9.1.0-1\t/usr/bin/convert'
|
2015-05-17 20:35:06 +02:00
|
|
|
|
2015-07-31 21:41:49 +02:00
|
|
|
PKGFILE_OUTPUT_VIM = '''extra/gvim 7.4.712-1 \t/usr/bin/vim
|
2015-05-17 20:35:06 +02:00
|
|
|
extra/gvim-python3 7.4.712-1\t/usr/bin/vim
|
|
|
|
extra/vim 7.4.712-1 \t/usr/bin/vim
|
|
|
|
extra/vim-minimal 7.4.712-1 \t/usr/bin/vim
|
2015-07-31 21:41:49 +02:00
|
|
|
extra/vim-python3 7.4.712-1 \t/usr/bin/vim'''
|
2015-05-17 20:35:06 +02:00
|
|
|
|
2015-05-14 17:34:40 -03:00
|
|
|
|
|
|
|
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
|
|
|
|
reason='Skip if pacman is not available')
|
|
|
|
@pytest.mark.parametrize('command', [
|
2017-08-31 17:58:56 +02:00
|
|
|
Command('vim', 'vim: command not found'),
|
|
|
|
Command('sudo vim', 'sudo: vim: command not found')])
|
2015-05-14 17:34:40 -03:00
|
|
|
def test_match(command):
|
2015-09-07 13:00:29 +03:00
|
|
|
assert match(command)
|
2015-05-14 17:34:40 -03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('command, return_value', [
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('vim', 'vim: command not found'), PKGFILE_OUTPUT_VIM),
|
|
|
|
(Command('sudo vim', 'sudo: vim: command not found'), PKGFILE_OUTPUT_VIM)])
|
2015-08-25 14:09:47 +03:00
|
|
|
@patch('thefuck.specific.archlinux.subprocess')
|
2015-05-14 17:34:40 -03:00
|
|
|
@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
|
2015-09-07 13:00:29 +03:00
|
|
|
assert match(command)
|
2015-05-14 17:34:40 -03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('command', [
|
2017-08-31 17:58:56 +02:00
|
|
|
Command('vim', ''), Command('', ''),
|
|
|
|
Command('sudo vim', ''), Command('', '')])
|
2015-05-14 17:34:40 -03:00
|
|
|
def test_not_match(command):
|
2015-09-07 13:00:29 +03:00
|
|
|
assert not match(command)
|
2015-05-14 17:34:40 -03:00
|
|
|
|
|
|
|
|
2015-07-31 21:41:49 +02:00
|
|
|
sudo_vim_possibilities = ['{} -S extra/gvim && sudo vim',
|
|
|
|
'{} -S extra/gvim-python3 && sudo vim',
|
|
|
|
'{} -S extra/vim && sudo vim',
|
|
|
|
'{} -S extra/vim-minimal && sudo vim',
|
|
|
|
'{} -S extra/vim-python3 && sudo vim']
|
|
|
|
sudo_vim_possibilities = [s.format(pacman_cmd) for s in sudo_vim_possibilities]
|
|
|
|
|
|
|
|
vim_possibilities = ['{} -S extra/gvim && vim',
|
|
|
|
'{} -S extra/gvim-python3 && vim',
|
|
|
|
'{} -S extra/vim && vim',
|
|
|
|
'{} -S extra/vim-minimal && vim',
|
|
|
|
'{} -S extra/vim-python3 && vim']
|
|
|
|
vim_possibilities = [s.format(pacman_cmd) for s in vim_possibilities]
|
|
|
|
|
|
|
|
|
2015-05-14 17:34:40 -03:00
|
|
|
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
|
|
|
|
reason='Skip if pacman is not available')
|
|
|
|
@pytest.mark.parametrize('command, new_command', [
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('vim', ''), vim_possibilities),
|
|
|
|
(Command('sudo vim', ''), sudo_vim_possibilities),
|
|
|
|
(Command('convert', ''), ['{} -S extra/imagemagick && convert'.format(pacman_cmd)]),
|
|
|
|
(Command('sudo convert', ''), ['{} -S extra/imagemagick && sudo convert'.format(pacman_cmd)])])
|
2015-05-14 17:34:40 -03:00
|
|
|
def test_get_new_command(command, new_command, mocker):
|
2015-09-07 13:00:29 +03:00
|
|
|
assert get_new_command(command) == new_command
|
2015-05-14 17:34:40 -03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('command, new_command, return_value', [
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('vim', ''), vim_possibilities, PKGFILE_OUTPUT_VIM),
|
|
|
|
(Command('sudo vim', ''), sudo_vim_possibilities, PKGFILE_OUTPUT_VIM),
|
|
|
|
(Command('convert', ''), ['{} -S extra/imagemagick && convert'.format(pacman_cmd)], PKGFILE_OUTPUT_CONVERT),
|
|
|
|
(Command('sudo', ''), ['{} -S core/sudo && sudo'.format(pacman_cmd)], PKGFILE_OUTPUT_SUDO),
|
|
|
|
(Command('sudo convert', ''), ['{} -S extra/imagemagick && sudo convert'.format(pacman_cmd)], PKGFILE_OUTPUT_CONVERT)])
|
2015-08-25 14:09:47 +03:00
|
|
|
@patch('thefuck.specific.archlinux.subprocess')
|
2015-05-14 17:34:40 -03:00
|
|
|
@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
|
2015-09-07 13:00:29 +03:00
|
|
|
assert get_new_command(command) == new_command
|