Ejemplo n.º 1
0
def test_Config_defaults_sub():
    config = Config(defaults=True)
    config['a'] = 10
    config['sub'] = {}
    config['sub']['x'] = 1
    config['sub']['subsub'] = {}
    config['sub']['subsub']['xx'] = 11
    config['sub']['subsub']['subsubsub'] = {}
    config['sub']['subsub']['subsubsub']['xxx'] = 111
    config['sub']['subsub']['subsubsub']['yyy'] = 222
    config['sub']['subsub']['yy'] = 22
    config['sub']['y'] = 2
    config['b'] = 20

    config2 = Config(defaults=True)
    config2.set_defaults(**config)
    assert len(config2) == 0

    assert config2['a'] == 10
    assert config2['sub']['x'] == 1
    assert config2['sub']['subsub']['xx'] == 11
    assert config2['sub']['subsub']['subsubsub']['xxx'] == 111
    assert config2['sub']['subsub']['subsubsub']['yyy'] == 222
    assert config2['sub']['subsub']['yy'] == 22
    assert config2['sub']['y'] == 2
    assert config2['b'] == 20
    assert len(config2) == 1
    assert config2.has_option('a')
    assert config2.has_section('sub')
Ejemplo n.º 2
0
def test_Config_defaults_sub():
    config = Config(defaults=True)
    config['a'] = 10
    config['sub'] = {}
    config['sub']['x'] = 1
    config['sub']['subsub'] = {}
    config['sub']['subsub']['xx'] = 11
    config['sub']['subsub']['subsubsub'] = {}
    config['sub']['subsub']['subsubsub']['xxx'] = 111
    config['sub']['subsub']['subsubsub']['yyy'] = 222
    config['sub']['subsub']['yy'] = 22
    config['sub']['y'] = 2
    config['b'] = 20

    config2 = Config(defaults=True)
    config2.set_defaults(**config)
    assert len(config2) == 0

    assert config2['a'] == 10
    assert config2['sub']['x'] == 1
    assert config2['sub']['subsub']['xx'] == 11
    assert config2['sub']['subsub']['subsubsub']['xxx'] == 111
    assert config2['sub']['subsub']['subsubsub']['yyy'] == 222
    assert config2['sub']['subsub']['yy'] == 22
    assert config2['sub']['y'] == 2
    assert config2['b'] == 20
    assert len(config2) == 1
    assert config2.has_option('a')
    assert config2.has_section('sub')
Ejemplo n.º 3
0
def test_Config_defaults_add_subsub():
    config = Config(defaults=True)
    config['x'] = 10
    config.set_defaults(a=1,
                        sub={
                            'sa': 2,
                            'subsub': {
                                'ssa': 3,
                                'empty1': {},
                                'empty2': {
                                    'ee1': {},
                                    'ee2': {}
                                },
                                'subsubsub': {
                                    'sss': 4
                                },
                                'ssb': 5
                            },
                            'sb': 6
                        },
                        b=7)
    assert config.has_section('sub')
    assert config['sub'].has_section('subsub')
    assert config['sub']['subsub'].has_section('subsubsub')
    assert not config['sub']['subsub'].has_section('empty1')
    assert not config['sub']['subsub'].has_section('empty2')
Ejemplo n.º 4
0
def test_Config_defaults_add_subsub():
    config = Config(defaults=True)
    config['x'] = 10
    config.set_defaults(a=1, sub={'sa': 2, 'subsub': {'ssa': 3, 'empty1': {}, 'empty2': {'ee1': {}, 'ee2': {}}, 'subsubsub': {'sss': 4}, 'ssb': 5}, 'sb': 6}, b=7)
    assert config.has_section('sub')
    assert config['sub'].has_section('subsub')
    assert config['sub']['subsub'].has_section('subsubsub')
    assert not config['sub']['subsub'].has_section('empty1')
    assert not config['sub']['subsub'].has_section('empty2')
Ejemplo n.º 5
0
def test_Config_no_defaults_set_defaults():
    config = Config(defaults=False)
    config.set_defaults(alpha=10, beta={'x': 1})
    assert config.has_option('alpha')
    assert config['alpha'] == 10
    assert len(config) == 2
    assert config.has_section('beta')
    assert config['beta'].has_option('x')
    assert config['beta']['x'] == 1
    assert len(config['beta']) == 1
