예제 #1
0
 def test_isnt_match(self):
     assert not Rule('', lambda _: False).is_match(Command('ls'))
예제 #2
0
'''

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)
])
예제 #3
0
def test_get_new_command(stderr):
    assert (get_new_command(
        Command('git stash pop',
                stderr=stderr)) == "git add . && git stash pop && git reset .")
예제 #4
0
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
예제 #5
0
 def fn(command):
     assert command == Command(called)
     return return_value
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
def test_get_new_command(before, after):
    assert get_new_command(Command(before)) == after
예제 #9
0
def test_match(script, stderr):
    command = Command(script, stderr=stderr.format(error))
    assert match(command)
예제 #10
0
def test_match(stderr, stdout):
    assert match(Command(stderr=stderr, stdout=stdout))
예제 #11
0
def test_not_match():
    assert not match(Command())
    assert not match(Command(script='sudo ls', stderr='Permission denied'))
예제 #12
0
 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)]
예제 #13
0
 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:'
예제 #14
0
 def test_is_match(self):
     rule = Rule('', lambda x: x.script == 'cd ..')
     assert rule.is_match(Command('cd ..'))
예제 #15
0
def test_get_new_command():
    assert (get_new_command(Command('git branch list'), None) ==
            shells.and_('git branch --delete list', 'git branch'))
예제 #16
0
def test_not_match(script, stderr):
    command = Command(script, stderr=stderr)
    assert not match(command)
예제 #17
0
def test_match():
    assert match(Command('git branch list'), None)
예제 #18
0
def test_get_new_command(script, result):
    command = Command(script)
    assert get_new_command(command) == result
예제 #19
0
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
예제 #20
0
@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)
예제 #21
0
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',
예제 #22
0
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
예제 #23
0
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
예제 #24
0
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'),
예제 #25
0
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'),
예제 #26
0
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))
예제 #27
0
def test_match(stderr):
    assert match(Command('git stash pop', stderr=stderr))
    assert not match(Command('git stash'))
예제 #28
0
def test_get_new_command(stderr):
    assert get_new_command(Command('git branch -d branch', stderr=stderr))\
        == "git branch -D branch"
예제 #29
0
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'
예제 #30
0
def test_get_new_command():
    assert get_new_command(Command('cd..'), None) == 'cd ..'