示例#1
0
def test_undefine_with_defaultvalue():
    default = 'hi'
    v = Value(KEY, default=default)
    v.value = 'x'
    assert v.value == 'x'
    v.value = None
    assert v.value == default
示例#2
0
 class TestConf(GoodConf):
     "Configuration for My App"
     a = Value(help=help_, default=5)
     b = Value()
示例#3
0
def test_required_no_value():
    v = Value(KEY)
    with pytest.raises(RequiredValueMissing):
        v.value = None
示例#4
0
def test_initial_bad():
    with pytest.raises(ValueError):
        Value(KEY, initial='x')
示例#5
0
def test_no_initial():
    v = Value(KEY)
    assert v.initial == ''
示例#6
0
def test_explicit_cast():
    v = Value(KEY, cast_as=bool)
    assert v.cast_as == bool
示例#7
0
def test_initial():
    v = Value(KEY, initial=lambda: 'x')
    assert v.initial == 'x'
示例#8
0
 class BadConf(GoodConf):
     a = Value(key='not_a')
示例#9
0
 class MyConf(GoodConf):
     a = Value()
     b = Value(default='fish')
示例#10
0
 class ParentConf(GoodConf):
     a = Value()
示例#11
0
 class ChildConf(ParentConf):
     b = Value()
示例#12
0
 class TestConf(GoodConf):
     a = Value()
示例#13
0
 class TestConf(GoodConf):
     a = Value(default=False)
示例#14
0
 class TestConf(GoodConf):
     a = Value(help=help_, default=5)
     b = Value()
示例#15
0
def test_default_cast():
    """Default cast is str"""
    v = Value(KEY)
    assert v.cast_as == str
示例#16
0
 class TestConf(GoodConf):
     a = Value(default='')
     c = Value(default=4)
示例#17
0
def test_default_callable():
    v = Value(KEY, default=lambda: 's')
    assert v.value == 's'
示例#18
0
 class TestConf(GoodConf):
     a = Value(initial=lambda: True)
     b = Value(default=False)
示例#19
0
def test_cast_bool():
    v = Value(KEY, cast_as=bool)
    with env_var(KEY, 'true'):
        assert v.value is True
    with env_var(KEY, 'false'):
        assert v.value is False
示例#20
0
 class TestConf(GoodConf):
     a = Value(initial=lambda: True)
示例#21
0
def test_default_not_required():
    """Values with a default are not required"""
    v = Value(KEY, default='s')
    assert v.required is False
示例#22
0
 class TestConf(GoodConf):
     "Configuration for My App"
     a = Value(help="this is a")
     b = Value()
示例#23
0
def test_initial_default():
    v = Value(KEY, default='x')
    assert v.initial == 'x'
示例#24
0
 class MyConf(GoodConf):
     a = Value()
     c = Value()
     b = Value()
示例#25
0
def test_defined_value():
    v = Value(KEY)
    v.value = 'x'
    assert v.value == 'x'
示例#26
0
def test_no_default_required():
    """Values with a default are not required"""
    v = Value(KEY)
    assert v.required is True
示例#27
0
def test_env_var_precedence():
    v = Value(KEY)
    with env_var(KEY, 'y'):
        v.value = 'x'
        assert v.value == 'y'
示例#28
0
def test_infer_cast():
    """If not provided, cast is type of default"""
    v = Value(KEY, default=5)
    assert v.cast_as == int
示例#29
0
def test_cast_list():
    v = Value(KEY, cast_as=list)
    with env_var(KEY, 'a,b,c'):
        assert v.value == ['a', 'b', 'c']
示例#30
0
 class TestConf(GoodConf):
     a = Value(help="this is a")