1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-06 02:41:10 +01:00
thefuck/tests/rules/test_apt_get.py

54 lines
2.2 KiB
Python
Raw Normal View History

import pytest
from thefuck.rules.apt_get import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command, packages', [
(Command('vim', 'vim: command not found'),
[('vim', 'main'), ('vim-tiny', 'main')]),
(Command('sudo vim', 'vim: command not found'),
[('vim', 'main'), ('vim-tiny', 'main')]),
(Command('vim', "The program 'vim' is currently not installed. You can install it by typing: sudo apt install vim"),
[('vim', 'main'), ('vim-tiny', 'main')])])
def test_match(mocker, command, packages):
mocker.patch('thefuck.rules.apt_get.which', return_value=None)
2018-02-23 20:15:05 +00:00
mocker.patch('thefuck.rules.apt_get._get_packages',
create=True, return_value=packages)
assert match(command)
@pytest.mark.parametrize('command, packages, which', [
(Command('a_bad_cmd', 'a_bad_cmd: command not found'),
[], None),
(Command('vim', ''), [], None),
(Command('', ''), [], None),
(Command('vim', 'vim: command not found'),
['vim'], '/usr/bin/vim'),
(Command('sudo vim', 'vim: command not found'),
['vim'], '/usr/bin/vim')])
def test_not_match(mocker, command, packages, which):
mocker.patch('thefuck.rules.apt_get.which', return_value=which)
2018-02-23 20:15:05 +00:00
mocker.patch('thefuck.rules.apt_get._get_packages',
create=True, return_value=packages)
2016-01-31 21:43:24 +00:00
assert not match(command)
@pytest.mark.parametrize('command, new_command, packages', [
(Command('vim', ''), 'sudo apt-get install vim && vim',
[('vim', 'main'), ('vim-tiny', 'main')]),
(Command('convert', ''), 'sudo apt-get install imagemagick && convert',
[('imagemagick', 'main'),
('graphicsmagick-imagemagick-compat', 'universe')]),
(Command('sudo vim', ''), 'sudo apt-get install vim && sudo vim',
[('vim', 'main'), ('vim-tiny', 'main')]),
(Command('sudo convert', ''), 'sudo apt-get install imagemagick && sudo convert',
[('imagemagick', 'main'),
('graphicsmagick-imagemagick-compat', 'universe')])])
def test_get_new_command(mocker, command, new_command, packages):
2018-02-23 20:15:05 +00:00
mocker.patch('thefuck.rules.apt_get._get_packages',
create=True, return_value=packages)
assert get_new_command(command) == new_command