Ejemplo n.º 1
0
def test_retrieve_commands():
    setup_context()
    decorators._other.clear()
    # emulate the decorator
    command('empty')(empty_command_handler)
    command('yield')(task_yielder)
    command('return')(return_task)
    for com in decorators.commands:
        ctx.commands.add(com)
    tasks = retrieve_command_tasks('empty')
    assert len(tasks) == 0
    try:
        retrieve_command_tasks('not-existing')
        assert False
    except NoSuchCommandError:
        pass
    tasks = retrieve_command_tasks('yield')
    test_tasks = []
    for t in tasks.values():
        if isinstance(t, TestTask):
            test_tasks.append(t)
    assert len(test_tasks) == 3
    tasks = retrieve_command_tasks('return')
    test_tasks = []
    for t in tasks.values():
        if isinstance(t, TestTask):
            test_tasks.append(t)
    assert len(test_tasks) == 2
Ejemplo n.º 2
0
def test_argument_retrieve():
    setup_context()
    meta = Metadata()
    meta.foo = 'bar'
    setup_context()
    ctx.meta = meta
    # test retrieval from ctx.env
    ctx.env['FOO'] = 'bar'
    arg = Argument('foo').retrieve(ctx.env)
    assert arg.value == 'bar'
    # test if argument is not present
    del ctx.env['FOO']
    arg = Argument('foo').retrieve(ctx.env)
    arg.retrieve(ctx.env)
    assert arg.value is None
    assert arg.is_empty
    # test retrieval from meta
    arg = Argument('foo').retrieve(ctx.meta)
    assert arg.value == 'bar'
    col = OptionsCollection()
    col.add(StringOption('foo', 'Enables foo for testing.', keys='somethingelse'))
    col.retrieve_from_dict({'foo': 'bar'})
    arg = Argument('foo').retrieve(col)
    assert arg.value == 'bar'
    arg = Argument('foo').retrieve({'foo': 'bar'})
    assert arg.value == 'bar'
    col = ArgumentCollection.from_dict({'foo': 'bar'})
    arg = Argument('foo').retrieve(col)
    assert arg.value == 'bar'
    arg = Argument('foo').retrieve('bar')
    assert arg.value == 'bar'
Ejemplo n.º 3
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.º 4
0
def test_file_node():
    setup_context()
    curdir = directory(__file__)
    testdir = curdir.join("test-dir")
    testdir.remove()
    testdir.ensure_exists()
    testfile = testdir.join("test-file.txt").path
    node = FileNode(testfile)
    node.signature().refresh()
    assert node.signature().value is None
    assert not node.signature().valid
    with open(testfile, "w") as f:
        f.write("asdf")
    assert not node.signature().valid
    node.signature().refresh()
    assert node.signature().valid
    v = node.signature().value
    assert v is not None
    with open(testfile, "w") as f:
        f.write("blabla")
    node.signature().refresh()
    assert node.signature().valid
    newv = node.signature().value
    assert newv != v
    assert newv is not None
    with open(testfile, "w") as f:
        f.write("asdf")
    node.signature().refresh()
    assert node.signature().value == v
Ejemplo n.º 5
0
def test_g():
    setup_context()
    failed = False
    try:
        foobar = ctx.g.test
    except AttributeError:
        failed = True
    assert failed
    ctx.g.test = {'foo': 'bar'}
    assert ctx.g.test['foo'] == 'bar'
Ejemplo n.º 6
0
def test_commands():
    setup_context()
    com = Command('build', _test_commandfun, description='Build a command.',
            depends='configure', produce=':build', option_alias='test', skip_as_depenency=True)
    assert com.name == 'build'
    assert com.depends[0] == 'configure'
    assert com.run() == 'result-of-testfun'
    command_cache = ctx.cache.prefix('commands')
    command_cache['build'] = {}
    command_cache['build']['success'] = True
    assert com.run(True) is None
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def test_symbolic_node():
    setup_context()
    node = SymbolicNode("asdf")
    data = node.read()
    node.signature().refresh()
    assert not node.signature().valid
    assert node.signature().value is None
    assert isinstance(data, ArgumentCollection)
    data.update(x=3)
    assert data["x"].value == 3
    node.write(data)
    node.signature().refresh()
    assert node.signature().valid
    v = node.signature().value
    assert v is not None
    node2 = SymbolicNode("asdf")
    assert node2.read()["x"].value == 3
    assert node2.signature().value == v