Пример #1
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'
Пример #2
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'
Пример #3
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'])
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
Пример #5
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'))
Пример #6
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/")
Пример #7
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('', ''))
Пример #8
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)
Пример #9
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)))
Пример #10
0
def test_side_effect(ssh_error):
    errormsg, path, reset, known_hosts = ssh_error
    command = Command('ssh user@host', errormsg)
    side_effect(command, None)
    expected = [
        '123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n'
    ]
    assert known_hosts(path) == expected
Пример #11
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'}
Пример #12
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', ''))
Пример #13
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', ''))
Пример #14
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', ''))
Пример #15
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[0], test[4])
    settings.fixcolcmd = '{editor} {file} +{line}:{col}'

    if test[3]:
        assert (get_new_command(cmd) == u'dummy_editor {} +{}:{} && {}'.format(
            test[1], test[2], test[3], test[0]))
    else:
        assert (get_new_command(cmd) == u'dummy_editor {} +{} && {}'.format(
            test[1], test[2], test[0]))
Пример #16
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('thedick.corrector.get_rules', return_value=rules)
    assert ([cmd.script for cmd in get_corrected_commands(command)
             ] == ['test!', 'test@', 'test;'])
Пример #17
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.'
        ))
Пример #18
0
def test_get_new_command(cmd, result):
    command = Command('heroku {}'.format(cmd), suggest_output)
    assert get_new_command(command) == result
Пример #19
0
def test_not_match(script, output):
    assert not match(Command(script, output))
Пример #20
0
def test_match(cmd):
    assert match(Command('heroku {}'.format(cmd), suggest_output))
Пример #21
0
 def test_get_valid_history_without_current(self, script, result):
     command = Command(script, '')
     assert get_valid_history_without_current(command) == result
Пример #22
0
def test_for_app(script, names, result):
    @for_app(*names)
    def match(command):
        return True

    assert match(Command(script, '')) == result
Пример #23
0
def test_is_app(script, names, result):
    assert is_app(Command(script, ''), *names) == result
Пример #24
0
def test_match():
    assert match(Command('apt list --upgradable', match_output))
    assert match(Command('sudo apt list --upgradable', match_output))
Пример #25
0
squashfs-tools/zesty-updates 1:4.3-3ubuntu2.17.04.1 amd64 [upgradable from: 1:4.3-3ubuntu2]
unattended-upgrades/zesty-updates,zesty-updates 0.93.1ubuntu2.4 all [upgradable from: 0.93.1ubuntu2.3]
'''

no_match_output = '''
Listing... Done
'''


def test_match():
    assert match(Command('apt list --upgradable', match_output))
    assert match(Command('sudo apt list --upgradable', match_output))


@pytest.mark.parametrize('command', [
    Command('apt list --upgradable', no_match_output),
    Command('sudo apt list --upgradable', no_match_output)
])
def test_not_match(command):
    assert not match(command)


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'
def test_get_new_command(script, result):
    command = Command(script, output)
    assert get_new_command(command) == result
    deloyp

Available commands:

    update_config
    prepare_extension
    Template               A string class for supporting $-substitutions.
    deploy
    glob                   Return a list of paths matching a pathname pattern.
    install_web
    set_version
'''


@pytest.mark.parametrize('command', [
    Command('fab extenson', output),
    Command('fab deloyp', output),
    Command('fab extenson deloyp', output)
])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize(
    'command', [Command('gulp extenson', output),
                Command('fab deloyp', '')])
def test_not_match(command):
    assert not match(command)


@pytest.mark.parametrize('script, result', [
Пример #28
0
def test_get_new_command(before, after):
    command = Command(before, output)
    assert get_new_command(command) == after
Пример #29
0
def test_not_match(isdir, script, output, isdir_result):
    isdir.return_value = isdir_result
    command = Command(script, output)
    assert not match(command)
Пример #30
0
def test_match(isdir, script, output):
    isdir.return_value = True
    command = Command(script, output)
    assert match(command)