mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 09:39:01 +00:00
use fixtures and regex
This commit is contained in:
parent
f2d8f6ef86
commit
b40b84b3d3
@ -1,9 +1,12 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
from thefuck.rules.git_lfs_mistype import match, get_new_command
|
from thefuck.rules.git_lfs_mistype import match, get_new_command
|
||||||
from thefuck.types import Command
|
from thefuck.types import Command
|
||||||
|
|
||||||
|
|
||||||
def test_match():
|
@pytest.fixture
|
||||||
err_response = """
|
def mistype_response():
|
||||||
|
return """
|
||||||
Error: unknown command "evn" for "git-lfs"
|
Error: unknown command "evn" for "git-lfs"
|
||||||
|
|
||||||
Did you mean this?
|
Did you mean this?
|
||||||
@ -12,51 +15,15 @@ Did you mean this?
|
|||||||
|
|
||||||
Run 'git-lfs --help' for usage.
|
Run 'git-lfs --help' for usage.
|
||||||
"""
|
"""
|
||||||
assert match(Command('git lfs evn', err_response))
|
|
||||||
|
|
||||||
|
|
||||||
def test_not_match():
|
def test_match(mistype_response):
|
||||||
|
assert match(Command('git lfs evn', mistype_response))
|
||||||
err_response = 'bash: git: command not found'
|
err_response = 'bash: git: command not found'
|
||||||
assert not match(Command('git lfs env', err_response))
|
assert not match(Command('git lfs env', err_response))
|
||||||
|
assert not match(Command('docker lfs env', mistype_response))
|
||||||
|
|
||||||
|
|
||||||
def test_not_git_command():
|
def test_get_new_command(mistype_response):
|
||||||
err_response = """
|
assert (get_new_command(Command('git lfs evn', mistype_response))
|
||||||
Error: unknown command "evn" for "git-lfs"
|
== ['git lfs env', 'git lfs ext'])
|
||||||
|
|
||||||
Did you mean this?
|
|
||||||
env
|
|
||||||
ext
|
|
||||||
|
|
||||||
Run 'git-lfs --help' for usage.
|
|
||||||
"""
|
|
||||||
assert not match(Command('docker lfs env', err_response))
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_new_command():
|
|
||||||
err_response = """
|
|
||||||
Error: unknown command "evn" for "git-lfs"
|
|
||||||
|
|
||||||
Did you mean this?
|
|
||||||
env
|
|
||||||
ext
|
|
||||||
|
|
||||||
Run 'git-lfs --help' for usage.
|
|
||||||
"""
|
|
||||||
result = get_new_command(Command('git lfs evn', err_response))
|
|
||||||
expected = 'git lfs env'
|
|
||||||
assert result == expected
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_another_new_command():
|
|
||||||
err_response = """
|
|
||||||
Error: unknown command "chekout" for "git-lfs"
|
|
||||||
|
|
||||||
Did you mean this?
|
|
||||||
checkout
|
|
||||||
|
|
||||||
Run 'git-lfs --help' for usage.
|
|
||||||
"""
|
|
||||||
result = get_new_command(Command('git lfs chekout', err_response))
|
|
||||||
expected = 'git lfs checkout'
|
|
||||||
assert result == expected
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from thefuck.shells import shell
|
import re
|
||||||
|
from thefuck.utils import get_all_matched_commands, replace_command
|
||||||
from thefuck.specific.git import git_support
|
from thefuck.specific.git import git_support
|
||||||
|
|
||||||
|
|
||||||
@ -12,7 +13,6 @@ def match(command):
|
|||||||
|
|
||||||
@git_support
|
@git_support
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
new = command.script.split(' ')
|
broken_cmd = re.findall(r'Error: unknown command "([^"]*)" for "git-lfs"', command.output)[0]
|
||||||
recommended = command.output.split('\n')[4].strip()
|
matched = get_all_matched_commands(command.output, ['Did you mean'])
|
||||||
new[2] = recommended
|
return replace_command(command, broken_cmd, matched)
|
||||||
return shell.and_(' '.join(new))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user