def schema_de():
    schema = Schema()
    schema['alpha'] = Int(default=10)
    schema['beta'] = Int(default=ROOT['alpha'] - 3)
    schema['sub'] = {}
    schema['sub']['x'] = Int(min=ROOT['beta'])
    schema['sub']['y'] = Int(default=ROOT['alpha'] + SECTION['x'])
    schema['sub']['z'] = Int(default=0)
    return schema
Пример #2
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() == """\
Пример #3
0
def macro_schema():
    schema = Schema()
    schema['a'] = Int()
    schema['b'] = Int()
    schema['c'] = IntChoice(choices=(SECTION['a'], SECTION['b']))
    schema['sub'] = {}
    schema['sub']['d'] = Int(min=ROOT['a'], max=ROOT['b'])
    schema['sub']['e'] = Int(default=ROOT['a'] + ROOT['b'] + SECTION['d'])
    return schema
Пример #4
0
def simple_validation(simple_schema_content, simple_section_content):
    schema = Schema(simple_schema_content)
    simple_section_content['a'] = -10
    simple_section_content['sub']['sa'] = 100.3
    simple_section_content['sub']['sb'] = "abc"
    simple_section_content['sub']['sc'] = True
    simple_section_content['sub']['subsub']['ssx'] = "omega"
    simple_section_content['sub']['subsub']['ssy'] = []
    config = Config(simple_section_content)
    return schema.validate(config)
Пример #5
0
def test_Config_err_disabled_macros_on_validation():
    from zirkon.config import ROOT
    config = Config(macros=False)
    schema = Schema()
    schema['x'] = Int()
    schema['y'] = Int(min=ROOT['x'] + 2)
    config['x'] = 3
    config['y'] = 5
    with pytest.raises(ValueError) as exc_info:
        validation = schema.validate(config)
    assert str(exc_info.value
               ) == "cannot evaluate ROOT['x'] + 2: macros are not enabled"
Пример #6
0
def schema():
    schema = Schema()
    schema['filename'] = Str()
    schema['run_mode'] = StrChoice(choices=("alpha", "beta", "gamma"))
    schema['values'] = {}
    schema['values']['x'] = Float(min=10.0, max=20.0)
    schema['values']['y'] = Float(min=10.0, max=20.0)
    schema['values']['z'] = Float(min=10.0, max=20.0)
    schema['operation'] = StrChoice(choices=("+", "-"))
    schema['parameters'] = {}
    schema['parameters']['max_iterations'] = Int(default=100)
    schema['parameters']['frequencies'] = FloatList(min_len=2)
    return schema
Пример #7
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() == """\
Пример #8
0
def test_Config_use_defaults_False(string_io, use_defaults):
    config = Config()
    schema = Schema(use_defaults=use_defaults)
    schema['x'] = Int(default=10)
    schema['sub'] = {'y': Int(default=20)}
    schema['sub']['sub'] = {'z': Int(default=30)}
    validation = schema.validate(config)
    assert config['x'] == 10
    assert config['sub']['y'] == 20
    assert config['sub']['sub']['z'] == 30
    assert not validation
    config.dump(string_io)
    if use_defaults:
        assert string_io.getvalue() == """\
[sub]
    [sub]
"""
    else:
        assert string_io.getvalue() == """\
Пример #9
0
def simple_schema(dictionary, simple_schema_content):
    schema = Schema(dictionary=dictionary, init=simple_schema_content)
    return schema
Пример #10
0
def test_Schema_create_dictionary_init(dictionary, simple_schema_content, string_io):
    schema = Schema(dictionary=dictionary, init=simple_schema_content)
    schema.dump(stream=string_io)
    assert string_io.getvalue() == SIMPLE_SCHEMA_DUMP
    assert len(dictionary) > 0
Пример #11
0
def test_Schema_create_dictionary(dictionary, string_io):
    schema = Schema(dictionary=dictionary)
    schema.dump(stream=string_io)
    assert string_io.getvalue() == ""
Пример #12
0
def test_Schema_create_empty(string_io):
    schema = Schema()
    schema.dump(stream=string_io)
    assert string_io.getvalue() == ""