mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 10:11:14 +00:00
Test if the file exists in the fix_file
rule
This avoid false positives in `match`.
This commit is contained in:
parent
de513cacb1
commit
43fead02d3
@ -158,19 +158,29 @@ ReferenceError: conole is not defined
|
||||
|
||||
|
||||
@pytest.mark.parametrize('test', tests)
|
||||
def test_match(monkeypatch, test):
|
||||
def test_match(mocker, monkeypatch, test):
|
||||
mocker.patch('os.path.isfile', return_value=True)
|
||||
monkeypatch.setenv('EDITOR', 'dummy_editor')
|
||||
assert match(Command(stderr=test[4]), None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('test', tests)
|
||||
def test_not_match(monkeypatch, test):
|
||||
def test_no_editor(mocker, monkeypatch, test):
|
||||
mocker.patch('os.path.isfile', return_value=True)
|
||||
if 'EDITOR' in os.environ:
|
||||
monkeypatch.delenv('EDITOR')
|
||||
|
||||
assert not match(Command(stderr=test[4]), None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('test', tests)
|
||||
def test_not_file(mocker, monkeypatch, test):
|
||||
mocker.patch('os.path.isfile', return_value=False)
|
||||
monkeypatch.setenv('EDITOR', 'dummy_editor')
|
||||
|
||||
assert not match(Command(stderr=test[4]), None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('test', tests)
|
||||
def test_get_new_command(monkeypatch, test):
|
||||
monkeypatch.setenv('EDITOR', 'dummy_editor')
|
||||
|
@ -50,7 +50,12 @@ def _search(stderr):
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
return 'EDITOR' in os.environ and _search(command.stderr)
|
||||
if 'EDITOR' not in os.environ:
|
||||
return False
|
||||
|
||||
m = _search(command.stderr)
|
||||
|
||||
return m and os.path.isfile(m.group('file'))
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
|
Loading…
x
Reference in New Issue
Block a user