def test_register_generator():
    """
    Test both style of generator registration.
    """

    clear_generator_registrations()
    register_generator('test-lang',
                       target='Java',
                       description='test-lang Java generator',
                       generator=generator_callable)

    generator = generator_description('test-lang', 'java')

    assert type(generator) is GeneratorDesc
    assert generator.language == 'test-lang'
    assert generator.target == 'Java'
    assert generator.description == 'test-lang Java generator'
    assert generator.generator == generator_callable

    clear_generator_registrations()
    register_generator(GeneratorDesc('test-lang',
                                     target='Java',
                                     description='test-lang Java generator',
                                     generator=generator_callable))

    generator = generator_description('test-lang', 'java')

    assert type(generator) is GeneratorDesc
    assert generator.language == 'test-lang'
    assert generator.target == 'Java'
    assert generator.description == 'test-lang Java generator'
    assert generator.generator == generator_callable
def test_asking_for_unregistered_generator_raises_error():
    """
    Test searching for unexisting generator raises an error.
    """
    with pytest.raises(TextXRegistrationError, match='.*No generators.*'):
        generator_description('flow-dsl', 'unexisting_target')

    with pytest.raises(TextXRegistrationError, match='.*No generators.*'):
        generator_description('unexisting_language', 'unexisting_target')
def test_declaratively_registered_generator_always_available():
    """
    Declaratively registered generators will be re-registered at the first API
    call.
    """
    clear_generator_registrations()
    generator = generator_description('flow-dsl', 'plantuml')

    assert generator.language == 'flow-dsl'
    assert generator.target == 'PlantUML'
    assert callable(generator.generator)
    assert generator.project_name == 'flow-codegen'