2015-04-25 02:54:39 +02:00
|
|
|
import pytest
|
2015-04-08 18:15:49 +02:00
|
|
|
from thefuck.rules.sudo import match, get_new_command
|
2015-04-25 02:35:26 +02:00
|
|
|
from tests.utils import Command
|
2015-04-08 18:15:49 +02:00
|
|
|
|
|
|
|
|
2015-04-29 05:01:30 +02:00
|
|
|
@pytest.mark.parametrize('stderr, stdout', [
|
|
|
|
('Permission denied', ''),
|
|
|
|
('permission denied', ''),
|
|
|
|
("npm ERR! Error: EACCES, unlink", ''),
|
|
|
|
('requested operation requires superuser privilege', ''),
|
2015-06-15 17:08:08 -07:00
|
|
|
('need to be root', ''),
|
|
|
|
('need root', ''),
|
|
|
|
('must be root', ''),
|
2015-07-21 06:49:56 +00:00
|
|
|
('You don\'t have access to the history DB.', ''),
|
2015-04-29 05:01:30 +02:00
|
|
|
('', "error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/ipaddr.py'")])
|
|
|
|
def test_match(stderr, stdout):
|
2015-09-07 13:00:29 +03:00
|
|
|
assert match(Command(stderr=stderr, stdout=stdout))
|
2015-04-25 02:54:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_not_match():
|
2015-09-07 13:00:29 +03:00
|
|
|
assert not match(Command())
|
2015-12-11 07:41:13 +08:00
|
|
|
assert not match(Command(script='sudo ls', stderr='Permission denied'))
|
2015-04-08 18:15:49 +02:00
|
|
|
|
|
|
|
|
2015-08-11 01:15:05 +03:00
|
|
|
@pytest.mark.parametrize('before, after', [
|
|
|
|
('ls', 'sudo ls'),
|
|
|
|
('echo a > b', 'sudo sh -c "echo a > b"'),
|
2015-12-23 14:35:47 +05:30
|
|
|
('echo "a" >> b', 'sudo sh -c "echo \\"a\\" >> b"'),
|
|
|
|
('mkdir && touch a', 'sudo sh -c "mkdir && touch a"')])
|
2015-08-11 01:15:05 +03:00
|
|
|
def test_get_new_command(before, after):
|
2015-09-07 13:00:29 +03:00
|
|
|
assert get_new_command(Command(before)) == after
|