Ejemplo n.º 1
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)