Beispiel #1
0
def test_config_register():
    config = Config('test')
    config.register(ConfigItem('item', 1))
    assert config['item'] == 1
    subconfig = Config('sub')
    subconfig.register(ConfigItem('item', 2))
    config.register(subconfig)
    assert config['sub']['item'] == 2
Beispiel #2
0
def test_config_locked():
    config = Config('test', True)
    config.register(ConfigItem('item', 1))
    with pytest.raises(KeyError):
        config['item']
    config.unlock()
    config.register(ConfigItem('item', 1))
    assert config['item'] == 1
    config.lock()
    config['item'] = 2
    assert config['item'] == 1
Beispiel #3
0
def test_config_static():
    config = Config('test', True, True)
    config.register(ConfigItem('item1', 1))
    config.unlock()
    config.register(ConfigItem('item2', 2))
    config['item1'] = 3
    with pytest.raises(KeyError):
        config['item1']
    with pytest.raises(KeyError):
        config['item2']
Beispiel #4
0
def test_config_from_dict():
    config = Config('test')
    config.register(ConfigItem('item', 1))
    subconfig = Config('sub')
    subconfig.register(ConfigItem('item', 2))
    config.register(subconfig)
    assert config == Config.from_dict('test', {'item': 1, 'sub': {'item': 2}})
Beispiel #5
0
def test_config_to_dict():
    config = Config('test')
    config.register(ConfigItem('item', 1))
    subconfig = Config('sub')
    subconfig.register(ConfigItem('item', 2))
    config.register(subconfig)
    assert config.to_dict() == {'item': 1, 'sub': {'item': 2}}
Beispiel #6
0
def test_config_mutate():
    config = Config('test')
    config.register(ConfigItem('item', 1))
    assert config['item'] == 1
    config['item'] = 2
    assert config['item'] == 2
Beispiel #7
0
def test_config_inexistent():
    config = Config('test')
    config['item'] = 1
    with pytest.raises(KeyError):
        config['item']