Exemple #1
0
def test_bad_layer():
    clac = CLAC()
    clac.remove_layer('none')
    with raises(MissingLayer):
        clac.remove_layer('none', error_ok=False)

    with raises(MissingLayer):
        clac.get('key', layer_name='none')
Exemple #2
0
def test_mutate_existing_key(mutable_layers):
    mutable_clac = CLAC(*mutable_layers)

    unique = object()

    assert mutable_clac.get('test_key') == 'test_value_alpha'
    assert mutable_clac.get('test_key', layer_name='beta') == 'test_value_beta'
    mutable_clac['test_key'] = unique
    assert mutable_clac.get('test_key') == 'test_value_alpha'
    assert mutable_clac.get('test_key', layer_name='beta') is unique
Exemple #3
0
def test_get_from_one_layer(clac_layers):
    alpha = clac_layers[0]
    simple_clac = CLAC(alpha)

    assert 'alpha' in simple_clac
    assert 'test_key' in simple_clac.names
    result1 = simple_clac['test_key']
    result2 = simple_clac.get('test_key')
    result3 = simple_clac.get('test_key', layer_name='alpha')
    assert result1 is result2 is result3
    assert result1 == 'test_value_alpha'
Exemple #4
0
def test_add_new_key(mutable_layers):
    mutable_clac = CLAC(*mutable_layers)

    unique = object()
    default = object()

    assert mutable_clac.get('new_key', default=default) is default
    assert mutable_clac.get('new_key', layer_name='beta',
                            default=default) is default
    mutable_clac['new_key'] = unique
    assert mutable_clac.get('new_key', default=default) is unique
    assert mutable_clac.get('new_key', layer_name='beta',
                            default=default) is unique
Exemple #5
0
def test_setdefault(mutable_layers):
    mutable_clac = CLAC(*mutable_layers)

    unique = object()
    default = object()

    assert mutable_clac.get('new_key', default=default) is default
    assert mutable_clac.get('new_key', layer_name='beta',
                            default=default) is default
    mutable_clac.setdefault('new_key', unique)
    assert mutable_clac.setdefault('new_key', 'acbde') is unique
    assert mutable_clac.get('new_key', default=default) is unique
    assert mutable_clac.get('new_key', layer_name='beta',
                            default=default) is unique
Exemple #6
0
def test_add_layer(clac_layers):
    alpha, beta, _ = clac_layers
    cfg = CLAC(alpha)

    assert cfg['test_key'] == 'test_value_alpha'
    with raises(NoConfigKey):
        _ = cfg['beta_secret']
    with raises(MissingLayer):
        cfg.get('test_key', layer_name='beta')

    cfg.add_layers(beta)

    assert cfg['test_key'] == 'test_value_alpha'
    assert cfg['beta_secret'] == 'fghij'
    assert cfg.get('test_key', layer_name='beta') == 'test_value_beta'
Exemple #7
0
def test_multi_layer_priority(clac_layers):
    alpha, beta, _ = clac_layers
    cfg = CLAC(alpha, beta)

    assert 'alpha' in cfg
    assert 'beta' in cfg
    assert 'test_key' in cfg.names
    assert 'beta_secret' in cfg.names
    assert cfg['test_key'] == 'test_value_alpha'
    assert cfg.get('test_key', layer_name='beta') == 'test_value_beta'
    assert cfg['beta_secret'] == 'fghij'
Exemple #8
0
def test_get_callback(clac_layers):
    simple_clac = CLAC(*clac_layers)

    assert simple_clac.get('unique', callback=int) == 123456789
    assert simple_clac.get('missing', default='not a list',
                           callback=list) == 'not a list'
Exemple #9
0
def test_get_default(clac_layers):
    simple_clac = CLAC(*clac_layers)
    default = object()
    assert simple_clac.get('missingkey', default=default) is default