Ejemplo n.º 1
0
def test_options():
    setup_context()
    decorators._other.clear()
    decorators.options = options_fun
    decorators.handle_options = handle_options
    assert decorators.options == [options_fun]
    decorators.commands = Command('build', build_fun)
    for com in decorators.commands:
        ctx.commands.add(com)
    handler = OptionHandler()
    handler.parse(['--foobar', '--enable-something',
                   '--argopt', 'foo=bar', 'build', '--foo', '1234',
                   '--hello-world', 'world'])
    assert handler.commands == ['build']
    assert ctx.options['foobar'].value
    assert ctx.options['something'].value
    arg = ctx.options['argopt'].value
    assert isinstance(arg, ArgumentCollection)
    arg = arg['foo']
    assert isinstance(arg, Argument)
    assert arg.name == 'foo'
    assert arg.value == 'bar'
    handler.handle_options()
    assert handler_called
    assert ctx.options.group('build')['foo'].value == 1234
    assert ctx.options.group('build')['hello_world'].value == 'world'
    # check alias
    assert ctx.options.group('dliub')['hello_world'].value == 'world'
    arg = Argument('hello_world').retrieve_all()
    assert arg.value == 'world'
Ejemplo n.º 2
0
def test_options2():
    setup_context()
    decorators._other.clear()
    decorators.options = options_fun2
    decorators.commands = Command('build', build_fun)
    for com in decorators.commands:
        ctx.commands.add(com)
    handler = OptionHandler()
    handler.parse(['-foo', '--bar', 'build'])
    assert handler.commands == ['build']
    assert ctx.options['something'].value