Exemplo n.º 1
0
def test_pillar_KeyPath_parent_dict():
    key_dict = {'1': {'2': '3'}}
    assert KeyPath('1/2').parent_dict(key_dict) is key_dict['1']

    with pytest.raises(KeyError):
        KeyPath('1/4/5').parent_dict(key_dict, fix_missing=False)

    assert KeyPath('1/4/5').parent_dict(key_dict) is key_dict['1']['4']
Exemplo n.º 2
0
def test_param_Param_init():
    name = '1/2/3'
    kp = '6/7/8'
    fp = 'q/w/e'

    for _kp in (kp, Path(kp), KeyPath(kp)):
        assert Param(name, _kp) == Param(name, PillarKey(kp))
    assert Param(name, (kp, fp)) == Param(name, PillarKey(kp, fp))
Exemplo n.º 3
0
def test_pillar_PillarKey_init():
    keypath = '1/2/3/4/5'
    assert PillarKey(keypath) == PillarKey(keypath, '1.sls')
    assert PillarKey(keypath, 'some.sls').fpath == Path('some.sls')
    assert PillarKey(keypath, Path('some.sls')).fpath == Path('some.sls')
    assert PillarKey(keypath) == PillarKey(KeyPath(keypath))
    # short keypath
    assert PillarKey('1') == PillarKey('1', '1.sls')
    # incorrect keypaths
    with pytest.raises(TypeError):
        PillarKey(None)
    for kp in ('', '.', '/'):
        with pytest.raises(ValueError):
            PillarKey(kp)
Exemplo n.º 4
0
def test_pillar_KeyPath_is_hashable():
    hash(KeyPath('1/2/3'))
Exemplo n.º 5
0
def test_pillar_KeyPath_value():
    key_dict = {'1': {'2': '3'}}
    assert KeyPath('1/2').value(key_dict) == '3'

    with pytest.raises(KeyError):
        KeyPath('1/3').value(key_dict)
Exemplo n.º 6
0
def test_pillar_KeyPath_leaf():
    assert KeyPath('1/2').leaf == '2'
Exemplo n.º 7
0
def test_pillar_KeyPath_parent():
    assert KeyPath('1/2/3/4').parent == KeyPath('1/2/3')
Exemplo n.º 8
0
def test_pillar_KeyPath_truediv():
    path = '1/2/3/4/5'
    assert KeyPath(path) / '6' == KeyPath(Path(path) / '6')
Exemplo n.º 9
0
def test_pillar_KeyPath_to_str():
    path = '1/2/3/4/5'
    assert str(KeyPath(path)) == str(Path(path))
Exemplo n.º 10
0
def test_pillar_KeyPath_init():
    with pytest.raises(TypeError):
        KeyPath(None)