Пример #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'})
Пример #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'
        })
Пример #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'
Пример #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 == {}
Пример #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'
Пример #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 == {}
Пример #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'}
Пример #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'}
Пример #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'}
Пример #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'}