mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
#N/A: Add prove_recursively
rule
This commit is contained in:
parent
e658f35bd9
commit
a906a751c8
@ -244,6 +244,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
||||
* `pip_unknown_command` – fixes wrong `pip` commands, for example `pip instatl/pip install`;
|
||||
* `php_s` – replaces `-s` by `-S` when trying to run a local php server;
|
||||
* `port_already_in_use` – kills process that bound port;
|
||||
* `prove_recursively` – adds `-r` when called with directory;
|
||||
* `python_command` – prepends `python` when you trying to run not executable/without `./` python script;
|
||||
* `python_execute` – appends missing `.py` when executing Python files;
|
||||
* `quotation_marks` – fixes uneven usage of `'` and `"` when containing args';
|
||||
|
40
tests/rules/test_prove_recursively.py
Normal file
40
tests/rules/test_prove_recursively.py
Normal file
@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
from thefuck.rules.prove_recursively import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
output = '''Files=0, Tests=0, 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)
|
||||
Result: NOTESTS'''
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def isdir(mocker):
|
||||
return mocker.patch('thefuck.rules.prove_recursively'
|
||||
'.os.path.isdir')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, output', [
|
||||
('prove -lv t', output),
|
||||
('prove app/t', output)])
|
||||
def test_match(isdir, script, output):
|
||||
isdir.return_value = True
|
||||
command = Command(script, output)
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, output, isdir_result', [
|
||||
('prove -lv t', output, False),
|
||||
('prove -r t', output, True),
|
||||
('prove --recurse t', output, True)])
|
||||
def test_not_match(isdir, script, output, isdir_result):
|
||||
isdir.return_value = isdir_result
|
||||
command = Command(script, output)
|
||||
assert not match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('before, after', [
|
||||
('prove -lv t', 'prove -r -lv t'),
|
||||
('prove t', 'prove -r t')])
|
||||
def test_get_new_command(before, after):
|
||||
command = Command(before, output)
|
||||
assert get_new_command(command) == after
|
27
thefuck/rules/prove_recursively.py
Normal file
27
thefuck/rules/prove_recursively.py
Normal file
@ -0,0 +1,27 @@
|
||||
import os
|
||||
from thefuck.utils import for_app
|
||||
|
||||
|
||||
def _is_recursive(part):
|
||||
if part == '--recurse':
|
||||
return True
|
||||
elif not part.startswith('--') and part.startswith('-') and 'r' in part:
|
||||
return True
|
||||
|
||||
|
||||
def _isdir(part):
|
||||
return not part.startswith('-') and os.path.isdir(part)
|
||||
|
||||
|
||||
@for_app('prove')
|
||||
def match(command):
|
||||
return (
|
||||
'NOTESTS' in command.stdout
|
||||
and not any(_is_recursive(part) for part in command.script_parts[1:])
|
||||
and any(_isdir(part) for part in command.script_parts[1:]))
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
parts = command.script_parts[:]
|
||||
parts.insert(1, '-r')
|
||||
return u' '.join(parts)
|
Loading…
x
Reference in New Issue
Block a user