Esempio n. 1
0
def test_match():
    err_response1 = """
    Sending build context to Docker daemon  118.8kB
Step 1/6 : FROM foo/bar:fdb7c6d
pull access denied for foo/bar, repository does not exist or may require 'docker login'
"""
    assert match(Command('docker build -t artifactory:9090/foo/bar:fdb7c6d .', err_response1))

    err_response2 = """
    The push refers to repository [artifactory:9090/foo/bar]
push access denied for foo/bar, repository does not exist or may require 'docker login'
"""
    assert match(Command('docker push artifactory:9090/foo/bar:fdb7c6d', err_response2))

    err_response3 = """
    docker push artifactory:9090/foo/bar:fdb7c6d
The push refers to repository [artifactory:9090/foo/bar]
9c29c7ad209d: Preparing
71f3ad53dfe0: Preparing
f58ee068224c: Preparing
aeddc924d0f7: Preparing
c2040e5d6363: Preparing
4d42df4f350f: Preparing
35723dab26f9: Preparing
71f3ad53dfe0: Pushed
cb95fa0faeb1: Layer already exists
"""
    assert not match(Command('docker push artifactory:9090/foo/bar:fdb7c6d', err_response3))
Esempio n. 2
0
def test_get_new_command(brew_unknown_cmd, brew_unknown_cmd2):
    assert (get_new_command(Command('brew inst', brew_unknown_cmd))
            == ['brew list', 'brew install', 'brew uninstall'])

    cmds = get_new_command(Command('brew instaa', brew_unknown_cmd2))
    assert 'brew install' in cmds
    assert 'brew uninstall' in cmds
Esempio n. 3
0
def test_get_new_command(brew_no_available_formula):
    assert get_new_command(Command('brew install elsticsearch',
                                   brew_no_available_formula))\
        == 'brew install elasticsearch'

    assert get_new_command(Command('brew install aa',
                                   brew_no_available_formula))\
        != 'brew install aha'
Esempio n. 4
0
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'
Esempio n. 5
0
def test_get_new_command():
    assert get_new_command(
        Command('pip install -r requirements.txt',
                '')) == 'pip install --user -r requirements.txt'
    assert get_new_command(Command('pip install bacon',
                                   '')) == 'pip install --user bacon'
    assert get_new_command(
        Command('pip install --user -r requirements.txt',
                '')) == 'sudo pip install -r requirements.txt'
Esempio n. 6
0
def test_match():
    with patch('os.path.exists', return_value=True):
        assert match(Command('main', 'main: command not found'))
        assert match(Command('main --help',
                             'main: command not found'))
        assert not match(Command('main', ''))

    with patch('os.path.exists', return_value=False):
        assert not match(Command('main', 'main: command not found'))
Esempio n. 7
0
def test_get_new_command(git_not_command, git_not_command_one_of_this,
                         git_not_command_closest):
    assert (get_new_command(Command('git brnch',
                                    git_not_command)) == ['git branch'])
    assert (get_new_command(Command('git st',
                                    git_not_command_one_of_this)) == [
                                        'git stats', 'git stash', 'git stage'
                                    ])
    assert (get_new_command(Command(
        'git tags', git_not_command_closest)) == ['git tag', 'git stage'])
Esempio n. 8
0
def test_match():
    """The character before 'grep' is Alt+Space, which happens frequently
    on the Mac when typing the pipe character (Alt+7), and holding the Alt
    key pressed for longer than necessary.

    """
    assert match(
        Command(u'ps -ef | grep foo', u'-bash:  grep: command not found'))
    assert not match(Command('ps -ef | grep foo', ''))
    assert not match(Command('', ''))
Esempio n. 9
0
def test_get_new_command(sed_unterminated_s):
    assert (get_new_command(Command(
        'sed -e s/foo/bar', sed_unterminated_s)) == 'sed -e s/foo/bar/')
    assert (get_new_command(Command('sed -es/foo/bar',
                                    sed_unterminated_s)) == 'sed -es/foo/bar/')
    assert (get_new_command(
        Command(r"sed -e 's/\/foo/bar'",
                sed_unterminated_s)) == r"sed -e 's/\/foo/bar/'")
    assert (get_new_command(
        Command(r"sed -e s/foo/bar -es/baz/quz",
                sed_unterminated_s)) == r"sed -e s/foo/bar/ -es/baz/quz/")
Esempio n. 10
0
 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)
