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'
Example #2
0
az: 'providers' is not in the 'az' command group. See 'az --help'.

The most similar choice to 'providers' is:
    provider
'''

misspelled_subcommand = '''\
az provider: 'lis' is not in the 'az provider' command group. See 'az provider --help'.

The most similar choice to 'lis' is:
    list
'''


@pytest.mark.parametrize('command', [
    Command('az providers', misspelled_command),
    Command('az provider lis', misspelled_subcommand)
])
def test_match(command):
    assert match(command)


def test_not_match():
    assert not match(Command('az provider', no_suggestions))


@pytest.mark.parametrize('command, result', [
    (Command('az providers list', misspelled_command), ['az provider list']),
    (Command('az provider lis', misspelled_subcommand), ['az provider list'])
])
def test_get_new_command(command, result):
Example #3
0
def test_get_new_command(script, output, new_command):
    assert get_new_command(Command(script, output)) == new_command
Example #4
0
def test_not_match(script):
    assert not match(Command(script, ''))
Example #5
0
def test_match(output, script):
    assert match(Command(script, output))
def test_get_new_command(output):
    new_command = get_new_command(Command('sudo apt update', output))
    assert new_command == 'sudo apt list --upgradable'

    new_command = get_new_command(Command('apt update', output))
    assert new_command == 'apt list --upgradable'
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'
Example #8
0
def test_get_new_command():
    new_command = get_new_command(Command('apt-get search foo', ''))
    assert new_command == 'apt-cache search foo'
Example #9
0
def test_get_new_command(set_help, output, script, help_text, result):
    set_help(help_text)
    assert get_new_command(Command(script, output))[0] == result
Example #10
0
def test_not_match(script, output):
    assert not match(Command(script, output))
Example #11
0
def test_not_match():
    assert not match(Command('aws dynamodb invalid', no_suggestions))
Example #12
0
  aws <command> <subcommand> help
aws: error: argument operation: Invalid choice, valid choices are:

describe-table                           | get-item
list-tables                              | put-item


Invalid choice: 't-item', maybe you meant:

  * put-item
  * get-item
'''


@pytest.mark.parametrize('command', [
    Command('aws dynamdb scan', misspelled_command),
    Command('aws dynamodb scn', misspelled_subcommand),
    Command('aws dynamodb t-item',
            misspelled_subcommand_with_multiple_options)])
def test_match(command):
    assert match(command)


def test_not_match():
    assert not match(Command('aws dynamodb invalid', no_suggestions))


@pytest.mark.parametrize('command, result', [
    (Command('aws dynamdb scan', misspelled_command),
     ['aws dynamodb scan']),
    (Command('aws dynamodb scn', misspelled_subcommand),
def test_match():
    assert match(Command('apt list --upgradable', match_output))
    assert match(Command('sudo apt list --upgradable', match_output))
Example #14
0
def test_not_match():
    assert not match(Command('az provider', no_suggestions))
Get:22 http://security.ubuntu.com/ubuntu zesty-security/multiverse amd64 DEP-11 Metadata [208 B]
Fetched 1,673 kB in 0s (1,716 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
'''


@pytest.mark.parametrize('output', match_output)
def test_match(output):
    assert match(Command('sudo apt update', output))


@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', ''),
    Command('sudo apt update', no_match_output)
])
def test_not_match(command):
    assert not match(command)


@pytest.mark.parametrize('output', match_output)
def test_get_new_command(output):
Example #16
0
import pytest
from theplease.rules.apt_get_search import get_new_command, match
from theplease.types 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():
    new_command = get_new_command(Command('apt-get search foo', ''))
    assert new_command == 'apt-cache search foo'
def test_match(output):
    assert match(Command('sudo apt update', output))
Example #18
0
def test_match():
    assert match(Command('apt-get search foo', ''))
Example #19
0
import pytest
from theplease.rules.apt_get import match, get_new_command
from theplease.types import Command


@pytest.mark.parametrize('command, packages', [
    (Command('vim', 'vim: command not found'), [('vim', 'main'),
                                                ('vim-tiny', 'main')]),
    (Command('sudo vim', 'vim: command not found'), [('vim', 'main'),
                                                     ('vim-tiny', 'main')]),
    (Command(
        'vim',
        "The program 'vim' is currently not installed. You can install it by typing: sudo apt install vim"
    ), [('vim', 'main'), ('vim-tiny', 'main')])
])
def test_match(mocker, command, packages):
    mocker.patch('theplease.rules.apt_get.which', return_value=None)
    mocker.patch('theplease.rules.apt_get._get_packages',
                 create=True,
                 return_value=packages)

    assert match(command)


@pytest.mark.parametrize(
    'command, packages, which',
    [(Command('a_bad_cmd', 'a_bad_cmd: command not found'), [], None),
     (Command('vim', ''), [], None), (Command('', ''), [], None),
     (Command('vim', 'vim: command not found'), ['vim'], '/usr/bin/vim'),
     (Command('sudo vim', 'vim: command not found'), ['vim'], '/usr/bin/vim')])
def test_not_match(mocker, command, packages, which):