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