Esempio n. 11
0
def test_match():
    response1 = """
    Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/entrypoints.pyc'
Consider using the `--user` option or check the permissions.
"""
    assert match(Command('pip install -r requirements.txt', response1))

    response2 = """
Collecting bacon
  Downloading https://files.pythonhosted.org/packages/b2/81/19fb79139ee71c8bc4e5a444546f318e2b87253b8939ec8a7e10d63b7341/bacon-0.3.1.zip (11.0MB)
    100% |████████████████████████████████| 11.0MB 3.0MB/s
Installing collected packages: bacon
  Running setup.py install for bacon ... done
Successfully installed bacon-0.3.1
"""
    assert not match(Command('pip install bacon', response2))
Esempio n. 12
0
def test_get_new_command(ext, tar_error, filename, unquoted, quoted, script,
                         fixed):
    tar_error(unquoted.format(ext))
    assert (get_new_command(Command(script.format(filename.format(ext)),
                                    '')) == fixed.format(
                                        dir=quoted.format(''),
                                        filename=filename.format(ext)))
Esempio n. 13
0
def test_get_new_command():
    err_response = """
        Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image
        is being used by running container e5e2591040d1
        """
    result = get_new_command(
        Command('docker image rm -f cd809b04b6ff', err_response))
    expected = 'docker container rm -f e5e2591040d1 && docker image rm -f cd809b04b6ff'
    assert result == expected
Esempio n. 14
0
def test_side_effect(zip_error, script, filename):
    zip_error(filename)
    side_effect(Command(script, ''), None)

    dir_list = os.listdir(u'.')
    if filename not in set(dir_list):
        filename = normalize('NFD', filename)

    assert set(dir_list) == {filename, 'd'}
Esempio n. 15
0
def test_match(ssh_error):
    errormsg, _, _, _ = ssh_error
    assert match(Command('ssh', errormsg))
    assert match(Command('ssh', errormsg))
    assert match(Command('scp something something', errormsg))
    assert match(Command('scp something something', errormsg))
    assert not match(Command(errormsg, ''))
    assert not match(Command('notssh', errormsg))
    assert not match(Command('ssh', ''))
Esempio n. 16
0
def test_match():
    assert match(Command('ls', ''))
    assert match(Command('ls file.py', ''))
    assert match(Command('ls /opt', ''))
    assert not match(Command('ls -lah /opt', ''))
    assert not match(Command('pacman -S binutils', ''))
    assert not match(Command('lsof', ''))
Esempio n. 17
0
def test_match(sed_unterminated_s):
    assert match(Command('sed -e s/foo/bar', sed_unterminated_s))
    assert match(Command('sed -es/foo/bar', sed_unterminated_s))
    assert match(Command('sed -e s/foo/bar -e s/baz/quz', sed_unterminated_s))
    assert not match(Command('sed -e s/foo/bar', ''))
    assert not match(Command('sed -es/foo/bar', ''))
    assert not match(Command('sed -e s/foo/bar -e s/baz/quz', ''))
Esempio n. 18
0
def test_get_corrected_commands(mocker):
    command = Command('test', 'test')
    rules = [
        Rule(match=lambda _: False),
        Rule(match=lambda _: True,
             get_new_command=lambda x: x.script + '!',
             priority=100),
        Rule(match=lambda _: True,
             get_new_command=lambda x: [x.script + '@', x.script + ';'],
             priority=60)
    ]
    mocker.patch('therandy.corrector.get_rules', return_value=rules)
    assert ([cmd.script for cmd in get_corrected_commands(command)
             ] == ['test!', 'test@', 'test;'])
Esempio n. 19
0
def test_match():
    assert match(
        Command('systemctl nginx start', 'Unknown operation \'nginx\'.'))
    assert match(
        Command('sudo systemctl nginx start', 'Unknown operation \'nginx\'.'))
    assert not match(Command('systemctl start nginx', ''))
    assert not match(Command('systemctl start nginx', ''))
    assert not match(
        Command('sudo systemctl nginx', 'Unknown operation \'nginx\'.'))
    assert not match(Command('systemctl nginx',
                             'Unknown operation \'nginx\'.'))
    assert not match(
        Command(
            'systemctl start wtf',
            'Failed to start wtf.service: Unit wtf.service failed to load: No such file or directory.'
        ))
Esempio n. 20
0
def test_match(script, is_bsd):
    command = Command(script, output(is_bsd))
    assert match(command)
Esempio n. 21
0

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'
Esempio n. 22
0
import pytest

