Пример #1
0
def test_Config_defaults_get_defaults():
    config = Config(defaults=True)
    config.set_defaults(a={'x': 1}, b=10)
    assert isinstance(config.defaults, Section)
    assert config.defaults == {'a': {'x': 1}, 'b': 10}
    config = Config(defaults=False)
    assert config.defaults is None
Пример #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')
Пример #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')
Пример #4
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')
Пример #5
0
def test_Config_defaults_get_defaults():
    config = Config(defaults=True)
    config.set_defaults(a={'x': 1}, b=10)
    assert isinstance(config.defaults, Section)
    assert config.defaults == {'a': {'x': 1}, 'b': 10}
    config = Config(defaults=False)
    assert config.defaults is None
Пример #6
0
def test_Config_copy(defaultsvalue):
    config = Config(defaults=defaultsvalue)
    config['a'] = 10
    config.set_defaults(b=20)
    config2 = config.copy()
    assert config2 == config
    assert isinstance(config2, Config)
Пример #7
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')
Пример #8
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
Пример #9
0
def test_Config_defaults_dump(string_io):
    config = Config(defaults=True)
    config['x'] = 1
    config.set_defaults(alpha=10)
    config['sub'] = {'w': 2}
    config['sub'].set_defaults(beta=20, gamma={'x': 11}, delta={})
    assert config['sub']['beta'] == 20
    assert config['sub']['gamma']['x'] == 11
    config.dump(string_io)
    assert string_io.getvalue() == """\
Пример #10
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
Пример #11
0
def test_Config_defaults_dump(string_io):
    config = Config(defaults=True)
    config['x'] = 1
    config.set_defaults(alpha=10)
    config['sub'] = {'w': 2}
    config['sub'].set_defaults(beta=20, gamma={'x': 11}, delta={})
    assert config['sub']['beta'] == 20
    assert config['sub']['gamma']['x'] == 11
    config.dump(string_io)
    assert string_io.getvalue() == """\
Пример #12
0
def test_Config_defaults_option():
    config = Config(defaults=True)
    config.set_defaults(a=10)
    assert 'a' in config
    assert config.has_key('a')
    assert config.has_option('a')
    assert config['a'] == 10
    assert config.get('a') == 10
    assert config.get_option('a') == 10
    assert len(config) == 0
    assert not 'a' in config.dictionary
Пример #13
0
def test_Config_defaults_eq():
    config = Config(defaults=True)
    config['d'] = 11
    config['e'] = 12
    config.set_defaults(a={}, b=5, c={'x': 7}, d=8)

    config2 = Config(defaults=True)
    config2['d'] = 11
    config2['e'] = 12

    assert config != config2
Пример #14
0
def test_Config_defaults_eq():
    config = Config(defaults=True)
    config['d'] = 11
    config['e'] = 12
    config.set_defaults(a={}, b=5, c={'x': 7}, d=8)
    
    config2 = Config(defaults=True)
    config2['d'] = 11
    config2['e'] = 12

    assert config != config2
Пример #15
0
def test_Config_defaults_option():
    config = Config(defaults=True)
    config.set_defaults(a=10)
    assert 'a' in config
    assert config.has_key('a')
    assert config.has_option('a')
    assert config['a'] == 10
    assert config.get('a') == 10
    assert config.get_option('a') == 10
    assert len(config) == 0
    assert not 'a' in config.dictionary
Пример #16
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
Пример #17
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
Пример #18
0
def test_Config_defaults_copy():
    config = Config(defaults=True)
    config['d'] = 11
    config['e'] = 12
    config.set_defaults(a={}, b=5, c={'x': 7}, d=8)
    config2 = config.copy()
    assert not config2.has_section('a')
    assert config2.has_option('b')
    assert config2['b'] == 5
    assert config2.has_section('c')
    assert len(config2['c']) == 0
    assert config2['c']['x'] == 7
    assert config2.has_option('d')
    assert config2['d'] == 11
    assert config2.has_option('e')
    assert config2['e'] == 12
