Пример #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
Пример #2
0
def test_generator():
    if curdir.join('test-dir').exists:
        curdir.join('test-dir').remove(recursive=True)
    testdir = curdir.mkdir('test-dir')
    with open(testdir.join('test.txt').path, 'w') as f:
        f.write('foobar')
    os.chdir(curdir.path)
    # startup
    init_context(testdir)
    # first stage - add generator
    generator = DummyGenerator()
    ctx.generators('generator-test').add(generator)
    # shutdown => save the context
    ctx.save()
    # restart => reload the context
    init_context(testdir)
    for com in wasp.decorators.commands:
        ctx.commands.add(com)
    # run the command
    tasks = retrieve_command_tasks('generator-test')
    assert isinstance(tasks[first(tasks)], CopyTask)
    generators = ctx.generators('generator-test')
    assert isinstance(generators, GeneratorCollection)
    assert isinstance(generators['foobar'], DummyGenerator)