Exemplo 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))
Exemplo n.º 2
0
def test_get_new_command(composer_not_command,
                         composer_not_command_one_of_this):
    assert (get_new_command(Command(
        'composer udpate', composer_not_command)) == 'composer update')
    assert (get_new_command(
        Command('composer pdate',
                composer_not_command_one_of_this)) == 'composer selfupdate')
Exemplo 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'
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
Exemplo n.º 5
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'
Exemplo 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'))
Exemplo n.º 7
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'
Exemplo 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('', ''))
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/")
Exemplo n.º 10
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))
Exemplo n.º 11
0
 def test_get_corrected_commands_with_rule_returns_list(self):
     rule = Rule(get_new_command=lambda x: [x.script + '!', x.script + '@'],
                 priority=100)
     assert (list(rule.get_corrected_commands(Command('test', ''))) == [
         CorrectedCommand(script='test!', priority=100),
         CorrectedCommand(script='test@', priority=200)
     ])
Exemplo 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)))
Exemplo n.º 13
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'}
Exemplo n.º 14
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', ''))
Exemplo n.º 15
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)
Exemplo 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', ''))
Exemplo 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', ''))
Exemplo n.º 18
0
def test_get_new_command_with_settings(mocker, monkeypatch, test, settings):
    mocker.patch('os.path.isfile', return_value=True)
    monkeypatch.setenv('EDITOR', 'dummy_editor')

    cmd = Command(test.script, test.output)
    settings.fixcolcmd = '{editor} {file} +{line}:{col}'

    if test.col:
        assert (get_new_command(cmd) ==
                u'dummy_editor {} +{}:{} && {}'.format(test.file, test.line, test.col, test.script))
    else:
        assert (get_new_command(cmd) ==
                u'dummy_editor {} +{} && {}'.format(test.file, test.line, test.script))
Exemplo n.º 19
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('thedarn.corrector.get_rules', return_value=rules)
    assert ([cmd.script for cmd in get_corrected_commands(command)
             ] == ['test!', 'test@', 'test;'])
Exemplo n.º 20
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.'
        ))
Exemplo n.º 21
0
def test_get_new_command(script, formula):
    command = Command(script, output)
    new_command = 'brew reinstall {}'.format(formula)
    assert get_new_command(command) == new_command
Exemplo n.º 22
0
def test_not_match(script):
    assert not match(Command(script, ''))
Exemplo n.º 23
0
def test_match():
    command = Command('brew update thedarn', output)
    assert match(command)
def test_get_new_command(script, output, result):
    assert get_new_command(Command(script, output))[0] == result
def test_not_match(command, output):
    assert not match(Command(command, output))
def test_match(command):
    assert match(Command('yum {}'.format(command), yum_invalid_op_text.format(command)))
Exemplo n.º 27
0
def test_not_match(script, output):
    assert not match(Command(script, output))
Exemplo n.º 28
0
def test_match():
    command = Command('brew install thedarn', output)
    assert match(command)
Exemplo n.º 29
0
import pytest
from thedarn.rules.cargo_no_command import match, get_new_command
from thedarn.types import Command

no_such_subcommand_old = """No such subcommand

        Did you mean `build`?
"""

no_such_subcommand = """error: no such subcommand

\tDid you mean `build`?
"""


@pytest.mark.parametrize('command', [
    Command('cargo buid', no_such_subcommand_old),
    Command('cargo buils', no_such_subcommand)
])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize(
    'command, new_command',
    [(Command('cargo buid', no_such_subcommand_old), 'cargo build'),
     (Command('cargo buils', no_such_subcommand), 'cargo build')])
def test_get_new_command(command, new_command):
    assert get_new_command(command) == new_command
Exemplo n.º 30
0
def test_get_new_command(script, output, result):
    new_command = get_new_command(Command(script, output))
    assert new_command[0] == result