Testing Script Existence Detection Rules in TheFuck Command-Line Tool
This test suite validates the functionality of the ‘has_exists_script’ rule in TheFuck project, which handles cases where commands exist as scripts in the current directory but aren’t properly invoked with ‘./’.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
nvbn/thefuck
tests/rules/test_has_exists_script.py
from mock import patch
from thefuck.rules.has_exists_script import match, get_new_command
from thefuck.types import Command
def test_match():
with patch('os.path.exists', return_value=True):
assert match(Command('main', 'main: command not found'))
assert match(Command('main --help',
'main: command not found'))
assert not match(Command('main', ''))
with patch('os.path.exists', return_value=False):
assert not match(Command('main', 'main: command not found'))
def test_get_new_command():
assert get_new_command(Command('main --help', '')) == './main --help'