Exemplo n.º 1
0
def test_defaults():
    command, options = args.parse(
        ['test', '--num', '1', '--help', '--stuff', 'The remainder.'])
    args.ensure_defaults(options, {'num': 2, 'help': True, 'stuff': None})
    assert options['help'] == True
    assert options['num'] == 1

    command, options = args.parse(
        ['test', '--num', '1', '--help', '--stuff', 'The remainder.'])
    args.ensure_defaults(options, {
        'num': 2,
        'extras': 3,
        'help': None,
        'stuff': None
    })
    assert options['extras'] == 3
    assert options['num'] == 1

    assert_raises(args.ArgumentError, args.ensure_defaults, options, {
        'num': 2,
        'extras': 3,
        'help': None,
        'TRAILING': None
    })

    assert_raises(args.ArgumentError, args.ensure_defaults, options, {
        'num': 2,
        'extras': 3,
        'help': None,
        'bad': None
    })
def test_parse():
    command, options = args.parse(['test', '--num', '1', '--help', '--stuff', 'The remainder.', '--tail'])
    assert command, "There should be a command."
    assert options, "There should be options."

    assert command == "test", "command should be test"
    assert options["num"] == 1, "num option wrong"
    assert options["help"] == True, "help should be true"
    assert options["stuff"] == 'The remainder.', "stuff should a string"
    assert options['tail'] == True, "There should be a True tail."

    command2, options = args.parse(['--num', '1', '--help', '--stuff', 'The remainder.'])
    assert not command2, "There should NOT be a command."
    assert options, "There should be options."
    assert options["num"] == 1, "num option wrong"
    assert options["help"] == True, "help should be true"
    assert options["stuff"] == 'The remainder.', "stuff should a string"

    _, options = args.parse(['--foo', 'True', '--bar', 'False'])
    assert options['foo']
    assert not options['bar']

    _, options = args.parse(['--foo', 'true', '--bar', 'false'])
    assert options['foo']
    assert not options['bar']

    _, options = args.parse(['--foo', 'yes', '--bar', 'no'])
    assert options['foo']
    assert not options['bar']
Exemplo n.º 3
0
def test_parse():
    command, options = args.parse([
        'test', '--num', '1', '--help', '--stuff', 'The remainder.', '--tail'
    ])
    assert command, "There should be a command."
    assert options, "There should be options."

    assert command == "test", "command should be test"
    assert options["num"] == 1, "num option wrong"
    assert options["help"] == True, "help should be true"
    assert options["stuff"] == 'The remainder.', "stuff should a string"
    assert options['tail'] == True, "There should be a True tail."

    command2, options = args.parse(
        ['--num', '1', '--help', '--stuff', 'The remainder.'])
    assert not command2, "There should NOT be a command."
    assert options, "There should be options."
    assert options["num"] == 1, "num option wrong"
    assert options["help"] == True, "help should be true"
    assert options["stuff"] == 'The remainder.', "stuff should a string"

    _, options = args.parse(['--foo', 'True', '--bar', 'False'])
    assert options['foo']
    assert not options['bar']

    _, options = args.parse(['--foo', 'true', '--bar', 'false'])
    assert options['foo']
    assert not options['bar']

    _, options = args.parse(['--foo', 'yes', '--bar', 'no'])
    assert options['foo']
    assert not options['bar']
def test_trailing():
    command, options = args.parse(['test', '--num', '1', '--', 'Trailing 1', 'Trailing 2'])
    expected = ['Trailing 1', 'Trailing 2']
    assert command == 'test'
    assert options['TRAILING']
    for e in expected: assert e in options['TRAILING']

    # test with a corner case of a switch option before trailing
    command, options = args.parse(['test', '--num', '1', '--switch', '--', 'Trailing 1', 'Trailing 2'])
    for e in expected: assert e in options['TRAILING']
Exemplo n.º 5
0
def test_trailing():
    command, options = args.parse(
        ['test', '--num', '1', '--', 'Trailing 1', 'Trailing 2'])
    expected = ['Trailing 1', 'Trailing 2']
    assert command == 'test'
    assert options['TRAILING']
    for e in expected:
        assert e in options['TRAILING']

    # test with a corner case of a switch option before trailing
    command, options = args.parse(
        ['test', '--num', '1', '--switch', '--', 'Trailing 1', 'Trailing 2'])
    for e in expected:
        assert e in options['TRAILING']
Exemplo n.º 6
0
def main():
    # O modargs sempre espera que a chamada da linha de comando tenha sido
    # $ prog command args
    # Por isso ignoramos o primeiro item da tupla retornada por ele.

    _, params = args.parse(sys.argv[1:])

    _validate_params(params)

    user = os.environ['user']
    key =  os.environ['key']
    container = params.get('container', None)
    dryrun = params.get('dryrun', False)
    rule = params.get('rule', None)
    rule_param = params.get('ruleparam', None)

    rule_instance = AVAILABLE_RULES[rule](rule_param)

    try:
        deleted = collect(container=container, dryrun=dryrun, rule=rule_instance, user=user, key=key)
        print deleted
        print "Removing {0} objects from container {1}".format(len(deleted), container)
    except AuthenticationFailed as auth:
        print "User or API KEY wrong ", auth.message
    except NoSuchContainer as nocontainer:
        print "No such container: ", nocontainer.message
    except Exception as e:
        print "Ops, an error ocurred : ", e.message
        import traceback
        traceback.print_exc()
    sys.exit(0)
def test_defaults():
    command, options = args.parse(['test', '--num', '1', '--help', '--stuff', 'The remainder.'])
    args.ensure_defaults(options, {'num': 2, 'help': True, 'stuff': None})
    assert options['help'] == True
    assert options['num'] == 1

    command, options = args.parse(['test', '--num', '1', '--help', '--stuff', 'The remainder.'])
    args.ensure_defaults(options, {'num': 2, 'extras': 3, 'help': None, 
                                   'stuff': None})
    assert options['extras'] == 3
    assert options['num'] == 1


    assert_raises(args.ArgumentError,
                  args.ensure_defaults,
                  options, {'num': 2, 'extras': 3, 'help': None, 'TRAILING': None})

    assert_raises(args.ArgumentError,
                  args.ensure_defaults,
                  options, {'num': 2, 'extras': 3, 'help': None, 'bad': None})
def test_multiple_kwargs():
    options = args.parse(['testmanykwargs', '-foo', 'bar', '-foo', 'baz'])[1]
    assert options['foo'] == ['bar', 'baz']
    options = args.parse(['testmanykwargs', '-foo', 'bar', '-foo', 'baz', '-foo', 'bag'])[1]
    assert options['foo'] == ['bar', 'baz', 'bag']
Exemplo n.º 9
0
def test_multiple_kwargs():
    options = args.parse(['testmanykwargs', '-foo', 'bar', '-foo', 'baz'])[1]
    assert options['foo'] == ['bar', 'baz']
    options = args.parse(
        ['testmanykwargs', '-foo', 'bar', '-foo', 'baz', '-foo', 'bag'])[1]
    assert options['foo'] == ['bar', 'baz', 'bag']