Ejemplo n.º 1
0
def test_field_initiate(test_config):
    field = fields.Field()
    section = 'section_1'
    option = 'string_option'
    field(test_config, section, option)

    assert field._initiated is True
    assert field._value is test_config.get(section, option)
Ejemplo n.º 2
0
def test_required_no_option(test_config):
    field = fields.Field()
    section = 'section_1'
    option = 'does not exist too'
    with pytest.raises(fields.MissingFieldError) as error:
        field(test_config, section, option)
    assert error.value.args[
        0] == f'Option "{option}" in section "{section}" is required.'
    assert isinstance(error.value.args[1], configparser.NoOptionError)
Ejemplo n.º 3
0
def test_not_required(test_config):
    field = fields.Field(required=False)
    section = 'is not required'
    option = 'is not required'
    field(test_config, section, option)

    assert field._initiated is True
    assert field._required is False
    assert field._value is None
Ejemplo n.º 4
0
def test_default(test_config):
    default_value = 'DEFAULT'
    field = fields.Field(default=default_value)
    section = 'is default'
    option = 'is default'
    field(test_config, section, option)

    assert field._initiated is True
    assert field._required is True
    assert field._default is default_value
    assert field._value is default_value
Ejemplo n.º 5
0
 class Section1(manager.Section):
     string_option = fields.Field(frozen=True)
Ejemplo n.º 6
0
 class Section2(manager.Section):
     option = fields.Field()
Ejemplo n.º 7
0
 class Section1(manager.Section):
     string_option = fields.Field()
     bool_option = fields.BoolField()
     int_option = fields.IntField()
     float_option = fields.FloatField()
Ejemplo n.º 8
0
 class Section1(manager.Section):
     unspecified_option = fields.Field()
     unspecified_option_2 = fields.IntField()
Ejemplo n.º 9
0
 class Section1(manager.Section):
     unspecified_option = fields.Field(default=default_value)
     unspecified_option_2 = fields.IntField(default=10)
Ejemplo n.º 10
0
def test_field_create():
    field = fields.Field()

    assert field._initiated is False
    assert field._required is True
    assert field._default is field._UNSET