def test_empty_conf_default_under_exclusive(): conf = ConfigSimple( Switch(None, [ Group('a', default=True, nodes=[ Value('x', int, 42), ]), Group('b', nodes=[ Value('x', int, 12), ]), ]) ) assert conf.to_dict() == {'a.x': 42}
def test_empty_conf_exclusive(): conf = ConfigSimple( Switch(None, [ Group('a', nodes=[ Value('x', int, 42), ]), Group('b', nodes=[ Value('x', int, 12), ]), ]) ) assert conf.to_dict() == {}
def test_default_group_under_exclusif(): root = Switch(None, [ Group('a', default=True, nodes=[ Value('x', int, 42), Value('y', bool, True) ]), Group('b', nodes=[ Value('x', int, 42), Value('y', bool, True) ]), ]) conf = ConfigSimple(root) assert conf['a'] assert conf['a.x'] == 42 assert conf['a.y'] assert not conf['b'] with pytest.raises(KeyError): conf['b.x'] with pytest.raises(KeyError): conf['b.y'] assert conf.to_dict() == {'a.x': 42, 'a.y': True} conf['b'] = True assert conf['b'] assert conf['b.x'] == 42 assert conf['b.y'] assert not conf['a'] with pytest.raises(KeyError): conf['a.x'] with pytest.raises(KeyError): conf['a.y'] assert conf.to_dict() == {'b.x': 42, 'b.y': True} conf['b'] = False assert not conf['a'] with pytest.raises(KeyError): conf['a.x'] with pytest.raises(KeyError): conf['a.y'] assert not conf['b'] with pytest.raises(KeyError): conf['b.x'] with pytest.raises(KeyError): conf['b.y'] assert conf.to_dict() == {}
def test_multiple_default_under_exclusif(): root = Switch(None, [ Value('x', int, 42), Value('y', bool, True) ]) with pytest.raises(ValueError): ConfigSimple(root)
def test_options_with_default(): root = Options(None, [ Group('a', [ Value('x', int, 42), Value('y', str, 'hello'), ], True), Group('b', [ Value('x', int, 6), Value('y', str, 'bye'), ]), ]) conf = ConfigSimple(root) assert conf.to_dict() == {'a.x': 42, 'a.y': 'hello'} conf['a'] = True assert conf.to_dict() == {'a.x': 42, 'a.y': 'hello'} conf['a'] = False assert conf.to_dict() == {} conf['b.x'] = 12 assert conf.to_dict() == {'b.x': 12, 'b.y': 'bye'} conf['a'] = True assert conf.to_dict() == {'a.x': 42, 'a.y': 'hello', 'b.x': 12, 'b.y': 'bye'}
def test_default_under_flag_group(): root = Options(None, [ Group('a', nodes=[Value('x', int, 42), Value('y', bool, False)]), ]) conf = ConfigSimple(root) assert conf.to_dict() == {} assert conf.to_nested_dict() == {} conf['a'] = True assert conf.to_dict() == { 'a.x': 42, 'a.y': False, } assert conf.to_nested_dict() == { 'a': { 'x': 42, 'y': False, }, } conf['a'] = False assert conf.to_dict() == {} assert conf.to_nested_dict() == {} conf['a.x'] = 2 assert conf.to_dict() == { 'a.x': 2, 'a.y': False, } assert conf.to_nested_dict() == { 'a': { 'x': 2, 'y': False, }, }
def test_simple(): from inept import ConfigSimple, Value, Options, Switch carte_tree = Options(None, [ Value('cafe', bool, False), Value('boisson', str), Switch(None, [ MenuPasCher.root.rename("menu_base"), MenuComplet.root.rename("menu_complet"), ]) ]) order = ConfigSimple(carte_tree) assert order.all_keys() == [ 'cafe', 'boisson', 'menu_base', 'menu_base.plat', 'menu_base.entree', 'menu_base.dessert', 'menu_complet', 'menu_complet.plat', 'menu_complet.entree', 'menu_complet.dessert', ]
def test_default_under_exclusif(): root = Switch(None, [ Value('x', int, 42), Value('y', bool) ]) conf = ConfigSimple(root) assert conf['x'] == 42 with pytest.raises(KeyError): conf['y'] conf['y'] = True assert conf['y'] with pytest.raises(KeyError): conf['x']
def test_one_option(): root = Options(None, [ Group('a', nodes=[ Value('x', int, 42), Value('y', bool, False) ]), ]) conf = ConfigSimple(root) assert not conf['a'] with pytest.raises(KeyError): conf['a.x'] with pytest.raises(KeyError): conf['a.y'] assert conf.to_dict() == {} conf['a'] = True assert conf['a'] assert conf['a.x'] == 42 assert conf['a.y'] == False assert conf.to_dict() == {'a.x': 42, 'a.y': False} conf['a'] = False assert not conf['a'] with pytest.raises(KeyError): conf['a.x'] with pytest.raises(KeyError): conf['a.y'] assert conf.to_dict() == {} conf['a.x'] = 15 assert conf['a'] assert conf['a.x'] == 15 assert conf['a.y'] == False assert conf.to_dict() == {'a.x': 15, 'a.y': False}
def test_make_empty_conf(**kwds): root = test_make_tree() conf = ConfigSimple(root, **kwds) return conf