Ejemplo n.º 1
0
def test_config_merge():
    config = Configuration({
            'foo': [4, 2],
            'bar': {
                    'child1': 'one',
                    'child2': 'two'
                }
        })
    other = Configuration({
            'baz': True,
            'blah': 'blah blah',
            'bar': {
                    'child1': 'other one',
                    'child10': 'ten'
                }
        })
    config.merge(other)

    expected = {
            'foo': [4, 2],
            'baz': True,
            'blah': 'blah blah',
            'bar': {
                'child1': 'other one',
                'child2': 'two',
                'child10': 'ten'
                }
            }
    assert config.getAll() == expected
Ejemplo n.º 2
0
def test_config_merge_with_mode(mode, expected):
    config = Configuration({
        'foo': [4, 2],
        'bar': 'something'
    })
    other = {'foo': [1, 0], 'bar': 'other thing'}
    config.merge(other, mode=mode)
    assert config.getAll() == expected
Ejemplo n.º 3
0
def test_config_deep_set_existing():
    config = Configuration({'foo': 'bar', 'baz': {'wat': 'nothing'}})
    assert config.has('baz') is True
    assert config.get('baz/wat') == 'nothing'
    assert config.get('baz/or') is None
    config.set('baz/or/whatever', 'something')
    assert config.has('baz') is True
    assert config.has('baz/or') is True
    assert config.get('baz/or/whatever') == 'something'
Ejemplo n.º 4
0
def test_config_deep_set_existing():
    config = Configuration({'foo': 'bar', 'baz': {'wat': 'nothing'}})
    assert config.has('baz') is True
    assert config.get('baz/wat') == 'nothing'
    assert config.get('baz/or') is None
    config.set('baz/or/whatever', 'something')
    assert config.has('baz') is True
    assert config.has('baz/or') is True
    assert config.get('baz/or/whatever') == 'something'
Ejemplo n.º 5
0
def test_config_get_and_set():
    config = Configuration({'foo': 'bar', 'answer': 42})
    assert config.get('foo') == 'bar'
    assert config.get('answer') == 42

    config.set('foo', 'something')
    assert config.get('foo') == 'something'
Ejemplo n.º 6
0
def test_config_get_and_set_nested():
    config = Configuration({
        'foo': [4, 2],
        'bar': {
            'child1': 'one',
            'child2': 'two'
        }
    })
    assert config.get('foo') == [4, 2]
    assert config.get('bar/child1') == 'one'
    assert config.get('bar/child2') == 'two'

    config.set('bar/child1', 'other one')
    config.set('bar/child3', 'new one')
    assert config.get('bar/child1') == 'other one'
    assert config.get('bar/child3') == 'new one'
Ejemplo n.º 7
0
def test_config_merge():
    config = Configuration({
        'foo': [4, 2],
        'bar': {
            'child1': 'one',
            'child2': 'two'
        }
    })
    other = Configuration({
        'baz': True,
        'blah': 'blah blah',
        'bar': {
            'child1': 'other one',
            'child10': 'ten'
        }
    })
    config.merge(other)

    expected = {
        'foo': [4, 2],
        'baz': True,
        'blah': 'blah blah',
        'bar': {
            'child1': 'other one',
            'child2': 'two',
            'child10': 'ten'
        }
    }
    assert config.get() == expected
Ejemplo n.º 8
0
def test_config_get_and_set():
    config = Configuration({'foo': 'bar', 'answer': 42})
    assert config.get('foo') == 'bar'
    assert config.get('answer') == 42

    config.set('foo', 'something')
    assert config.get('foo') == 'something'
Ejemplo n.º 9
0
def test_config_get_and_set_nested():
    config = Configuration({
            'foo': [4, 2],
            'bar': {
                    'child1': 'one',
                    'child2': 'two'
                }
        })
    assert config.get('foo') == [4, 2]
    assert config.get('bar/child1') == 'one'
    assert config.get('bar/child2') == 'two'

    config.set('bar/child1', 'other one')
    config.set('bar/child3', 'new one')
    assert config.get('bar/child1') == 'other one'
    assert config.get('bar/child3') == 'new one'
Ejemplo n.º 10
0
def test_config_merge_with_mode(mode, expected):
    config = Configuration({'foo': [4, 2], 'bar': 'something'})
    other = {'foo': [1, 0], 'bar': 'other thing'}
    config.merge(other, mode=mode)
    assert config.getAll() == expected
Ejemplo n.º 11
0
def test_config_has():
    config = Configuration({'foo': 'bar'})
    assert config.has('foo') is True
    assert config.has('baz') is False
Ejemplo n.º 12
0
def test_config_get_missing():
    config = Configuration({'foo': 'bar'})
    assert config.get('baz') is None
Ejemplo n.º 13
0
def test_config_set_all():
    config = Configuration()
    config.setAll({'foo': 'bar'})
    assert config.get() == {'foo': 'bar'}
Ejemplo n.º 14
0
def test_config_init(values, expected):
    config = Configuration(values)
    assert config.get() == expected
Ejemplo n.º 15
0
def test_config_init(values, expected):
    config = Configuration(values)
    assert config.getAll() == expected
Ejemplo n.º 16
0
def test_config_set_all():
    config = Configuration()
    config.setAll({'foo': 'bar'})
    assert config.getAll() == {'foo': 'bar'}
Ejemplo n.º 17
0
def test_config_has():
    config = Configuration({'foo': 'bar'})
    assert config.has('foo') is True
    assert config.has('baz') is False
Ejemplo n.º 18
0
def test_config_get_missing():
    config = Configuration({'foo': 'bar'})
    assert config.get('baz') is None