Ejemplo n.º 6
0
def test_Config_no_defaults_set_defaults():
    config = Config(defaults=False)
    config.set_defaults(alpha=10, beta={'x': 1})
    assert config.has_option('alpha')
    assert config['alpha'] == 10
    assert len(config) == 2
    assert config.has_section('beta')
    assert config['beta'].has_option('x')
    assert config['beta']['x'] == 1
    assert len(config['beta']) == 1
Ejemplo n.º 7
0
def test_Config_defaults_section():
    config = Config(defaults=True)
    config.set_defaults(a={'x': 1})
    assert 'a' in config
    assert config.has_key('a')
    assert config.has_section('a')
    assert isinstance(config['a'], Section)
    assert len(config) == 1
    assert len(config['a']) == 0
    assert config['a'].has_option('x')
    assert config.get('a') == config['a']
    assert config.get_section('a') == config['a']
    config['a'] = {'y': 2}
    assert len(config['a']) == 1
    assert config['a'].has_option('x')
    assert config['a'].has_option('y')
    del config['a']
    assert config.has_section('a')
    assert len(config['a']) == 0
    assert config['a'].has_option('x')
Ejemplo n.º 8
0
def test_Config_defaults_section():
    config = Config(defaults=True)
    config.set_defaults(a={'x': 1})
    assert 'a' in config
    assert config.has_key('a')
    assert config.has_section('a')
    assert isinstance(config['a'], Section)
    assert len(config) == 1
    assert len(config['a']) == 0
    assert config['a'].has_option('x')
    assert config.get('a') == config['a']
    assert config.get_section('a') == config['a']
    config['a'] = {'y': 2}
    assert len(config['a']) == 1
    assert config['a'].has_option('x')
    assert config['a'].has_option('y')
    del config['a']
    assert config.has_section('a')
    assert len(config['a']) == 0
    assert config['a'].has_option('x')
Ejemplo n.º 9
0
def test_Config_defaults_external(extdefaults):
    edcopy = as_dict(extdefaults, depth=-1, dict_class=dict)
    config = Config(defaults=extdefaults)
    assert config.has_section('sub')
    assert config['sub']['f22'] == 2.2
    assert not config['sub'].has_section('sse')
    with pytest.raises(KeyError) as exc_info:
        config['sub']['sse']['xx'] = 18
    assert str(exc_info.value) == "'sse'"
    assert not config['sub'].has_section('sse')
    assert config['sub'].has_section('ssf')
    assert len(config['sub']['ssf']) == 0
    assert config['sub']['ssf']['f44'] == 4.4
    config['sub']['ssf']['xx'] = 19
    del config['sub']
    assert config.has_section('sub')
    assert config['sub'].has_section('ssf')
    assert config['sub']['ssf'].has_option('f44')
    assert config['sub']['ssf']['f44'] == 4.4
    edcopy2 = as_dict(extdefaults, depth=-1, dict_class=dict)
    assert edcopy == edcopy2
Ejemplo n.º 10
0
def test_Config_defaults_external(extdefaults):
    edcopy = as_dict(extdefaults, depth=-1, dict_class=dict)
    config = Config(defaults=extdefaults)
    assert config.has_section('sub')
    assert config['sub']['f22'] == 2.2
    assert not config['sub'].has_section('sse')
    with pytest.raises(KeyError) as exc_info:
        config['sub']['sse']['xx'] = 18
    assert str(exc_info.value) == "'sse'"
    assert not config['sub'].has_section('sse')
    assert config['sub'].has_section('ssf')
    assert len(config['sub']['ssf']) == 0
    assert config['sub']['ssf']['f44'] == 4.4
    config['sub']['ssf']['xx'] = 19
    del config['sub']
    assert config.has_section('sub')
    assert config['sub'].has_section('ssf')
    assert config['sub']['ssf'].has_option('f44')
    assert config['sub']['ssf']['f44'] == 4.4
    edcopy2 = as_dict(extdefaults, depth=-1, dict_class=dict)
    assert edcopy == edcopy2
