add option name's validation and rename Option method with objimpl_
This commit is contained in:
@ -2,14 +2,16 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, OptionDescription
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
@ -21,25 +23,28 @@ def make_description():
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def test_base_config():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy == False
|
||||
assert cfg.dummy is False
|
||||
dm = cfg.unwrap_from_path('dummy')
|
||||
assert dm._name == 'dummy'
|
||||
|
||||
|
||||
def test_reset_value():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
assert cfg.gc.dummy == False
|
||||
assert cfg.gc.dummy is False
|
||||
cfg.gc.dummy = True
|
||||
assert cfg.gc.dummy == True
|
||||
assert cfg.gc.dummy is True
|
||||
|
||||
|
||||
def test_base_config_and_groups():
|
||||
descr = make_description()
|
||||
@ -47,7 +52,7 @@ def test_base_config_and_groups():
|
||||
config = Config(descr)
|
||||
config.bool = False
|
||||
assert config.gc.name == 'ref'
|
||||
assert config.bool == False
|
||||
assert config.bool is False
|
||||
nm = config.unwrap_from_path('gc.name')
|
||||
assert nm._name == 'name'
|
||||
gc = config.unwrap_from_path('gc')
|
||||
@ -55,6 +60,7 @@ def test_base_config_and_groups():
|
||||
#nm = config.unwrap_from_name('name')
|
||||
#assert nm._name == 'name'
|
||||
|
||||
|
||||
def test_base_config_in_a_tree():
|
||||
"how options are organized into a tree"
|
||||
descr = make_description()
|
||||
@ -89,13 +95,6 @@ def test_base_config_in_a_tree():
|
||||
assert config.gc.name == 'ref'
|
||||
config.wantframework = True
|
||||
|
||||
#def test_config_values():
|
||||
# "_cfgimpl_values appears to be a simple dict"
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# config.bool = False
|
||||
# config.set(dummy=False)
|
||||
# assert config.gc._cfgimpl_values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
||||
|
||||
def test_cfgimpl_get_home_by_path():
|
||||
descr = make_description()
|
||||
@ -103,6 +102,5 @@ def test_cfgimpl_get_home_by_path():
|
||||
config.bool = False
|
||||
assert config.cfgimpl_get_home_by_path('gc.dummy')[1] == 'dummy'
|
||||
assert config.cfgimpl_get_home_by_path('dummy')[1] == 'dummy'
|
||||
assert config.getpaths(include_groups=False) == ['gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
assert config.getpaths(include_groups=True) == ['gc', 'gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
|
||||
#assert config.getpaths(include_groups=False) == ['gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
#assert config.getpaths(include_groups=True) == ['gc', 'gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
|
@ -2,14 +2,16 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, OptionDescription
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
@ -20,9 +22,9 @@ def make_description():
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
@ -34,86 +36,47 @@ def test_compare_configs():
|
||||
conf2.wantref = True
|
||||
assert conf1 != conf2
|
||||
assert hash(conf1) != hash(conf2)
|
||||
assert conf1.getkey() != conf2.getkey()
|
||||
#assert conf1.getkey() != conf2.getkey()
|
||||
conf1.wantref = True
|
||||
assert conf1 == conf2
|
||||
assert hash(conf1) == hash(conf2)
|
||||
assert conf1.getkey() == conf2.getkey()
|
||||
#assert conf1.getkey() == conf2.getkey()
|
||||
conf2.gc.dummy = True
|
||||
assert conf1 != conf2
|
||||
assert hash(conf1) != hash(conf2)
|
||||
#assert conf1.getkey() != conf2.getkey()
|
||||
conf1.gc.dummy = True
|
||||
assert conf1 == conf2
|
||||
assert hash(conf1) == hash(conf2)
|
||||
#assert conf1.getkey() == conf2.getkey()
|
||||
# ____________________________________________________________
|
||||
|
||||
|
||||
def test_iter_config():
|
||||
"iteration on config object"
|
||||
s = StrOption("string", "", default="string")
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
descr = OptionDescription("options", "", [s,s2])
|
||||
descr = OptionDescription("options", "", [s, s2])
|
||||
config = Config(descr)
|
||||
assert [(name, value) for name, value in config] == \
|
||||
[('string', 'string'), ('string2', 'string2')]
|
||||
[('string', 'string'), ('string2', 'string2')]
|
||||
|
||||
|
||||
def test_iter_subconfig():
|
||||
"iteration on config sub object"
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
for (name, value), (gname, gvalue) in \
|
||||
zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
||||
zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
||||
assert name == gname
|
||||
assert value == gvalue
|
||||
|
||||
def test_cfgimpl_get_value():
|
||||
"same as getattr."
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
#FIXME
|
||||
#assert conf.cfgimpl_get_value(('gc', 'dummy')) == False
|
||||
|
||||
#____________________________________________________________
|
||||
def test_getpaths():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
|
||||
assert config.getpaths() == ['gc.name', 'gc.dummy', 'gc.float', 'bool',
|
||||
'objspace', 'wantref', 'str', 'wantframework',
|
||||
'int', 'boolop']
|
||||
assert config.getpaths() == descr.getpaths()
|
||||
assert config.gc.getpaths() == ['name', 'dummy', 'float']
|
||||
assert config.gc.getpaths() == descr.gc.getpaths()
|
||||
assert config.getpaths(include_groups=True) == [
|
||||
'gc', 'gc.name', 'gc.dummy', 'gc.float',
|
||||
'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
|
||||
assert config.getpaths(True) == descr.getpaths(True)
|
||||
|
||||
def test_getpaths_with_hidden():
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True, properties=('hidden',))
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
|
||||
descr = OptionDescription('tiramisu', '', [booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
|
||||
config = Config(descr)
|
||||
result = ['bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
assert config.getpaths() == result
|
||||
r2 = ['bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
assert config.getpaths(allpaths=True) == r2
|
||||
|
||||
def test_str():
|
||||
descr = make_description()
|
||||
c = Config(descr)
|
||||
c # does not crash
|
||||
c # does not crash
|
||||
|
||||
#def test_dir():
|
||||
# descr = make_description()
|
||||
# c = Config(descr)
|
||||
# print dir(c)
|
||||
|
||||
def test_make_dict():
|
||||
"serialization of the whole config to a dict"
|
||||
@ -131,19 +94,6 @@ def test_make_dict():
|
||||
d2 = config.make_dict(flatten=True)
|
||||
assert d2 == {'a': True, 'int': 43}
|
||||
|
||||
#def test_delattr():
|
||||
# "delattr, means suppression of an option in a config"
|
||||
# descr = OptionDescription("opt", "", [
|
||||
# OptionDescription("s1", "", [
|
||||
# BoolOption("a", "", default=False)]),
|
||||
# IntOption("int", "", default=42)])
|
||||
# c = Config(descr)
|
||||
# c.int = 45
|
||||
# assert c.int == 45
|
||||
# del c.int
|
||||
# assert c.int == 42
|
||||
# c.int = 45
|
||||
# assert c.int == 45
|
||||
|
||||
def test_find_in_config():
|
||||
"finds option in config"
|
||||
@ -164,36 +114,8 @@ def test_find_in_config():
|
||||
#assert conf.find_first(byattrs= dict(default=2.3)) == conf.unwrap_from_path('gc.float')
|
||||
#assert conf.find_first(byvalue=False, byname='dummy', byattrs=dict(default=False)) == conf.unwrap_from_path('gc.dummy')
|
||||
|
||||
|
||||
def test_does_not_find_in_config():
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
raises(AttributeError, "conf.find(byname='IDontExist')")
|
||||
|
||||
#def test_validator():
|
||||
# "validates the integrity of an option towards a whole configuration"
|
||||
# def my_validator_1(config):
|
||||
# assert config is c
|
||||
|
||||
# def my_validator_2(config):
|
||||
# assert config is c
|
||||
# raise ConflictConfigError
|
||||
|
||||
# descr = OptionDescription("opt", "", [
|
||||
# BoolOption('booloption1', 'option test1', default=False,
|
||||
# validator=my_validator_1),
|
||||
# BoolOption('booloption2', 'option test2', default=False,
|
||||
# validator=my_validator_2),
|
||||
# BoolOption('booloption4', 'option test4', default=False,
|
||||
# ),
|
||||
# ])
|
||||
# c = Config(descr)
|
||||
# c.booloption1 = True
|
||||
## raises(ConfigError, "c.booloption2 = True")
|
||||
## assert c.booloption2 is False
|
||||
## raises(ConfigError, "c.booloption3 = True")
|
||||
# assert c.booloption2 is False
|
||||
# c.booloption4 = True
|
||||
# assert c.booloption2 is False
|
||||
# c.booloption2 = False
|
||||
# assert c.booloption2 is False
|
||||
#
|
||||
|
@ -1,34 +1,35 @@
|
||||
"test all types of option default values for options, add new option in a descr"
|
||||
import autopath
|
||||
|
||||
from py.test import raises
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, OptionDescription
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
requires=['boolop'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
# default values
|
||||
def test_default_is_none():
|
||||
@ -42,13 +43,15 @@ def test_default_is_none():
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
config = Config(group)
|
||||
# so when the default value is not set, there is actually a default value
|
||||
assert config.dummy1 == None
|
||||
assert config.dummy2 == None
|
||||
assert config.dummy1 is None
|
||||
assert config.dummy2 is None
|
||||
|
||||
|
||||
def test_set_defaut_value_from_option_object():
|
||||
"""Options have an available default setting and can give it back"""
|
||||
b = BoolOption("boolean", "", default=False)
|
||||
assert b.getdefault() == False
|
||||
assert b.objimpl_getdefault() is False
|
||||
|
||||
|
||||
def test_force_default_on_freeze():
|
||||
"a frozen option wich is forced returns his default"
|
||||
@ -61,21 +64,9 @@ def test_force_default_on_freeze():
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting[dummy1].append('frozen')
|
||||
setting[dummy2].append('frozen')
|
||||
assert config.dummy1 == False
|
||||
assert config.dummy2 == False
|
||||
assert config.dummy1 is False
|
||||
assert config.dummy2 is False
|
||||
|
||||
#def test_override_are_defaults():
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# config.bool = False
|
||||
# config.gc.dummy = True
|
||||
# assert config._cfgimpl_values['gc']._cfgimpl_values.owners['dummy'] == 'user'
|
||||
# #Options have an available default setting and can give it back
|
||||
# assert config._cfgimpl_descr._children[0]._children[1].getdefault() == False
|
||||
## config.override({'gc.dummy':True})
|
||||
# #assert config.gc.dummy == True
|
||||
# #assert config._cfgimpl_descr._children[0]._children[1].getdefault() == True
|
||||
# #assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'default'
|
||||
|
||||
def test_overrides_changes_option_value():
|
||||
"with config.override(), the default is changed and the value is changed"
|
||||
@ -83,10 +74,8 @@ def test_overrides_changes_option_value():
|
||||
BoolOption("b", "", default=False)])
|
||||
config = Config(descr)
|
||||
config.b = True
|
||||
# config.override({'b': False})
|
||||
# assert config.b == False
|
||||
#____________________________________________________________
|
||||
# test various option types
|
||||
|
||||
|
||||
def test_choice_with_no_default():
|
||||
descr = OptionDescription("test", "", [
|
||||
ChoiceOption("backend", "", ("c", "cli"))])
|
||||
@ -94,26 +83,9 @@ def test_choice_with_no_default():
|
||||
assert config.backend is None
|
||||
config.backend = "c"
|
||||
|
||||
|
||||
def test_choice_with_default():
|
||||
descr = OptionDescription("test", "", [
|
||||
ChoiceOption("backend", "", ("c", "cli"), default="cli")])
|
||||
config = Config(descr)
|
||||
assert config.backend == "cli"
|
||||
|
||||
#def test_arbitrary_option():
|
||||
# descr = OptionDescription("top", "", [
|
||||
# ArbitraryOption("a", "no help", default=None)
|
||||
# ])
|
||||
# config = Config(descr)
|
||||
# config.a = []
|
||||
# config.a.append(1)
|
||||
# assert config.a == [1]
|
||||
|
||||
# descr = OptionDescription("top", "", [
|
||||
# ArbitraryOption("a", "no help", defaultfactory=list)
|
||||
# ])
|
||||
# c1 = Config(descr)
|
||||
# c2 = Config(descr)
|
||||
# c1.a.append(1)
|
||||
# assert c2.a == []
|
||||
# assert c1.a == [1]
|
||||
|
@ -5,8 +5,8 @@ from py.test import raises
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption
|
||||
from tiramisu.error import ConflictOptionError, PropertiesOptionError
|
||||
StrOption, OptionDescription
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
def make_description():
|
||||
@ -251,7 +251,7 @@ def test_multi_with_bool():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.is_multi() is True
|
||||
assert descr.bool.objimpl_is_multi() is True
|
||||
config.bool = [True, False]
|
||||
assert config.cfgimpl_get_values()[s] == [True, False]
|
||||
assert config.bool == [True, False]
|
||||
@ -261,7 +261,7 @@ def test_multi_with_bool_two():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.is_multi() is True
|
||||
assert descr.bool.objimpl_is_multi() is True
|
||||
raises(ValueError, "config.bool = True")
|
||||
|
||||
|
||||
@ -283,80 +283,80 @@ def test_choice_access_with_multi():
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_dwim_set():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("sub", "", [
|
||||
BoolOption("b1", ""),
|
||||
ChoiceOption("c1", "", ('a', 'b', 'c'), 'a'),
|
||||
BoolOption("d1", ""),
|
||||
]),
|
||||
BoolOption("b2", ""),
|
||||
BoolOption("d1", ""),
|
||||
])
|
||||
c = Config(descr)
|
||||
c.set(b1=False, c1='b')
|
||||
assert not c.sub.b1
|
||||
assert c.sub.c1 == 'b'
|
||||
# new config, because you cannot change values once they are set
|
||||
c = Config(descr)
|
||||
c.set(b2=False, **{'sub.c1': 'c'})
|
||||
assert not c.b2
|
||||
assert c.sub.c1 == 'c'
|
||||
raises(ConflictOptionError, "c.set(d1=True)")
|
||||
raises(AttributeError, "c.set(unknown='foo')")
|
||||
#def test_dwim_set():
|
||||
# descr = OptionDescription("opt", "", [
|
||||
# OptionDescription("sub", "", [
|
||||
# BoolOption("b1", ""),
|
||||
# ChoiceOption("c1", "", ('a', 'b', 'c'), 'a'),
|
||||
# BoolOption("d1", ""),
|
||||
# ]),
|
||||
# BoolOption("b2", ""),
|
||||
# BoolOption("d1", ""),
|
||||
# ])
|
||||
# c = Config(descr)
|
||||
# c.set(b1=False, c1='b')
|
||||
# assert not c.sub.b1
|
||||
# assert c.sub.c1 == 'b'
|
||||
# # new config, because you cannot change values once they are set
|
||||
# c = Config(descr)
|
||||
# c.set(b2=False, **{'sub.c1': 'c'})
|
||||
# assert not c.b2
|
||||
# assert c.sub.c1 == 'c'
|
||||
# raises(ConflictOptionError, "c.set(d1=True)")
|
||||
# raises(AttributeError, "c.set(unknown='foo')")
|
||||
|
||||
|
||||
def test_more_set():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False)]),
|
||||
IntOption("int", "", default=42)])
|
||||
d = {'s1.a': True, 'int': 23}
|
||||
config = Config(descr)
|
||||
config.set(**d)
|
||||
assert config.s1.a
|
||||
assert config.int == 23
|
||||
#def test_more_set():
|
||||
# descr = OptionDescription("opt", "", [
|
||||
# OptionDescription("s1", "", [
|
||||
# BoolOption("a", "", default=False)]),
|
||||
# IntOption("int", "", default=42)])
|
||||
# d = {'s1.a': True, 'int': 23}
|
||||
# config = Config(descr)
|
||||
# config.set(**d)
|
||||
# assert config.s1.a
|
||||
# assert config.int == 23
|
||||
|
||||
|
||||
def test_set_with_hidden_option():
|
||||
boolopt = BoolOption("a", "", default=False, properties=(('hidden'),))
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [boolopt]),
|
||||
IntOption("int", "", default=42)])
|
||||
d = {'s1.a': True, 'int': 23}
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
raises(PropertiesOptionError, "config.set(**d)")
|
||||
|
||||
|
||||
def test_set_with_unknown_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [boolopt]),
|
||||
IntOption("int", "", default=42)])
|
||||
d = {'s1.a': True, 'int': 23}
|
||||
config = Config(descr)
|
||||
raises(AttributeError, "config.set(**d)")
|
||||
|
||||
|
||||
def test_set_symlink_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", "s1.b", opt=boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
config = Config(descr)
|
||||
setattr(config, "s1.b", True)
|
||||
setattr(config, "s1.b", False)
|
||||
assert config.s1.b is False
|
||||
assert config.c is False
|
||||
config.c = True
|
||||
assert config.s1.b is True
|
||||
assert config.c is True
|
||||
config.c = False
|
||||
assert config.s1.b is False
|
||||
assert config.c is False
|
||||
|
||||
#def test_set_with_hidden_option():
|
||||
# boolopt = BoolOption("a", "", default=False, properties=(('hidden'),))
|
||||
# descr = OptionDescription("opt", "", [
|
||||
# OptionDescription("s1", "", [boolopt]),
|
||||
# IntOption("int", "", default=42)])
|
||||
# d = {'s1.a': True, 'int': 23}
|
||||
# config = Config(descr)
|
||||
# setting = config.cfgimpl_get_settings()
|
||||
# setting.read_write()
|
||||
# raises(PropertiesOptionError, "config.set(**d)")
|
||||
#
|
||||
#
|
||||
#def test_set_with_unknown_option():
|
||||
# boolopt = BoolOption("b", "", default=False)
|
||||
# descr = OptionDescription("opt", "", [
|
||||
# OptionDescription("s1", "", [boolopt]),
|
||||
# IntOption("int", "", default=42)])
|
||||
# d = {'s1.a': True, 'int': 23}
|
||||
# config = Config(descr)
|
||||
# raises(AttributeError, "config.set(**d)")
|
||||
#
|
||||
#
|
||||
#def test_set_symlink_option():
|
||||
# boolopt = BoolOption("b", "", default=False)
|
||||
# linkopt = SymLinkOption("c", "s1.b", opt=boolopt)
|
||||
# descr = OptionDescription("opt", "",
|
||||
# [linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
# config = Config(descr)
|
||||
# setattr(config, "s1.b", True)
|
||||
# setattr(config, "s1.b", False)
|
||||
# assert config.s1.b is False
|
||||
# assert config.c is False
|
||||
# config.c = True
|
||||
# assert config.s1.b is True
|
||||
# assert config.c is True
|
||||
# config.c = False
|
||||
# assert config.s1.b is False
|
||||
# assert config.c is False
|
||||
#
|
||||
##____________________________________________________________
|
||||
#def test_config_impl_values():
|
||||
# descr = make_description()
|
||||
@ -401,8 +401,10 @@ def test_allow_multiple_changes_from_config():
|
||||
config = Config(descr)
|
||||
config.string = "oh"
|
||||
assert config.string == "oh"
|
||||
config.set(string2='blah')
|
||||
assert config.bip.string2 == 'blah'
|
||||
config.string = "blah"
|
||||
assert config.string == "blah"
|
||||
# config.set(string2='blah')
|
||||
# assert config.bip.string2 == 'blah'
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
|
@ -48,8 +48,10 @@ def test_optname_shall_not_start_with_numbers():
|
||||
|
||||
|
||||
def test_option_has_an_api_name():
|
||||
print "FIXME"
|
||||
#gcdummy = BoolOption('cfgimpl_get_settings', 'dummy', default=False)
|
||||
#boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
#descr = OptionDescription('tiramisu', '', [gcdummy, boolop])
|
||||
#raises(ValueError, "cfg = Config(descr)")
|
||||
raises(ValueError, "BoolOption('cfgimpl_get_settings', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('unwrap_from_path', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('objimpl_getdoc', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('_unvalid', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('6unvalid', 'dummy', default=False)")
|
||||
BoolOption('unvalid6', 'dummy', default=False)
|
||||
BoolOption('unvalid_', 'dummy', default=False)
|
||||
|
@ -27,13 +27,13 @@ def make_description():
|
||||
|
||||
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1 = OptionDescription('interface1', '', [master])
|
||||
interface1.set_group_type(groups.family)
|
||||
interface1.objimpl_set_group_type(groups.family)
|
||||
|
||||
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
||||
nombre_interfaces, activer_proxy_client,
|
||||
mode_conteneur_actif, adresse_serveur_ntp,
|
||||
time_zone])
|
||||
general.set_group_type(groups.family)
|
||||
general.objimpl_set_group_type(groups.family)
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1])
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
||||
return descr
|
||||
@ -62,10 +62,10 @@ def test_get_group_type():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
grp = config.unwrap_from_path('creole.general')
|
||||
assert grp.get_group_type() == groups.family
|
||||
assert grp.get_group_type() == 'family'
|
||||
assert isinstance(grp.get_group_type(), groups.GroupType)
|
||||
raises(TypeError, 'grp.set_group_type(groups.default)')
|
||||
assert grp.objimpl_get_group_type() == groups.family
|
||||
assert grp.objimpl_get_group_type() == 'family'
|
||||
assert isinstance(grp.objimpl_get_group_type(), groups.GroupType)
|
||||
raises(TypeError, 'grp.objimpl_set_group_type(groups.default)')
|
||||
|
||||
|
||||
def test_iter_on_groups():
|
||||
@ -91,31 +91,31 @@ def test_groups_with_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.set_group_type(groups.master)
|
||||
assert interface1.get_group_type() == groups.master
|
||||
interface1.objimpl_set_group_type(groups.master)
|
||||
assert interface1.objimpl_get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_groups_with_master_in_config():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.set_group_type(groups.master)
|
||||
interface1.objimpl_set_group_type(groups.master)
|
||||
Config(interface1)
|
||||
assert interface1.get_group_type() == groups.master
|
||||
assert interface1.objimpl_get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_allowed_groups():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ValueError, "interface1.set_group_type('toto')")
|
||||
raises(ValueError, "interface1.objimpl_set_group_type('toto')")
|
||||
|
||||
|
||||
def test_master_not_valid_name():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
invalid_group = OptionDescription('interface1', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ValueError, "invalid_group.set_group_type(groups.master)")
|
||||
raises(ValueError, "invalid_group.objimpl_set_group_type(groups.master)")
|
||||
|
||||
|
||||
def test_sub_group_in_master_group():
|
||||
@ -123,14 +123,14 @@ def test_sub_group_in_master_group():
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
subgroup = OptionDescription("subgroup", '', [])
|
||||
invalid_group = OptionDescription('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ValueError, "invalid_group.set_group_type(groups.master)")
|
||||
raises(ValueError, "invalid_group.objimpl_set_group_type(groups.master)")
|
||||
|
||||
|
||||
def test_group_always_has_multis():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
|
||||
group = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ValueError, "group.set_group_type(groups.master)")
|
||||
raises(ValueError, "group.objimpl_set_group_type(groups.master)")
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
@ -138,13 +138,13 @@ def test_values_with_master_and_slaves():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.set_group_type(groups.master)
|
||||
interface1.objimpl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
opt = cfg.unwrap_from_path("ip_admin_eth0.ip_admin_eth0")
|
||||
opt_slave = cfg.unwrap_from_path("ip_admin_eth0.netmask_admin_eth0")
|
||||
owner = cfg._cfgimpl_context._cfgimpl_settings.getowner()
|
||||
assert interface1.get_group_type() == groups.master
|
||||
assert interface1.objimpl_get_group_type() == groups.master
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owners.default
|
||||
assert cfg.cfgimpl_get_values().getowner(opt_slave) == owners.default
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
@ -159,13 +159,13 @@ def test_reset_values_with_master_and_slaves():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.set_group_type(groups.master)
|
||||
interface1.objimpl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
opt = cfg.unwrap_from_path("ip_admin_eth0.ip_admin_eth0")
|
||||
opt_slave = cfg.unwrap_from_path("ip_admin_eth0.netmask_admin_eth0")
|
||||
owner = cfg._cfgimpl_context._cfgimpl_settings.getowner()
|
||||
assert interface1.get_group_type() == groups.master
|
||||
assert interface1.objimpl_get_group_type() == groups.master
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owners.default
|
||||
assert cfg.cfgimpl_get_values().getowner(opt_slave) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
@ -182,7 +182,7 @@ def test_values_with_master_and_slaves_slave():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.set_group_type(groups.master)
|
||||
interface1.objimpl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
@ -204,7 +204,7 @@ def test_values_with_master_and_slaves_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.set_group_type(groups.master)
|
||||
interface1.objimpl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
|
Reference in New Issue
Block a user