2015-05-14 17:34:40 -03:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.apt_get 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
|
|
|
|
|
|
|
|
2016-08-13 15:30:57 +03:00
|
|
|
@pytest.mark.parametrize('command, packages', [
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('vim', 'vim: command not found'),
|
2015-08-13 17:44:42 +02:00
|
|
|
[('vim', 'main'), ('vim-tiny', 'main')]),
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('sudo vim', 'vim: command not found'),
|
2017-01-29 00:15:55 +01:00
|
|
|
[('vim', 'main'), ('vim-tiny', 'main')]),
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('vim', "The program 'vim' is currently not installed. You can install it by typing: sudo apt install vim"),
|
2015-05-14 17:34:40 -03:00
|
|
|
[('vim', 'main'), ('vim-tiny', 'main')])])
|
2016-08-13 15:30:57 +03:00
|
|
|
def test_match(mocker, command, packages):
|
|
|
|
mocker.patch('thefuck.rules.apt_get.which', return_value=None)
|
2018-02-23 21:15:05 +01:00
|
|
|
mocker.patch('thefuck.rules.apt_get._get_packages',
|
|
|
|
create=True, return_value=packages)
|
2015-05-14 17:34:40 -03:00
|
|
|
|
2016-08-13 15:30:57 +03:00
|
|
|
assert match(command)
|
2015-05-14 17:34:40 -03:00
|
|
|
|
|
|
|
|
2016-08-13 15:30:57 +03:00
|
|
|
@pytest.mark.parametrize('command, packages, which', [
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('a_bad_cmd', 'a_bad_cmd: command not found'),
|
2016-08-13 15:30:57 +03:00
|
|
|
[], None),
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('vim', ''), [], None),
|
|
|
|
(Command('', ''), [], None),
|
|
|
|
(Command('vim', 'vim: command not found'),
|
2016-08-13 15:30:57 +03:00
|
|
|
['vim'], '/usr/bin/vim'),
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('sudo vim', 'vim: command not found'),
|
2016-08-13 15:30:57 +03:00
|
|
|
['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 21:15:05 +01:00
|
|
|
mocker.patch('thefuck.rules.apt_get._get_packages',
|
|
|
|
create=True, return_value=packages)
|
2015-05-14 17:34:40 -03:00
|
|
|
|
2016-01-31 19:43:24 -02:00
|
|
|
assert not match(command)
|
|
|
|
|
|
|
|
|
2016-08-13 15:30:57 +03:00
|
|
|
@pytest.mark.parametrize('command, new_command, packages', [
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('vim', ''), 'sudo apt-get install vim && vim',
|
2015-05-14 17:34:40 -03:00
|
|
|
[('vim', 'main'), ('vim-tiny', 'main')]),
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('convert', ''), 'sudo apt-get install imagemagick && convert',
|
2015-08-13 17:44:42 +02:00
|
|
|
[('imagemagick', 'main'),
|
|
|
|
('graphicsmagick-imagemagick-compat', 'universe')]),
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('sudo vim', ''), 'sudo apt-get install vim && sudo vim',
|
2015-08-13 17:44:42 +02:00
|
|
|
[('vim', 'main'), ('vim-tiny', 'main')]),
|
2017-08-31 17:58:56 +02:00
|
|
|
(Command('sudo convert', ''), 'sudo apt-get install imagemagick && sudo convert',
|
2015-05-14 17:34:40 -03:00
|
|
|
[('imagemagick', 'main'),
|
|
|
|
('graphicsmagick-imagemagick-compat', 'universe')])])
|
2016-08-13 15:30:57 +03:00
|
|
|
def test_get_new_command(mocker, command, new_command, packages):
|
2018-02-23 21:15:05 +01:00
|
|
|
mocker.patch('thefuck.rules.apt_get._get_packages',
|
|
|
|
create=True, return_value=packages)
|
|
|
|
|
2015-09-07 13:00:29 +03:00
|
|
|
assert get_new_command(command) == new_command
|