Ejemplo n.º 11
0
def test_Config_defaults_section_add():
    config = Config(defaults=True)
    config.set_defaults(a={'x': 1})
    assert 'a' in config
    config['a']['t'] = 0.1
    assert config['a']['x'] == 1
    assert config['a']['t'] == 0.1
    assert not config.defaults['a'].has_option('t')
    del config['a']
    assert config.has_section('a')
    assert config['a'].has_option('x')
    assert config['a']['x'] == 1
Ejemplo n.º 12
0
def test_Config_defaults_section_add():
    config = Config(defaults=True)
    config.set_defaults(a={'x': 1})
    assert 'a' in config
    config['a']['t'] = 0.1
    assert config['a']['x'] == 1
    assert config['a']['t'] == 0.1
    assert not config.defaults['a'].has_option('t')
    del config['a']
    assert config.has_section('a')
    assert config['a'].has_option('x')
    assert config['a']['x'] == 1
Ejemplo n.º 13
0
def test_Config_change_defaults():
    config1 = Config(defaults=True)
    defaults1 = config1.defaults
    config1.set_defaults(s={'a': 1, 'b': 2})
    config2 = Config(defaults=True)
    defaults2 = config2.defaults
    config2.set_defaults(s={'a': 10, 'c': 20})

    assert config1['s']['a'] == 1
    assert config2['s']['a'] == 10

    config1.defaults = None

    config2.defaults = defaults1

    config1.defaults = defaults2

    assert config1.has_section('s')
    assert config1['s']['a'] == 10
    assert config2['s']['a'] == 1
Ejemplo n.º 14
0
def test_Config_change_defaults():
    config1 = Config(defaults=True)
    defaults1 = config1.defaults
    config1.set_defaults(s={'a': 1, 'b': 2})
    config2 = Config(defaults=True)
    defaults2 = config2.defaults
    config2.set_defaults(s={'a': 10, 'c': 20})

    assert config1['s']['a'] == 1
    assert config2['s']['a'] == 10

    config1.defaults = None

    config2.defaults = defaults1

    config1.defaults = defaults2

    assert config1.has_section('s')
    assert config1['s']['a'] == 10
    assert config2['s']['a'] == 1
Ejemplo n.º 15
0
def test_Config_defaults_deloptions():
    config = Config(defaults=True)
    config['d'] = 11
    config['e'] = 12
    config.set_defaults(a={}, b=5, c={'x': 7}, d=8)
    assert config.has_option('d')
    assert config['d'] == 11
    del config['d']
    assert config.has_option('d')
    assert config['d'] == 8
    assert config.has_option('e')
    assert config['e'] == 12
    del config['e']
    assert not config.has_option('e')
    with pytest.raises(KeyError):
        del config['e']
    del config['d']
    assert config.has_option('d')
    del config['c']
    assert config.has_section('c')
    assert config['c']['x'] == 7
Ejemplo n.º 16
0
def test_Config_defaults_deloptions():
    config = Config(defaults=True)
    config['d'] = 11
    config['e'] = 12
    config.set_defaults(a={}, b=5, c={'x': 7}, d=8)
    assert config.has_option('d')
    assert config['d'] == 11
    del config['d']
    assert config.has_option('d')
    assert config['d'] == 8
    assert config.has_option('e')
    assert config['e'] == 12
    del config['e']
    assert not config.has_option('e')
    with pytest.raises(KeyError):
        del config['e']
    del config['d']
    assert config.has_option('d')
    del config['c']
    assert config.has_section('c')
    assert config['c']['x'] == 7
Ejemplo n.º 17
0
def test_Config_defaults_empty_section():
    config = Config(defaults=True)
    config.set_defaults(a={})
    assert not 'a' in config
    assert not config.has_key('a')
    assert not config.has_section('a')
Ejemplo n.º 18
0
def test_Config_defaults_empty_section():
    config = Config(defaults=True)
    config.set_defaults(a={})
    assert not 'a' in config
    assert not config.has_key('a')
    assert not config.has_section('a')