Testing Grep Argument Order Correction in TheFuck
This test suite validates the functionality of grep argument order correction in TheFuck, a command-line tool that fixes mistyped console commands. It ensures proper handling of grep pattern and file arguments when users accidentally swap their positions.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
nvbn/thefuck
tests/rules/test_grep_arguments_order.py
import pytest
from thefuck.rules.grep_arguments_order import get_new_command, match
from thefuck.types import Command
output = 'grep: {}: No such file or directory'.format
@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):
assert match(Command(script, output(file)))
@pytest.mark.parametrize('script, output', [
('cat test.py', output('test')),
('grep test test.py', ''),
('grep -lir test .', ''),
('egrep test test.py', ''),
('egrep -lir test .', '')])
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