def test_match(ext, tar_error, filename, unquoted, quoted, script, fixed): tar_error(unquoted.format(ext)) assert match(Command(script.format(filename.format(ext)), ""))
def test_not_match(script): assert not match(Command(script, ''))
import pytest from mock import patch from thefuck.rules import pacman_not_found from thefuck.rules.pacman_not_found import match, get_new_command from thefuck.types import Command PKGFILE_OUTPUT_LLC = '''extra/llvm 3.6.0-5 /usr/bin/llc extra/llvm35 3.5.2-13/usr/bin/llc''' @pytest.mark.skipif(not getattr(pacman_not_found, 'enabled_by_default', True), reason='Skip if pacman is not available') @pytest.mark.parametrize('command', [ Command('yaourt -S llc', 'error: target not found: llc'), Command('pacman llc', 'error: target not found: llc'), Command('sudo pacman llc', 'error: target not found: llc') ]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command('yaourt -S llc', 'error: target not found: llc'), Command('pacman llc', 'error: target not found: llc'), Command('sudo pacman llc', 'error: target not found: llc') ]) @patch('thefuck.specific.archlinux.subprocess') def test_match_mocked(subp_mock, command): subp_mock.check_output.return_value = PKGFILE_OUTPUT_LLC assert match(command)
def test_get_new_command(output): command = Command('touch /a/b/c', output) fixed_command = get_new_command(command) assert fixed_command == 'mkdir -p /a/b && touch /a/b/c'
def test_match(script, result): output = get_output("source") assert match(Command(script, output)) assert get_new_command(Command(script, output)) == result
def test_match(option): assert match(Command("pacman -{}v meat".format(option), bad_output))
import pytest from thefuck.rules.touch import match, get_new_command from thefuck.types import Command @pytest.fixture def output(): return "touch: cannot touch '/a/b/c':" \ " No such file or directory" def test_match(output): command = Command('touch /a/b/c', output) assert match(command) @pytest.mark.parametrize( 'command', [Command('touch /a/b/c', ''), Command('ls /a/b/c', output())]) def test_not_match(command): assert not match(command) def test_get_new_command(output): command = Command('touch /a/b/c', output) fixed_command = get_new_command(command) assert fixed_command == 'mkdir -p /a/b && touch /a/b/c'
import pytest from thefuck.rules.yarn_command_replaced import get_new_command from thefuck.rules.yarn_command_replaced import match from thefuck.types import Command output = ("error `install` has been replaced with `add` to add new " 'dependencies. Run "yarn add {}" instead.').format @pytest.mark.parametrize( "command", [ Command("yarn install redux", output("redux")), Command("yarn install moment", output("moment")), Command("yarn install lodash", output("lodash")), ], ) def test_match(command): assert match(command) @pytest.mark.parametrize("command", [Command("yarn install", "")]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize( "command, new_command", [ (Command("yarn install redux", output("redux")), "yarn add redux"),
import pytest from thefuck.rules.git_merge import match, get_new_command from thefuck.types import Command @pytest.fixture def output(): return 'merge: local - not something we can merge\n\n' \ 'Did you mean this?\n\tremote/local' def test_match(output): assert match(Command('git merge test', output)) assert not match(Command('git merge master', '')) assert not match(Command('ls', output)) @pytest.mark.parametrize( 'command, new_command', [(Command('git merge local', output()), 'git merge remote/local'), (Command('git merge -m "test" local', output()), 'git merge -m "test" remote/local'), (Command('git merge -m "test local" local', output()), 'git merge -m "test local" remote/local')]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command
def test_not_match(): assert not match(Command('aws dynamodb invalid', no_suggestions))
import pytest from thefuck.rules.quotation_marks import get_new_command from thefuck.rules.quotation_marks import match from thefuck.types import Command @pytest.mark.parametrize( "command", [ Command("git commit -m 'My Message\"", ""), Command("git commit -am \"Mismatched Quotation Marks'", ""), Command("echo \"hello'", ""), ], ) def test_match(command): assert match(command) @pytest.mark.parametrize( "command, new_command", [ (Command("git commit -m 'My Message\"", ""), 'git commit -m "My Message"'), ( Command("git commit -am \"Mismatched Quotation Marks'", ""), 'git commit -am "Mismatched Quotation Marks"', ), (Command("echo \"hello'", ""), 'echo "hello"'), ], )
misspelled_subcommand = '''\ ERROR: (gcloud.compute) Invalid choice: 'instance'. Maybe you meant: gcloud compute instance-groups gcloud compute instance-templates gcloud compute instances gcloud compute target-instances To search the help text of gcloud commands, run: gcloud help -- SEARCH_TERMS ''' @pytest.mark.parametrize('command', [ Command('gcloud comute instances list', misspelled_subcommand), Command('gcloud compute instance list', misspelled_subcommand) ]) def test_match(command): assert match(command) def test_not_match(): assert not match(Command('aws dynamodb invalid', no_suggestions)) @pytest.mark.parametrize( 'command, result', [(Command('gcloud comute instances list', misspelled_subcommand), ['gcloud compute instance-groups']), (Command('gcloud compute instance list',
no_website_long = """ {}: No Domain list found for website: a_website_that_does_not_exist Please raise a Issue here: https://github.com/dhilipsiva/hostscli/issues/new if you think we should add domains for this website. type `hostscli websites` to see a list of websites that you can block/unblock """.format(no_website) @pytest.mark.parametrize( "command", [Command("hostscli block a_website_that_does_not_exist", no_website_long)], ) def test_match(command): assert match(command) @pytest.mark.parametrize( "command, result", [( Command("hostscli block a_website_that_does_not_exist", no_website_long), ["hostscli websites"], )], ) def test_get_new_command(command, result): assert get_new_command(command) == result
def test_side_effect(ext, tar_error, filename, unquoted, quoted, script, fixed): tar_error(unquoted.format(ext)) side_effect(Command(script.format(filename.format(ext)), ""), None) assert set(os.listdir(".")) == {unquoted.format(ext), "d"}
def test_match(): assert match(Command("apt list --upgradable", match_output)) assert match(Command("sudo apt list --upgradable", match_output))
def test_match(output): assert match(Command('git merge test', output)) assert not match(Command('git merge master', '')) assert not match(Command('ls', output))
def test_not_match_good_output(option): assert not match(Command("pacman -{}s meat".format(option), good_output))
import pytest from thefuck.rules.yarn_alias import get_new_command from thefuck.rules.yarn_alias import match from thefuck.types import Command output_remove = "error Did you mean `yarn remove`?" output_etl = 'error Command "etil" not found. Did you mean "etl"?' output_list = "error Did you mean `yarn list`?" @pytest.mark.parametrize( "command", [ Command("yarn rm", output_remove), Command("yarn etil", output_etl), Command("yarn ls", output_list), ], ) def test_match(command): assert match(command) @pytest.mark.parametrize( "command, new_command", [ (Command("yarn rm", output_remove), "yarn remove"), (Command("yarn etil", output_etl), "yarn etl"), (Command("yarn ls", output_list), "yarn list"), ], )
def test_get_new_command(option): new_command = get_new_command( Command("pacman -{}v meat".format(option), "")) assert new_command == "pacman -{}v meat".format(option.upper())
def test_match(output, script, target): assert match(Command(script, output))
def test_match(output): command = Command('touch /a/b/c', output) assert match(command)
def test_get_new_command(set_help, output, script, help_text, result): set_help(help_text) assert get_new_command(Command(script, output))[0] == result
def test_not_match(file_exists, script, output, exists): file_exists.return_value = exists assert not match(Command(script, output))
def test_get_new_command(script, output, new_command): assert get_new_command(Command(script, output)) == new_command
import pytest from thefuck.rules.java import match, get_new_command from thefuck.types import Command @pytest.mark.parametrize('command', [ Command('java foo.java', ''), Command('java bar.java', '')]) def test_match(command): assert match(command) @pytest.mark.parametrize('command, new_command', [ (Command('java foo.java', ''), 'java foo'), (Command('java bar.java', ''), 'java bar')]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command
def test_match(script, output): assert match(Command(script, output))
def test_get_new_command(script, result): assert get_new_command(Command(script, '')) == result
""" no_match_output = """ Listing... Done """ def test_match(): assert match(Command("apt list --upgradable", match_output)) assert match(Command("sudo apt list --upgradable", match_output)) @pytest.mark.parametrize( "command", [ Command("apt list --upgradable", no_match_output), Command("sudo apt list --upgradable", no_match_output), ], ) def test_not_match(command): assert not match(command) def test_get_new_command(): new_command = get_new_command( Command("apt list --upgradable", match_output)) assert new_command == "apt upgrade" new_command = get_new_command( Command("sudo apt list --upgradable", match_output)) assert new_command == "sudo apt upgrade"
from thefuck.types import Command def output(is_bsd): if is_bsd: return "touch: /a/b/c: No such file or directory" return "touch: cannot touch '/a/b/c': No such file or directory" @pytest.mark.parametrize("script, is_bsd", [("touch /a/b/c", False), ("touch /a/b/c", True)]) def test_match(script, is_bsd): command = Command(script, output(is_bsd)) assert match(command) @pytest.mark.parametrize( "command", [Command("touch /a/b/c", ""), Command("ls /a/b/c", output(False))]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize("script, is_bsd", [("touch /a/b/c", False), ("touch /a/b/c", True)]) def test_get_new_command(script, is_bsd): command = Command(script, output(is_bsd)) fixed_command = get_new_command(command) assert fixed_command == "mkdir -p /a/b && touch /a/b/c"
def test_get_new_command(): assert get_new_command(Command('git clone git clone foo', output_clean)) == 'git clone foo'