2016-02-08 11:04:19 +03:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.grep_arguments_order import get_new_command, match
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2016-02-08 11:04:19 +03:00
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
output = 'grep: {}: No such file or directory'.format
|
2016-02-08 11:04:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def os_path(monkeypatch):
|
|
|
|
monkeypatch.setattr('os.path.isfile', lambda x: not x.startswith('-'))
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('script, file', [
|
|
|
|
('grep test.py test', 'test'),
|
|
|
|
('grep -lir . test', 'test'),
|
|
|
|
('egrep test.py test', 'test'),
|
|
|
|
('egrep -lir . test', 'test')])
|
|
|
|
def test_match(script, file):
|
2017-08-31 17:58:56 +02:00
|
|
|
assert match(Command(script, output(file)))
|
2016-02-08 11:04:19 +03:00
|
|
|
|
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
@pytest.mark.parametrize('script, output', [
|
|
|
|
('cat test.py', output('test')),
|
2016-02-08 11:04:19 +03:00
|
|
|
('grep test test.py', ''),
|
|
|
|
('grep -lir test .', ''),
|
|
|
|
('egrep test test.py', ''),
|
|
|
|
('egrep -lir test .', '')])
|
2017-08-31 17:58:56 +02:00
|
|
|
def test_not_match(script, output):
|
|
|
|
assert not match(Command(script, output))
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('script, output, result', [
|
|
|
|
('grep test.py test', output('test'), 'grep test test.py'),
|
|
|
|
('grep -lir . test', output('test'), 'grep -lir test .'),
|
|
|
|
('grep . test -lir', output('test'), 'grep test -lir .'),
|
|
|
|
('egrep test.py test', output('test'), 'egrep test test.py'),
|
|
|
|
('egrep -lir . test', output('test'), 'egrep -lir test .'),
|
|
|
|
('egrep . test -lir', output('test'), 'egrep test -lir .')])
|
|
|
|
def test_get_new_command(script, output, result):
|
|
|
|
assert get_new_command(Command(script, output)) == result
|