* config herite from BaseInformation class
* _cfgimpl_ => _impl_ * optimpl_ => impl_ * properties/permissives are now set/frozenset * validation raise ValueError if not valid, didn't return anything otherwise * consistencies are now validate in setting and when deleting value * ip/network with netmask consistency now works * DomainnameOption now works * if no validation, don't set cache for value * symlinkoption: remove path (not used)
This commit is contained in:
@ -104,3 +104,11 @@ def test_cfgimpl_get_home_by_path():
|
||||
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']
|
||||
|
||||
|
||||
def test_information_config():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
string = 'some informations'
|
||||
config.impl_set_information('info', string)
|
||||
assert config.impl_get_information('info') == string
|
||||
|
37
test/test_config_domain.py
Normal file
37
test/test_config_domain.py
Normal file
@ -0,0 +1,37 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import DomainnameOption, OptionDescription
|
||||
|
||||
|
||||
def test_domainname():
|
||||
d = DomainnameOption('d', '')
|
||||
od = OptionDescription('a', '', [d])
|
||||
c = Config(od)
|
||||
c.d = 'toto.com'
|
||||
raises(ValueError, "c.d = 'toto'")
|
||||
c.d = 'toto3.com'
|
||||
c.d = 'toto3.3la'
|
||||
raises(ValueError, "c.d = '3toto.com'")
|
||||
c.d = 'toto.co3'
|
||||
raises(ValueError, "c.d = 'toto_super.com'")
|
||||
c.d = 'toto-.com'
|
||||
|
||||
|
||||
def test_domainname_netbios():
|
||||
d = DomainnameOption('d', '', type_='netbios')
|
||||
od = OptionDescription('a', '', [d])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.d = 'toto.com'")
|
||||
c.d = 'toto'
|
||||
raises(ValueError, "c.d = 'domainnametoolong'")
|
||||
|
||||
|
||||
def test_domainname_hostname():
|
||||
d = DomainnameOption('d', '', type_='hostname')
|
||||
od = OptionDescription('a', '', [d])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.d = 'toto.com'")
|
||||
c.d = 'toto'
|
||||
c.d = 'domainnametoolong'
|
45
test/test_config_ip.py
Normal file
45
test/test_config_ip.py
Normal file
@ -0,0 +1,45 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, \
|
||||
OptionDescription
|
||||
|
||||
|
||||
def test_ip():
|
||||
a = IPOption('a', '')
|
||||
b = IPOption('b', '', only_private=True)
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.a = '192.168.1.0'
|
||||
c.a = '88.88.88.88'
|
||||
c.a = '0.0.0.0'
|
||||
assert(ValueError, "c.a = '255.255.255.0'")
|
||||
c.b = '192.168.1.1'
|
||||
c.b = '192.168.1.0'
|
||||
assert(ValueError, "c.b = '88.88.88.88'")
|
||||
c.b = '0.0.0.0'
|
||||
assert(ValueError, "c.b = '255.255.255.0'")
|
||||
|
||||
|
||||
def test_network():
|
||||
a = NetworkOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.a = '192.168.1.0'
|
||||
c.a = '88.88.88.88'
|
||||
c.a = '0.0.0.0'
|
||||
assert(ValueError, "c.a = '255.255.255.0'")
|
||||
|
||||
def test_netmask():
|
||||
a = NetmaskOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
assert(ValueError, "c.a = '192.168.1.1'")
|
||||
assert(ValueError, "c.a = '192.168.1.0'")
|
||||
assert(ValueError, "c.a = '88.88.88.88'")
|
||||
c.a = '0.0.0.0'
|
||||
c.a = '255.255.255.0'
|
@ -29,7 +29,7 @@ def make_description():
|
||||
#FIXME ne pas mettre 2 OD differents dans un meta
|
||||
def test_none():
|
||||
meta = make_description()
|
||||
conf1, conf2 = meta._cfgimpl_children
|
||||
conf1, conf2 = meta._impl_children
|
||||
assert conf1.od1.i3 is conf2.od1.i3 is None
|
||||
assert conf1.getowner('od1.i3') is conf2.getowner('od1.i3') is owners.default
|
||||
meta.od1.i3 = 3
|
||||
@ -58,7 +58,7 @@ def test_none():
|
||||
|
||||
def test_default():
|
||||
meta = make_description()
|
||||
conf1, conf2 = meta._cfgimpl_children
|
||||
conf1, conf2 = meta._impl_children
|
||||
assert conf1.od1.i2 == conf2.od1.i2 == 1
|
||||
assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.default
|
||||
meta.od1.i2 = 3
|
||||
@ -87,7 +87,7 @@ def test_default():
|
||||
|
||||
def test_contexts():
|
||||
meta = make_description()
|
||||
conf1, conf2 = meta._cfgimpl_children
|
||||
conf1, conf2 = meta._impl_children
|
||||
assert conf1.od1.i2 == conf2.od1.i2 == 1
|
||||
assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.default
|
||||
meta.set_contexts('od1.i2', 6)
|
||||
@ -108,7 +108,7 @@ def test_meta_meta():
|
||||
meta1 = make_description()
|
||||
meta2 = MetaConfig([meta1])
|
||||
meta2.cfgimpl_get_settings().setowner(owners.meta)
|
||||
conf1, conf2 = meta1._cfgimpl_children
|
||||
conf1, conf2 = meta1._impl_children
|
||||
assert conf1.od1.i2 == conf2.od1.i2 == 1
|
||||
assert conf1.getowner('od1.i2') is conf2.getowner('od1.i2') is owners.default
|
||||
meta2.od1.i2 = 3
|
||||
@ -142,7 +142,7 @@ def test_meta_meta_set():
|
||||
meta1 = make_description()
|
||||
meta2 = MetaConfig([meta1])
|
||||
meta2.cfgimpl_get_settings().setowner(owners.meta)
|
||||
conf1, conf2 = meta1._cfgimpl_children
|
||||
conf1, conf2 = meta1._impl_children
|
||||
meta2.set_contexts('od1.i1', 7)
|
||||
assert conf1.od1.i1 == conf2.od1.i1 == 7
|
||||
assert conf1.getowner('od1.i1') is conf2.getowner('od1.i1') is owners.user
|
||||
@ -160,7 +160,7 @@ def test_not_meta():
|
||||
conf2 = Config(od2)
|
||||
meta = MetaConfig([conf1, conf2], False)
|
||||
raises(ConfigError, 'meta.od1.i1')
|
||||
conf1, conf2 = meta._cfgimpl_children
|
||||
conf1, conf2 = meta._impl_children
|
||||
meta.set_contexts('od1.i1', 7)
|
||||
assert conf1.od1.i1 == conf2.od1.i1 == 7
|
||||
assert conf1.getowner('od1.i1') is conf2.getowner('od1.i1') is owners.user
|
||||
|
271
test/test_option_calculation.py
Normal file
271
test/test_option_calculation.py
Normal file
@ -0,0 +1,271 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, IPOption, OptionDescription
|
||||
from tiramisu.error import PropertiesOptionError, ConflictError
|
||||
|
||||
|
||||
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')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
intoption2 = 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, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, intoption2])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def make_description_duplicates():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
## dummy 1
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('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, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
# dummy2 (same path)
|
||||
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
||||
# dummy3 (same name)
|
||||
gcdummy3 = BoolOption('dummy', 'dummy2', default=True)
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, gcdummy2, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop, gcdummy3])
|
||||
return descr
|
||||
|
||||
|
||||
def test_identical_paths():
|
||||
"""If in the schema (the option description) there is something that
|
||||
have the same name, an exection is raised
|
||||
"""
|
||||
raises(ConflictError, "make_description_duplicates()")
|
||||
|
||||
|
||||
def make_description2():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
# first multi
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
boolop.enable_multi()
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
# second multi
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
wantframework_option.enable_multi()
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
# FIXME: il faudra tester les validations sur les multis
|
||||
#def test_multi_constraints():
|
||||
# "a multi in a constraint has to have the same length"
|
||||
# descr = make_description2()
|
||||
# cfg = Config(descr)
|
||||
# cfg.boolop = [True, True, False]
|
||||
# cfg.wantframework = [False, False, True]
|
||||
#
|
||||
#def test_multi_raise():
|
||||
# "a multi in a constraint has to have the same length"
|
||||
# # FIXME fusionner les deux tests, MAIS PROBLEME :
|
||||
# # il ne devrait pas etre necessaire de refaire une config
|
||||
# # si la valeur est modifiee une deuxieme fois ->
|
||||
# #raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
|
||||
# # ExceptionFailure: 'DID NOT RAISE'
|
||||
# descr = make_description2()
|
||||
# cfg = Config(descr)
|
||||
# cfg.boolop = [True]
|
||||
# raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
|
||||
# ____________________________________________________________
|
||||
# adding dynamically new options description schema
|
||||
#def test_newoption_add_in_descr():
|
||||
# descr = make_description()
|
||||
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
# descr.add_child(newoption)
|
||||
# config = Config(descr)
|
||||
# assert config.newoption == False
|
||||
|
||||
#def test_newoption_add_in_subdescr():
|
||||
# descr = make_description()
|
||||
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
# descr.gc.add_child(newoption)
|
||||
# config = Config(descr)
|
||||
# config.bool = False
|
||||
# assert config.gc.newoption == False
|
||||
|
||||
#def test_newoption_add_in_config():
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# config.bool = False
|
||||
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
# descr.add_child(newoption)
|
||||
# config.cfgimpl_update()
|
||||
# assert config.newoption == False
|
||||
# ____________________________________________________________
|
||||
|
||||
|
||||
def make_description_requires():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
requires=((intoption, 1, 'hidden'),))
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
stroption, intoption])
|
||||
return descr
|
||||
|
||||
|
||||
def test_hidden_if_in():
|
||||
descr = make_description_requires()
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
cfg.read_write()
|
||||
stroption = cfg.unwrap_from_path('str')
|
||||
assert not 'hidden' in setting[stroption]
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.str")
|
||||
raises(PropertiesOptionError, 'cfg.str="uvw"')
|
||||
assert 'hidden' in setting[stroption]
|
||||
|
||||
|
||||
def test_hidden_if_in_with_group():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=((intoption, 1, 'hidden'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
cfg.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.gc.name")
|
||||
|
||||
|
||||
def test_disabled_with_group():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=((intoption, 1, 'disabled'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
cfg.read_write()
|
||||
assert cfg.gc.name
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.gc.name")
|
||||
#____________________________________________________________
|
||||
|
||||
|
||||
def make_description_callback():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy')
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('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, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def test_has_callback():
|
||||
descr = make_description_callback()
|
||||
# here the owner is 'default'
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.bool = False
|
||||
# because dummy has a callback
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
setting.append('freeze')
|
||||
setting[dummy].append('frozen')
|
||||
raises(PropertiesOptionError, "config.gc.dummy = True")
|
||||
|
||||
|
||||
def test_freeze_and_has_callback():
|
||||
descr = make_description_callback()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.bool = False
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.append('freeze')
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
setting[dummy].append('frozen')
|
||||
raises(PropertiesOptionError, "config.gc.dummy = True")
|
@ -1,270 +1,70 @@
|
||||
import autopath
|
||||
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
|
||||
from tiramisu.error import PropertiesOptionError, ConflictError
|
||||
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\
|
||||
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')
|
||||
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, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
def test_consistency_not_equal():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', (a, b))
|
||||
c = Config(od)
|
||||
assert c.a is None
|
||||
assert c.b is None
|
||||
c.a = 1
|
||||
del(c.a)
|
||||
c.a = 1
|
||||
raises(ValueError, "c.b = 1")
|
||||
c.b = 2
|
||||
|
||||
|
||||
def make_description_duplicates():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
## dummy 1
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('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, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
# dummy2 (same path)
|
||||
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
||||
# dummy3 (same name)
|
||||
gcdummy3 = BoolOption('dummy', 'dummy2', default=True)
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, gcdummy2, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop, gcdummy3])
|
||||
return descr
|
||||
def test_consistency_default():
|
||||
a = IntOption('a', '', 1)
|
||||
b = IntOption('b', '', 1)
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', (a, b))")
|
||||
|
||||
|
||||
def test_identical_paths():
|
||||
"""If in the schema (the option description) there is something that
|
||||
have the same name, an exection is raised
|
||||
"""
|
||||
raises(ConflictError, "make_description_duplicates()")
|
||||
def test_consistency_default_diff():
|
||||
a = IntOption('a', '', 3)
|
||||
b = IntOption('b', '', 1)
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', (a, b))
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.a = 1")
|
||||
c.a = 2
|
||||
c.b = 3
|
||||
assert c.getowner('a') is owners.user
|
||||
raises(ValueError, "del(c.a)")
|
||||
assert c.getowner('a') is owners.user
|
||||
|
||||
|
||||
def make_description2():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
# first multi
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
boolop.enable_multi()
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
# second multi
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
wantframework_option.enable_multi()
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
def test_consistency_ip_netmask():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', (b, a))
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.b = '255.255.255.0'
|
||||
c.a = '192.168.1.2'
|
||||
c.b = '255.255.255.255'
|
||||
c.b = '255.255.255.0'
|
||||
raises(ValueError, "c.a = '192.168.1.0'")
|
||||
|
||||
|
||||
# FIXME: il faudra tester les validations sur les multis
|
||||
#def test_multi_constraints():
|
||||
# "a multi in a constraint has to have the same length"
|
||||
# descr = make_description2()
|
||||
# cfg = Config(descr)
|
||||
# cfg.boolop = [True, True, False]
|
||||
# cfg.wantframework = [False, False, True]
|
||||
#
|
||||
#def test_multi_raise():
|
||||
# "a multi in a constraint has to have the same length"
|
||||
# # FIXME fusionner les deux tests, MAIS PROBLEME :
|
||||
# # il ne devrait pas etre necessaire de refaire une config
|
||||
# # si la valeur est modifiee une deuxieme fois ->
|
||||
# #raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
|
||||
# # ExceptionFailure: 'DID NOT RAISE'
|
||||
# descr = make_description2()
|
||||
# cfg = Config(descr)
|
||||
# cfg.boolop = [True]
|
||||
# raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
|
||||
# ____________________________________________________________
|
||||
# adding dynamically new options description schema
|
||||
#def test_newoption_add_in_descr():
|
||||
# descr = make_description()
|
||||
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
# descr.add_child(newoption)
|
||||
# config = Config(descr)
|
||||
# assert config.newoption == False
|
||||
|
||||
#def test_newoption_add_in_subdescr():
|
||||
# descr = make_description()
|
||||
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
# descr.gc.add_child(newoption)
|
||||
# config = Config(descr)
|
||||
# config.bool = False
|
||||
# assert config.gc.newoption == False
|
||||
|
||||
#def test_newoption_add_in_config():
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# config.bool = False
|
||||
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
# descr.add_child(newoption)
|
||||
# config.cfgimpl_update()
|
||||
# assert config.newoption == False
|
||||
# ____________________________________________________________
|
||||
|
||||
|
||||
def make_description_requires():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
requires=((intoption, 1, 'hidden'),))
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
stroption, intoption])
|
||||
return descr
|
||||
|
||||
|
||||
def test_hidden_if_in():
|
||||
descr = make_description_requires()
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
cfg.read_write()
|
||||
stroption = cfg.unwrap_from_path('str')
|
||||
assert not 'hidden' in setting[stroption]
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.str")
|
||||
raises(PropertiesOptionError, 'cfg.str="uvw"')
|
||||
assert 'hidden' in setting[stroption]
|
||||
|
||||
|
||||
def test_hidden_if_in_with_group():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=((intoption, 1, 'hidden'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
cfg.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.gc.name")
|
||||
|
||||
|
||||
def test_disabled_with_group():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=((intoption, 1, 'disabled'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
cfg.read_write()
|
||||
assert cfg.gc.name
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.gc.name")
|
||||
#____________________________________________________________
|
||||
|
||||
|
||||
def make_description_callback():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy')
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('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, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def test_has_callback():
|
||||
descr = make_description_callback()
|
||||
# here the owner is 'default'
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.bool = False
|
||||
# because dummy has a callback
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
setting.append('freeze')
|
||||
setting[dummy].append('frozen')
|
||||
raises(PropertiesOptionError, "config.gc.dummy = True")
|
||||
|
||||
|
||||
def test_freeze_and_has_callback():
|
||||
descr = make_description_callback()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.bool = False
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.append('freeze')
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
setting[dummy].append('frozen')
|
||||
raises(PropertiesOptionError, "config.gc.dummy = True")
|
||||
def test_consistency_network_netmask():
|
||||
a = NetworkOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
b.impl_add_consistency('network_netmask', (b, a))
|
||||
c = Config(od)
|
||||
c.a = '192.168.1.1'
|
||||
c.b = '255.255.255.255'
|
||||
del(c.b)
|
||||
c.a = '192.168.1.0'
|
||||
c.b = '255.255.255.0'
|
||||
raises(ValueError, "c.a = '192.168.1.1'")
|
||||
|
@ -50,7 +50,7 @@ def test_default_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.optimpl_getdefault() is False
|
||||
assert b.impl_getdefault() is False
|
||||
|
||||
|
||||
def test_force_default_on_freeze():
|
||||
|
@ -233,7 +233,7 @@ def test_multi_with_bool():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.optimpl_is_multi() is True
|
||||
assert descr.bool.impl_is_multi() is True
|
||||
config.bool = [True, False]
|
||||
assert config.cfgimpl_get_values()[s] == [True, False]
|
||||
assert config.bool == [True, False]
|
||||
@ -243,7 +243,7 @@ def test_multi_with_bool_two():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.optimpl_is_multi() is True
|
||||
assert descr.bool.impl_is_multi() is True
|
||||
raises(ValueError, "config.bool = True")
|
||||
|
||||
|
||||
@ -258,7 +258,7 @@ def test_choice_access_with_multi():
|
||||
#____________________________________________________________
|
||||
def test_symlink_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", "s1.b", opt=boolopt)
|
||||
linkopt = SymLinkOption("c", boolopt)
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
config = Config(descr)
|
||||
@ -280,10 +280,10 @@ def test_accepts_multiple_changes_from_option():
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = "egg"
|
||||
assert s.optimpl_getdefault() == "string"
|
||||
assert s.impl_getdefault() == "string"
|
||||
assert config.string == "egg"
|
||||
config.string = 'blah'
|
||||
assert s.optimpl_getdefault() == "string"
|
||||
assert s.impl_getdefault() == "string"
|
||||
assert config.string == "blah"
|
||||
config.string = 'bol'
|
||||
assert config.string == 'bol'
|
||||
|
@ -119,5 +119,5 @@ def test_with_many_subgroups():
|
||||
path = 'gc.subgroup.booltwo'
|
||||
homeconfig, name = config.cfgimpl_get_home_by_path(path)
|
||||
assert name == "booltwo"
|
||||
getattr(homeconfig._cfgimpl_descr, name)
|
||||
getattr(homeconfig.cfgimpl_get_description(), name)
|
||||
assert 'hidden' in setting[booltwo]
|
||||
|
@ -50,7 +50,7 @@ def test_optname_shall_not_start_with_numbers():
|
||||
def test_option_has_an_api_name():
|
||||
raises(ValueError, "BoolOption('cfgimpl_get_settings', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('unwrap_from_path', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('optimpl_getdoc', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('impl_getdoc', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('_unvalid', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('6unvalid', 'dummy', default=False)")
|
||||
BoolOption('unvalid6', '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.optimpl_set_group_type(groups.family)
|
||||
interface1.impl_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.optimpl_set_group_type(groups.family)
|
||||
general.impl_set_group_type(groups.family)
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1])
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
||||
return descr
|
||||
@ -74,10 +74,10 @@ def test_get_group_type():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
grp = config.unwrap_from_path('creole.general')
|
||||
assert grp.optimpl_get_group_type() == groups.family
|
||||
assert grp.optimpl_get_group_type() == 'family'
|
||||
assert isinstance(grp.optimpl_get_group_type(), groups.GroupType)
|
||||
raises(TypeError, 'grp.optimpl_set_group_type(groups.default)')
|
||||
assert grp.impl_get_group_type() == groups.family
|
||||
assert grp.impl_get_group_type() == 'family'
|
||||
assert isinstance(grp.impl_get_group_type(), groups.GroupType)
|
||||
raises(TypeError, 'grp.impl_set_group_type(groups.default)')
|
||||
|
||||
|
||||
def test_iter_on_groups():
|
||||
@ -103,31 +103,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.optimpl_set_group_type(groups.master)
|
||||
assert interface1.optimpl_get_group_type() == groups.master
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
assert interface1.impl_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.optimpl_set_group_type(groups.master)
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
Config(interface1)
|
||||
assert interface1.optimpl_get_group_type() == groups.master
|
||||
assert interface1.impl_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.optimpl_set_group_type('toto')")
|
||||
raises(ValueError, "interface1.impl_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.optimpl_set_group_type(groups.master)")
|
||||
raises(ValueError, "invalid_group.impl_set_group_type(groups.master)")
|
||||
|
||||
|
||||
def test_sub_group_in_master_group():
|
||||
@ -135,14 +135,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.optimpl_set_group_type(groups.master)")
|
||||
raises(ValueError, "invalid_group.impl_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.optimpl_set_group_type(groups.master)")
|
||||
raises(ValueError, "group.impl_set_group_type(groups.master)")
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
@ -150,11 +150,11 @@ 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.optimpl_set_group_type(groups.master)
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
owner = cfg._cfgimpl_context._cfgimpl_settings.getowner()
|
||||
assert interface1.optimpl_get_group_type() == groups.master
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
|
||||
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
@ -169,11 +169,11 @@ 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.optimpl_set_group_type(groups.master)
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
owner = cfg._cfgimpl_context._cfgimpl_settings.getowner()
|
||||
assert interface1.optimpl_get_group_type() == groups.master
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert interface1.impl_get_group_type() == groups.master
|
||||
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owners.default
|
||||
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
@ -190,7 +190,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.optimpl_set_group_type(groups.master)
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
@ -212,7 +212,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.optimpl_set_group_type(groups.master)
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
|
54
test/test_slots.py
Normal file
54
test/test_slots.py
Normal file
@ -0,0 +1,54 @@
|
||||
# coding: utf-8
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config, SubConfig
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, UnicodeOption
|
||||
|
||||
|
||||
def test_slots_option():
|
||||
c = BoolOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = IntOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = FloatOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = StrOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = SymLinkOption('b', c)
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = UnicodeOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = ChoiceOption('a', '', ('a',))
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = OptionDescription('a', '', [])
|
||||
raises(AttributeError, "c.x = 1")
|
||||
|
||||
|
||||
def test_slots_config():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
c = Config(od2)
|
||||
raises(AttributeError, "c.x = 1")
|
||||
raises(AttributeError, "c.cfgimpl_x = 1")
|
||||
sc = c.a
|
||||
assert isinstance(sc, SubConfig)
|
||||
raises(AttributeError, "sc.x = 1")
|
||||
raises(AttributeError, "sc.cfgimpl_x = 1")
|
||||
|
||||
|
||||
def test_slots_setting():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
c = Config(od2)
|
||||
s = c.cfgimpl_get_settings()
|
||||
raises(AttributeError, "s.x = 1")
|
||||
|
||||
|
||||
def test_slots_value():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
c = Config(od2)
|
||||
v = c.cfgimpl_get_values()
|
||||
raises(AttributeError, "v.x = 1")
|
Reference in New Issue
Block a user