mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 10:11:14 +00:00
Adapt the pacman
rule to #324
This commit is contained in:
parent
3ae01ac65d
commit
8374be0872
@ -7,17 +7,13 @@ from tests.utils import Command
|
|||||||
|
|
||||||
pacman_cmd = getattr(pacman, 'pacman', 'pacman')
|
pacman_cmd = getattr(pacman, 'pacman', 'pacman')
|
||||||
|
|
||||||
PKGFILE_OUTPUT_CONVERT = '''
|
PKGFILE_OUTPUT_CONVERT = 'extra/imagemagick 6.9.1.0-1\t/usr/bin/convert'
|
||||||
extra/imagemagick 6.9.1.0-1\t/usr/bin/convert
|
|
||||||
'''
|
|
||||||
|
|
||||||
PKGFILE_OUTPUT_VIM = '''
|
PKGFILE_OUTPUT_VIM = '''extra/gvim 7.4.712-1 \t/usr/bin/vim
|
||||||
extra/gvim 7.4.712-1 \t/usr/bin/vim
|
|
||||||
extra/gvim-python3 7.4.712-1\t/usr/bin/vim
|
extra/gvim-python3 7.4.712-1\t/usr/bin/vim
|
||||||
extra/vim 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
|
extra/vim-minimal 7.4.712-1 \t/usr/bin/vim
|
||||||
extra/vim-python3 7.4.712-1 \t/usr/bin/vim
|
extra/vim-python3 7.4.712-1 \t/usr/bin/vim'''
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
|
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
|
||||||
@ -46,22 +42,37 @@ def test_not_match(command):
|
|||||||
assert not match(command, None)
|
assert not match(command, None)
|
||||||
|
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
|
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
|
||||||
reason='Skip if pacman is not available')
|
reason='Skip if pacman is not available')
|
||||||
@pytest.mark.parametrize('command, new_command', [
|
@pytest.mark.parametrize('command, new_command', [
|
||||||
(Command('vim'), '{} -S extra/gvim && vim'.format(pacman_cmd)),
|
(Command('vim'), vim_possibilities),
|
||||||
(Command('sudo vim'), '{} -S extra/gvim && sudo vim'.format(pacman_cmd)),
|
(Command('sudo vim'), sudo_vim_possibilities),
|
||||||
(Command('convert'), '{} -S extra/imagemagick && convert'.format(pacman_cmd)),
|
(Command('convert'), ['{} -S extra/imagemagick && convert'.format(pacman_cmd)]),
|
||||||
(Command('sudo convert'), '{} -S extra/imagemagick && sudo convert'.format(pacman_cmd))])
|
(Command('sudo convert'), ['{} -S extra/imagemagick && sudo convert'.format(pacman_cmd)])])
|
||||||
def test_get_new_command(command, new_command, mocker):
|
def test_get_new_command(command, new_command, mocker):
|
||||||
assert get_new_command(command, None) == new_command
|
assert get_new_command(command, None) == new_command
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command, new_command, return_value', [
|
@pytest.mark.parametrize('command, new_command, return_value', [
|
||||||
(Command('vim'), '{} -S extra/gvim && vim'.format(pacman_cmd), PKGFILE_OUTPUT_VIM),
|
(Command('vim'), vim_possibilities, PKGFILE_OUTPUT_VIM),
|
||||||
(Command('sudo vim'), '{} -S extra/gvim && sudo vim'.format(pacman_cmd), 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('convert'), ['{} -S extra/imagemagick && convert'.format(pacman_cmd)], PKGFILE_OUTPUT_CONVERT),
|
||||||
(Command('sudo convert'), '{} -S extra/imagemagick && sudo convert'.format(pacman_cmd), PKGFILE_OUTPUT_CONVERT)])
|
(Command('sudo convert'), ['{} -S extra/imagemagick && sudo convert'.format(pacman_cmd)], PKGFILE_OUTPUT_CONVERT)])
|
||||||
@patch('thefuck.rules.pacman.subprocess')
|
@patch('thefuck.rules.pacman.subprocess')
|
||||||
@patch.multiple(pacman, create=True, pacman=pacman_cmd)
|
@patch.multiple(pacman, create=True, pacman=pacman_cmd)
|
||||||
def test_get_new_command_mocked(subp_mock, command, new_command, return_value):
|
def test_get_new_command_mocked(subp_mock, command, new_command, return_value):
|
||||||
|
@ -14,10 +14,12 @@ def __get_pkgfile(command):
|
|||||||
|
|
||||||
command = command.split(" ")[0]
|
command = command.split(" ")[0]
|
||||||
|
|
||||||
return subprocess.check_output(
|
packages = subprocess.check_output(
|
||||||
['pkgfile', '-b', '-v', command],
|
['pkgfile', '-b', '-v', command],
|
||||||
universal_newlines=True, stderr=DEVNULL
|
universal_newlines=True, stderr=DEVNULL
|
||||||
).split()
|
).splitlines()
|
||||||
|
|
||||||
|
return [package.split()[0] for package in packages]
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -27,10 +29,11 @@ def match(command, settings):
|
|||||||
|
|
||||||
|
|
||||||
def get_new_command(command, settings):
|
def get_new_command(command, settings):
|
||||||
package = __get_pkgfile(command)[0]
|
packages = __get_pkgfile(command)
|
||||||
|
|
||||||
formatme = shells.and_('{} -S {}', '{}')
|
formatme = shells.and_('{} -S {}', '{}')
|
||||||
return formatme.format(pacman, package, command.script)
|
return [formatme.format(pacman, package, command.script)
|
||||||
|
for package in packages]
|
||||||
|
|
||||||
|
|
||||||
if not which('pkgfile'):
|
if not which('pkgfile'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user