def test_isnt_match(self): assert not Rule('', lambda _: False).is_match(Command('ls'))
''' git_uptodate = 'Everything up-to-date' git_ok = ''' Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To /tmp/bar 514eed3..f269c79 master -> master ''' @pytest.mark.parametrize('command', [ Command(script='git push', stderr=git_err), Command(script='git push nvbn', stderr=git_err), Command(script='git push nvbn master', stderr=git_err) ]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command(script='git push', stderr=git_ok), Command(script='git push', stderr=git_uptodate), Command(script='git push nvbn', stderr=git_ok), Command(script='git push nvbn master', stderr=git_uptodate), Command(script='git push nvbn', stderr=git_ok), Command(script='git push nvbn master', stderr=git_uptodate) ])
def test_get_new_command(stderr): assert (get_new_command( Command('git stash pop', stderr=stderr)) == "git add . && git stash pop && git reset .")
import pytest from thefuck.rules.git_flag_after_filename import match, get_new_command from tests.utils import Command command1 = Command('git log README.md -p', stderr="fatal: bad flag '-p' used after filename") command2 = Command('git log README.md -p CONTRIBUTING.md', stderr="fatal: bad flag '-p' used after filename") command3 = Command('git log -p README.md --name-only', stderr="fatal: bad flag '--name-only' used after filename") @pytest.mark.parametrize('command', [ command1, command2, command3]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command('git log README.md'), Command('git log -p README.md')]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize('command, result', [ (command1, "git log -p README.md"), (command2, "git log -p README.md CONTRIBUTING.md"), (command3, "git log -p --name-only README.md")]) def test_get_new_command(command, result): assert get_new_command(command) == result
def fn(command): assert command == Command(called) return return_value
def test_not_match(): assert not match(Command(), None) assert not match(Command('git commit'), None) assert not match(Command('git branch'), None) assert not match(Command('git stash list'), None)
def test_match(brew_unknown_cmd): assert match(Command('brew inst', stderr=brew_unknown_cmd), None) for command in brew_commands: assert not match(Command('brew ' + command), None)
def test_get_new_command(before, after): assert get_new_command(Command(before)) == after
def test_match(script, stderr): command = Command(script, stderr=stderr.format(error)) assert match(command)
def test_match(stderr, stdout): assert match(Command(stderr=stderr, stdout=stdout))
def test_not_match(): assert not match(Command()) assert not match(Command(script='sudo ls', stderr='Permission denied'))
def test_get_corrected_commands_with_rule_returns_command(self): rule = Rule(get_new_command=lambda x: x.script + '!', priority=100) assert list(rule.get_corrected_commands(Command(script='test'))) \ == [CorrectedCommand(script='test!', priority=100)]
def test_isnt_match_when_rule_failed(self, capsys): rule = Rule('test', Mock(side_effect=OSError('Denied')), requires_output=False) assert not rule.is_match(Command('ls')) assert capsys.readouterr()[1].split('\n')[0] == '[WARN] Rule test:'
def test_is_match(self): rule = Rule('', lambda x: x.script == 'cd ..') assert rule.is_match(Command('cd ..'))
def test_get_new_command(): assert (get_new_command(Command('git branch list'), None) == shells.and_('git branch --delete list', 'git branch'))
def test_not_match(script, stderr): command = Command(script, stderr=stderr) assert not match(command)
def test_match(): assert match(Command('git branch list'), None)
def test_get_new_command(script, result): command = Command(script) assert get_new_command(command) == result
import pytest from thefuck.rules.quotation_marks import match, get_new_command from tests.utils import Command @pytest.mark.parametrize('command', [ Command(script="git commit -m \'My Message\""), Command(script="git commit -am \"Mismatched Quotation Marks\'"), Command(script="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\"")]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command
@pytest.fixture def did_not_match(target, did_you_forget=False): error = ("error: pathspec '{}' did not match any " "file(s) known to git.".format(target)) if did_you_forget: error = ("{}\nDid you forget to 'git add'?'".format(error)) return error @pytest.fixture def get_branches(mocker): return mocker.patch('thefuck.rules.git_checkout.get_branches') @pytest.mark.parametrize('command', [ Command(script='git checkout unknown', stderr=did_not_match('unknown')), Command(script='git commit unknown', stderr=did_not_match('unknown')) ]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command(script='git submodule update unknown', stderr=did_not_match('unknown', True)), Command(script='git checkout known', stderr=('')), Command(script='git commit known', stderr=('')) ]) def test_not_match(command): assert not match(command)
import pytest from thefuck.rules.git_stash import match, get_new_command from tests.utils import Command cherry_pick_error = ( 'error: Your local changes would be overwritten by cherry-pick.\n' 'hint: Commit your changes or stash them to proceed.\n' 'fatal: cherry-pick failed') rebase_error = ('Cannot rebase: Your index contains uncommitted changes.\n' 'Please commit or stash them.') @pytest.mark.parametrize('command', [ Command(script='git cherry-pick a1b2c3d', stderr=cherry_pick_error), Command(script='git rebase -i HEAD~7', stderr=rebase_error) ]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command(script='git cherry-pick a1b2c3d', stderr=('')), Command(script='git rebase -i HEAD~7', stderr=('')) ]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize( 'command, new_command',
import pytest from theoops.rules.mvn_no_command import match, get_new_command from tests.utils import Command @pytest.mark.parametrize('command', [ Command( script='mvn', stdout= '[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]' ) ]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command(script='mvn clean', stdout=""" [INFO] Scanning for projects...[INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building test 0.2 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test --- [INFO] Deleting /home/mlk/code/test/target [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.477s [INFO] Finished at: Wed Aug 26 13:05:47 BST 2015
def test_sudo_support(return_value, command, called, result): def fn(command): assert command == Command(called) return return_value assert sudo_support(fn)(Command(command)) == result
import pytest from thefuck.rules.mkdir_p import match, get_new_command from tests.utils import Command @pytest.mark.parametrize('command', [ Command('mkdir foo/bar/baz', stderr='mkdir: foo/bar: No such file or directory'), Command('./bin/hdfs dfs -mkdir foo/bar/baz', stderr='mkdir: `foo/bar/baz\': No such file or directory'), Command('hdfs dfs -mkdir foo/bar/baz', stderr='mkdir: `foo/bar/baz\': No such file or directory') ]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command('mkdir foo/bar/baz'), Command('mkdir foo/bar/baz', stderr='foo bar baz'), Command('hdfs dfs -mkdir foo/bar/baz'), Command('./bin/hdfs dfs -mkdir foo/bar/baz'), Command() ]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize('command, new_command', [ (Command('mkdir foo/bar/baz'), 'mkdir -p foo/bar/baz'), (Command('hdfs dfs -mkdir foo/bar/baz'), 'hdfs dfs -mkdir -p foo/bar/baz'),
import pytest from thefuck.rules.tsuru_login import match, get_new_command from tests.utils import Command error_msg = ( "Error: you're not authenticated or your session has expired.", ("You're not authenticated or your session has expired. " "Please use \"login\" command for authentication."), ) @pytest.mark.parametrize('command', [ Command(script='tsuru app-shell', stderr=error_msg[0]), Command(script='tsuru app-log -f', stderr=error_msg[1]), ]) def test_match(command): assert match(command, {}) @pytest.mark.parametrize('command', [ Command(script='tsuru'), Command(script='tsuru app-restart', stderr=('Error: unauthorized')), Command(script='tsuru app-log -f', stderr=('Error: unparseable data')), ]) def test_not_match(command): assert not match(command, {}) @pytest.mark.parametrize('command, new_command', [ (Command('tsuru app-shell', stderr=error_msg[0]), 'tsuru login && tsuru app-shell'),
def test_match(stderr): assert match(Command('git branch -d branch', stderr=stderr)) assert not match(Command('git branch -d branch')) assert not match(Command('ls', stderr=stderr))
def test_match(stderr): assert match(Command('git stash pop', stderr=stderr)) assert not match(Command('git stash'))
def test_get_new_command(stderr): assert get_new_command(Command('git branch -d branch', stderr=stderr))\ == "git branch -D branch"
import pytest from theoops.rules.apt_get_search import get_new_command, match from tests.utils import Command def test_match(): assert match(Command('apt-get search foo')) @pytest.mark.parametrize('command', [ Command('apt-cache search foo'), Command('aptitude search foo'), Command('apt search foo'), Command('apt-get install foo'), Command('apt-get source foo'), Command('apt-get clean'), Command('apt-get remove'), Command('apt-get update') ]) def test_not_match(command): assert not match(command) def test_get_new_command(): assert get_new_command( Command('apt-get search foo')) == 'apt-cache search foo'
def test_get_new_command(): assert get_new_command(Command('cd..'), None) == 'cd ..'