def test_from_script_calls(self, Popen, settings, os_environ): settings.env = {} assert Command.from_raw_script( ['apt-get', 'search', 'vim']) == Command( 'apt-get search vim', 'output') Popen.assert_called_once_with('apt-get search vim', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=os_environ)
import pytest from thefuck.rules.cat_dir import match, get_new_command from thefuck.types import Command @pytest.fixture def isdir(mocker): return mocker.patch('thefuck.rules.cat_dir' '.os.path.isdir') @pytest.mark.parametrize('command', [ Command('cat foo', 'cat: foo: Is a directory\n'), Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'), Command('cat cat/', 'cat: cat/: Is a directory\n'), ]) def test_match(command, isdir): isdir.return_value = True assert match(command) @pytest.mark.parametrize('command', [ Command('cat foo', 'foo bar baz'), Command('cat foo bar', 'foo bar baz'), Command('notcat foo bar', 'some output'), ]) def test_not_match(command, isdir): isdir.return_value = False assert not match(command)
def test_not_match(): assert not match(Command("az provider", no_suggestions))
def test_get_new_command(output, script, target, new_command): assert get_new_command(Command(script, output)) == new_command
def test_match(output, script, target): assert match(Command(script, output))
def test_match(script, output): assert match(Command(script, output))
def test_not_match(): err_response = "bash: docker: command not found" assert not match(Command("docker image rm -f cd809b04b6ff", err_response))
def test_not_match(isdir, script, output, isdir_result): isdir.return_value = isdir_result command = Command(script, output) assert not match(command)
def test_match(mistype_response): assert match(Command('conda lst', mistype_response)) err_response = 'bash: codna: command not found' assert not match(Command('codna list', err_response))
az: 'providers' is not in the 'az' command group. See 'az --help'. The most similar choice to 'providers' is: provider ''' misspelled_subcommand = '''\ az provider: 'lis' is not in the 'az provider' command group. See 'az provider --help'. The most similar choice to 'lis' is: list ''' @pytest.mark.parametrize('command', [ Command('az providers', misspelled_command), Command('az provider lis', misspelled_subcommand)]) def test_match(command): assert match(command) def test_not_match(): assert not match(Command('az provider', no_suggestions)) @pytest.mark.parametrize('command, result', [ (Command('az providers list', misspelled_command), ['az provider list']), (Command('az provider lis', misspelled_subcommand), ['az provider list']) ]) def test_get_new_command(command, result): assert get_new_command(command) == result
import pytest from thefuck.rules.git_pull_clone import get_new_command from thefuck.rules.git_pull_clone import match from thefuck.types import Command git_err = """ fatal: Not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). """ @pytest.mark.parametrize( "command", [Command("git pull [email protected]:mcarton/thefuck.git", git_err)]) def test_match(command): assert match(command) @pytest.mark.parametrize( "command, output", [( Command("git pull [email protected]:mcarton/thefuck.git", git_err), "git clone [email protected]:mcarton/thefuck.git", )], ) def test_get_new_command(command, output): assert get_new_command(command) == output
def test_get_new_command(get_actual_scm_mock, script, actual_scm, result): get_actual_scm_mock.return_value = actual_scm new_command = get_new_command(Command(script, "")) assert new_command == result
def test_not_match(get_actual_scm_mock, script, output, actual_scm): get_actual_scm_mock.return_value = actual_scm assert not match(Command(script, output))
def test_get_new_command(pip_unknown_cmd): assert get_new_command(Command('pip instatl', pip_unknown_cmd)) == 'pip install'
def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend): assert match(Command('pip instatl', pip_unknown_cmd)) assert not match(Command('pip i', pip_unknown_cmd_without_recommend))
def test_from_script(self, script, result): if result: assert Command.from_raw_script(script).script == result else: with pytest.raises(EmptyCommand): Command.from_raw_script(script)
def test_match(isdir, script, output): isdir.return_value = True command = Command(script, output) assert match(command)
def test_get_new_command(mistype_response): assert (get_new_command(Command('conda lst', mistype_response)) == ['conda list'])
def test_get_new_command(before, after): command = Command(before, output) assert get_new_command(command) == after
def test_match(brew_no_available_formula, brew_already_installed, brew_install_no_argument): assert match( Command('brew install elsticsearch', brew_no_available_formula)) assert not match(Command('brew install git', brew_already_installed)) assert not match(Command('brew install', brew_install_no_argument))
def test_match(): err_response = """Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image is being used by running container e5e2591040d1""" assert match(Command("docker image rm -f cd809b04b6ff", err_response))
def test_get_new_command(script, formula): command = Command(script, output) new_command = 'brew upgrade {}'.format(formula) assert get_new_command(command) == new_command
def test_get_new_command(script, new_cmd, output): assert get_new_command((Command(script, output))) == new_cmd
def test_match(): command = Command('brew update thefuck', output) assert match(command)
def test_not_match(script): assert not match(Command(script, ''))
def test_is_app(script, names, result): assert is_app(Command(script, ''), *names) == result
The most similar choice to 'providers' is: provider """ misspelled_subcommand = """\ az provider: 'lis' is not in the 'az provider' command group. See 'az provider --help'. The most similar choice to 'lis' is: list """ @pytest.mark.parametrize( "command", [ Command("az providers", misspelled_command), Command("az provider lis", misspelled_subcommand), ], ) def test_match(command): assert match(command) def test_not_match(): assert not match(Command("az provider", no_suggestions)) @pytest.mark.parametrize( "command, result", [ (Command("az providers list",
def test_for_app(script, names, result): @for_app(*names) def match(command): return True assert match(Command(script, '')) == result
import pytest from thefuck.rules.apt_get import match, get_new_command from thefuck.types import Command @pytest.mark.parametrize('command, packages', [ (Command('vim', 'vim: command not found'), [('vim', 'main'), ('vim-tiny', 'main')]), (Command('sudo vim', 'vim: command not found'), [('vim', 'main'), ('vim-tiny', 'main')]), (Command( 'vim', "The program 'vim' is currently not installed. You can install it by typing: sudo apt install vim" ), [('vim', 'main'), ('vim-tiny', 'main')]) ]) def test_match(mocker, command, packages): mocker.patch('thefuck.rules.apt_get.which', return_value=None) mock = mocker.patch('thefuck.rules.apt_get.command_not_found', create=True) mock.getPackages.return_value = packages assert match(command) @pytest.mark.parametrize( 'command, packages, which', [(Command('a_bad_cmd', 'a_bad_cmd: command not found'), [], None), (Command('vim', ''), [], None), (Command('', ''), [], None), (Command('vim', 'vim: command not found'), ['vim'], '/usr/bin/vim'), (Command('sudo vim', 'vim: command not found'), ['vim'], '/usr/bin/vim')]) def test_not_match(mocker, command, packages, which): mocker.patch('thefuck.rules.apt_get.which', return_value=which)
def test_get_valid_history_without_current(self, script): command = Command(script, '') assert script not in get_valid_history_without_current(command)
def test_match(wrong): assert match(Command(wrong, git_stash_err))
import pytest from thefuck.rules.git_two_dashes import get_new_command from thefuck.rules.git_two_dashes import match from thefuck.types import Command output = "error: did you mean `{}` (with two dashes ?)".format @pytest.mark.parametrize( "command", [ Command("git add -patch", output("--patch")), Command("git checkout -patch", output("--patch")), Command("git commit -amend", output("--amend")), Command("git push -tags", output("--tags")), Command("git rebase -continue", output("--continue")), ], ) def test_match(command): assert match(command) @pytest.mark.parametrize( "command", [ Command("git add --patch", ""), Command("git checkout --patch", ""), Command("git commit --amend", ""), Command("git push --tags", ""), Command("git rebase --continue", ""),