Пример #19
0
def test_Config_defaults_copy():
    config = Config(defaults=True)
    config['d'] = 11
    config['e'] = 12
    config.set_defaults(a={}, b=5, c={'x': 7}, d=8)
    config2 = config.copy()
    assert not config2.has_section('a')
    assert config2.has_option('b')
    assert config2['b'] == 5
    assert config2.has_section('c')
    assert len(config2['c']) == 0
    assert config2['c']['x'] == 7
    assert config2.has_option('d')
    assert config2['d'] == 11
    assert config2.has_option('e')
    assert config2['e'] == 12
Пример #20
0
def test_Config_defaults_add_overlap(defaultsvalue):
    config = Config(defaults=defaultsvalue)
    config['a'] = 100
    config['b'] = 101
    config['sub'] = {}
    config['sub']['x'] = 10
    config['sub']['y'] = 11
    config.set_defaults(b=201, c=202, sub={'y': 21, 'z': 22})
    assert 'a' in config
    assert config['a'] == 100
    assert 'b' in config
    assert config['b'] == 101
    assert 'c' in config
    assert config['c'] == 202
    assert 'x' in config['sub']
    assert config['sub']['x'] == 10
    assert 'y' in config['sub']
    assert config['sub']['y'] == 11
    assert 'z' in config['sub']
    assert config['sub']['z'] == 22
Пример #21
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')
Пример #22
0
def test_Config_defaults_add_overlap(defaultsvalue):
    config = Config(defaults=defaultsvalue)
    config['a'] = 100
    config['b'] = 101
    config['sub'] = {}
    config['sub']['x'] = 10
    config['sub']['y'] = 11
    config.set_defaults(b=201, c=202, sub={'y': 21, 'z': 22})
    assert 'a' in config
    assert config['a'] == 100
    assert 'b' in config
    assert config['b'] == 101
    assert 'c' in config
    assert config['c'] == 202
    assert 'x' in config['sub']
    assert config['sub']['x'] == 10
    assert 'y' in config['sub']
    assert config['sub']['y'] == 11
    assert 'z' in config['sub']
    assert config['sub']['z'] == 22
Пример #23
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')
Пример #24
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
Пример #25
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
Пример #26
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
Пример #27
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
Пример #28
0
def test_Config_defaults_update(defaultsvalue):
    config1 = Config(defaults=defaultsvalue)
    config1['d'] = 11
    config1['e'] = 12
    config1.set_defaults(a={}, b=5, c={'x': 7}, d=8)
    config2 = Config(defaults=True)
    config2.update(config1)
    assert config2 == config1
    config1.set_defaults(only1=1)
    assert not config2.has_option('only1')
    config2.set_defaults(only2=2)
    assert not config1.has_option('only2')
    assert config2 != config1
Пример #29
0
def test_Config_defaults_update(defaultsvalue):
    config1 = Config(defaults=defaultsvalue)
    config1['d'] = 11
    config1['e'] = 12
    config1.set_defaults(a={}, b=5, c={'x': 7}, d=8)
    config2 = Config(defaults=True)
    config2.update(config1)
    assert config2 == config1
    config1.set_defaults(only1=1)
    assert not config2.has_option('only1')
    config2.set_defaults(only2=2)
    assert not config1.has_option('only2')
    assert config2 != config1
Пример #30
0
def config_section():
    config = Config(defaults=True)
    config.set_defaults(a={'ax': 1}, b={'bx': 2})
    config['a'] = {'ax': 10}
    config['c'] = {'cx': 20}
    return config
Пример #31
0
def config_option():
    config = Config(defaults=True)
    config.set_defaults(a=10, b=20)
    config['a'] = 5
    config['c'] = 15
    return config
Пример #32
0
def test_Config_defaults_error():
    config = Config(defaults=True)
    with pytest.raises(TypeError):
        config.set_defaults(10)
Пример #33
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')
Пример #34
0
def test_Config_copy(defaultsvalue):
    config = Config(defaults=defaultsvalue)
    config['a'] = 10
    config.set_defaults(b=20)
    config2 = config.copy()
    assert config2 == config
Пример #35
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')
Пример #36
0
def config_option():
    config = Config(defaults=True)
    config.set_defaults(a=10, b=20)
    config['a'] = 5
    config['c'] = 15
    return config
Пример #37
0
def config_section():
    config = Config(defaults=True)
    config.set_defaults(a={'ax': 1}, b={'bx': 2})
    config['a'] = {'ax': 10}
    config['c'] = {'cx': 20}
    return config