forked from nvbn/thefuck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a rule to delete sudo for pacaur. (nvbn#787)
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
from thefuck.rules.unsudo import match, get_new_command | ||
from thefuck.types import Command | ||
|
||
|
||
@pytest.mark.parametrize('output', [ | ||
'you cannot perform this operation as root']) | ||
def test_match(output): | ||
assert match(Command('sudo ls', output)) | ||
|
||
|
||
def test_not_match(): | ||
assert not match(Command('', '')) | ||
assert not match(Command('sudo ls', 'Permission denied')) | ||
assert not match(Command('ls', 'you cannot perform this operation as root')) | ||
|
||
|
||
@pytest.mark.parametrize('before, after', [ | ||
('sudo ls', 'ls'), | ||
('sudo pacaur -S helloworld', 'pacaur -S helloworld')]) | ||
def test_get_new_command(before, after): | ||
assert get_new_command(Command(before, '')) == after |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
patterns = ['you cannot perform this operation as root'] | ||
|
||
|
||
def match(command): | ||
if command.script_parts and command.script_parts[0] != 'sudo': | ||
return False | ||
|
||
for pattern in patterns: | ||
if pattern in command.output.lower(): | ||
return True | ||
return False | ||
|
||
|
||
def get_new_command(command): | ||
return ' '.join(command.script_parts[1:]) |