from therandy.types import Command
from therandy.rules.mercurial import (extract_possibilities, match,
                                      get_new_command)


@pytest.mark.parametrize('command', [
    Command('hg base', ("hg: unknown command 'base'"
                        '\n(did you mean one of blame, phase, rebase?)')),
    Command('hg branchch', ("hg: unknown command 'branchch'"
                            '\n(did you mean one of branch, branches?)')),
    Command('hg vert', ("hg: unknown command 'vert'"
                        '\n(did you mean one of revert?)')),
    Command('hg lgo -r tip', ("hg: command 're' is ambiguous:"
                              '\n(did you mean one of log?)')),
    Command('hg rerere', ("hg: unknown command 'rerere'"
                          '\n(did you mean one of revert?)')),
    Command('hg re', ("hg: command 're' is ambiguous:"
                      '\n    rebase recover remove rename resolve revert')),
    Command('hg re re', ("hg: command 're' is ambiguous:"
                         '\n    rebase recover remove rename resolve revert')),
])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize('command', [
    Command('hg', ('\nMercurial Distributed SCM\n\nbasic commands:')),
    Command('hg asdf', ("hg: unknown command 'asdf'"
                        '\nMercurial Distributed SCM\n\nbasic commands:')),
Esempio n. 23
0
import pytest
from therandy.rules.go_run import match, get_new_command
from therandy.types import Command


@pytest.mark.parametrize('command', [
    Command('go run foo', ''),
    Command('go run bar', '')])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize('command, new_command', [
    (Command('go run foo', ''), 'go run foo.go'),
    (Command('go run bar', ''), 'go run bar.go')])
def test_get_new_command(command, new_command):
    assert get_new_command(command) == new_command
Esempio n. 24
0
def test_get_new_command():
    assert get_new_command(Command('ls file.py', '')) == 'ls -lah file.py'
    assert get_new_command(Command('ls', '')) == 'ls -lah'
Esempio n. 25
0
def test_match(output):
    assert match(Command('./manage.py migrate', output))
    assert match(Command('python manage.py migrate', output))
    assert not match(Command('./manage.py migrate', ''))
    assert not match(Command('app migrate', output))
    assert not match(Command('./manage.py test', output))
Esempio n. 26
0
import pytest

from therandy.types import Command
from therandy.rules.git_push_without_commits import (
    fix,
    get_new_command,
    match,
)

command = 'git push -u origin master'
expected_error = '''
error: src refspec master does not match any.
error: failed to push some refs to '[email protected]:User/repo.git'
'''


@pytest.mark.parametrize('command', [Command(command, expected_error)])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize('command, result', [(
    Command(command, expected_error),
    fix.format(command=command),
)])
def test_get_new_command(command, result):
    assert get_new_command(command) == result
Esempio n. 27
0
import pytest
from therandy.rules.mvn_unknown_lifecycle_phase import match, get_new_command
from therandy.types import Command


@pytest.mark.parametrize('command', [
    Command('mvn cle', '[ERROR] Unknown lifecycle phase "cle". 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('mvn clean', """
[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
[INFO] Final Memory: 6M/240M
[INFO] ------------------------------------------------------------------------
"""),  # noqa
    Command('mvn --help', ''),
    Command('mvn -v', '')
])
Esempio n. 28
0
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'
Esempio n. 29
0
Task '{}' is ambiguous in root project 'org.rerenderer_example.snake'. Candidates are: 'assembleRelease', 'assembleReleaseUnitTest'.

* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
'''.format


@pytest.fixture(autouse=True)
def tasks(mocker):
    patch = mocker.patch('therandy.rules.gradle_no_task.Popen')
    patch.return_value.stdout = BytesIO(gradle_tasks)
    return patch


@pytest.mark.parametrize('command', [
    Command('./gradlew assembler', output_ambiguous('assembler')),
    Command('./gradlew instar', output_not_found('instar')),
    Command('gradle assembler', output_ambiguous('assembler')),
    Command('gradle instar', output_not_found('instar'))
])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize('command', [
    Command('./gradlew assemble', ''),
    Command('gradle assemble', ''),
    Command('npm assembler', output_ambiguous('assembler')),
    Command('npm instar', output_not_found('instar'))
])
def test_not_match(command):
Esempio n. 30
0
def test_get_new_command():
    assert (get_new_command(Command('./manage.py migrate auth',
                                    '')) == './manage.py migrate auth --merge')