Exemplo n.º 1
0
def test_filter_env_non_dict_in_match():
    """
    ~xxx syntax: should contain dict
    """
    yc = YamlConfig(env='foo')

    with pytest.raises(TypeError):
        yc.filter_env({'~foo': 'bar'})
Exemplo n.º 2
0
def test_filter_env_non_dict_in_match():
    """
    ~xxx syntax: should contain dict
    """
    yc = YamlConfig(env='foo')

    with pytest.raises(TypeError):
        yc.filter_env({
            '~foo': 'bar'
        })
Exemplo n.º 3
0
def test_filter_env_non_dict():
    """
    pass through non-dict elements
    """
    yc = YamlConfig(env='xx')
    result = yc.filter_env('foo')
    assert result == 'foo'
Exemplo n.º 4
0
def test_filter_env_remove():
    """
    ~xxx syntax: remove elements that not match
    """
    yc = YamlConfig(env='xx')
    result = yc.filter_env({'~foo': 'bar'})
    assert result == {}
Exemplo n.º 5
0
def test_filter_env_non_dict():
    """
    pass through non-dict elements
    """
    yc = YamlConfig(env='xx')
    result = yc.filter_env('foo')
    assert result == 'foo'
Exemplo n.º 6
0
def test_filter_env_remove():
    """
    ~xxx syntax: remove elements that not match
    """
    yc = YamlConfig(env='xx')
    result = yc.filter_env({
        '~foo': 'bar'
    })
    assert result == {}
Exemplo n.º 7
0
def test_filter_env_dict_no_env():
    """
    pass through dict elements without ~
    """
    yc = YamlConfig(env='xx')
    flexmock(yc).should_call('filter_env').with_args({'foo': 'bar'}).once()
    flexmock(yc).should_call('filter_env').with_args('bar').once()
    result = yc.filter_env({'foo': 'bar'})

    assert result == {'foo': 'bar'}
Exemplo n.º 8
0
def test_filter_env_dict_no_env():
    """
    pass through dict elements without ~
    """
    yc = YamlConfig(env='xx')
    flexmock(yc).should_call('filter_env').with_args({'foo': 'bar'}).once()
    flexmock(yc).should_call('filter_env').with_args('bar').once()
    result = yc.filter_env({'foo': 'bar'})

    assert result == {'foo': 'bar'}
Exemplo n.º 9
0
def test_filter_env_keep():
    """
    ~xxx syntax: keep elements that match
    """
    yc = YamlConfig(env='foo')
    flexmock(yc).should_call('filter_env').with_args({'~foo': {'bar': 'baz'}}).once().and_return({'bar': 'baz'})
    flexmock(yc).should_call('filter_env').with_args({'bar': 'baz'}).once().and_return({'bar': 'baz'})
    flexmock(yc).should_call('filter_env').with_args('baz').once().and_return('baz')
    result = yc.filter_env({
        '~foo': {'bar': 'baz'}
    })
    assert result == {'bar': 'baz'}
Exemplo n.º 10
0
def test_filter_env_keep():
    """
    ~xxx syntax: keep elements that match
    """
    yc = YamlConfig(env='foo')
    flexmock(yc).should_call('filter_env').with_args({
        '~foo': {
            'bar': 'baz'
        }
    }).once().and_return({'bar': 'baz'})
    flexmock(yc).should_call('filter_env').with_args({
        'bar': 'baz'
    }).once().and_return({'bar': 'baz'})
    flexmock(yc).should_call('filter_env').with_args('baz').once().and_return(
        'baz')
    result = yc.filter_env({'~foo': {'bar': 'baz'}})
    assert result == {'bar': 'baz'}