Example #1
0
def test_create_template_from_schema(string_io):
    schema = Schema()
    schema['m0'] = Int(default=3)
    schema['m1'] = Int(default=ROOT['m0'] + 1)
    config = Config()
    create_template_from_schema(schema, config=config)
    
    config.dump(stream=string_io)
    assert string_io.getvalue() == """\
Example #2
0
def test_create_template_from_schema(string_io):
    schema = Schema()
    schema['m0'] = Int(default=3)
    schema['m1'] = Int()
    schema['alpha'] = Float(default=0.5)
    schema['input_file'] = Str(min_len=1)
    schema['data'] = {}
    schema['data']['i'] = Int(max=10)
    schema['data']['isub'] = {}
    schema['data']['isub']['a'] = Str()
    schema['data']['isub']['b'] = Str(default='bc')
    schema['data']['isub']['c'] = Str(default=SECTION['b'] * ROOT['m0'])
    schema['data']['isub']['d'] = Str(default=SECTION['b'] * ROOT['m1'])
    schema['data']['j'] = Int(default=2)
    config = create_template_from_schema(schema)
    config.dump(stream=string_io)
    assert string_io.getvalue() == """\
Example #3
0
def test_create_template_from_schema_with_defaults(include_default_kwargs):
    schema = Schema.from_string("""\
[a]
    x = Int(default=11)
    __default_option__ = Str()
[__default_section__]
    y = Float(default=5.5)
    """, fmt="zirkon")
    include_default_sections = include_default_kwargs.get("include_default_sections", False)
    include_default_options = include_default_kwargs.get("include_default_options", False)
    print(include_default_kwargs)
    config = create_template_from_schema(schema, **include_default_kwargs)
    config.dump()
    if include_default_options:
        assert "__default_option__" in config["a"]
    else:
        assert not "__default_option__" in config["a"]
    if include_default_sections:
        assert "__default_section__" in config
    else:
        assert not "__default_section__" in config
Example #4
0
def test_create_template_from_schema_error(string_io):
    with pytest.raises(TypeError):
        create_template_from_schema(123)