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
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2015-04-08 18:15:49 +02:00
|
|
|
|
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
@pytest.mark.parametrize('output', [
|
|
|
|
'Permission denied',
|
|
|
|
'permission denied',
|
|
|
|
"npm ERR! Error: EACCES, unlink",
|
|
|
|
'requested operation requires superuser privilege',
|
|
|
|
'need to be root',
|
|
|
|
'need root',
|
2022-05-29 22:40:31 +03:00
|
|
|
'shutdown: NOT super-user',
|
|
|
|
'Error: This command has to be run with superuser privileges (under the root user on most systems).',
|
2022-06-05 22:58:31 +02:00
|
|
|
'updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db',
|
2017-08-31 17:58:56 +02:00
|
|
|
'must be root',
|
|
|
|
'You don\'t have access to the history DB.',
|
|
|
|
"error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/ipaddr.py'"])
|
|
|
|
def test_match(output):
|
|
|
|
assert match(Command('', output))
|
2015-04-25 02:54:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_not_match():
|
2017-08-31 17:58:56 +02:00
|
|
|
assert not match(Command('', ''))
|
|
|
|
assert not match(Command('sudo ls', '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):
|
2017-08-31 17:58:56 +02:00
|
|
|
assert get_new_command(Command(before, '')) == after
|