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