remove _setoption in SymLinkOption
objimpl_ => optimpl_ ConflictConfigError => ConflictError add read_write/read_only/getowner in Config
This commit is contained in:
@ -38,7 +38,7 @@ def test_freeze_whole_config():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
conf.read_write()
|
||||
setting.append('everything_frozen')
|
||||
assert conf.gc.dummy is False
|
||||
prop = []
|
||||
@ -57,7 +57,7 @@ def test_freeze_one_option():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
conf.read_write()
|
||||
#freeze only one option
|
||||
dummy = conf.unwrap_from_path('gc.dummy')
|
||||
setting[dummy].append('frozen')
|
||||
@ -76,7 +76,7 @@ def test_frozen_value():
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
setting.append('frozen')
|
||||
setting[s].append('frozen')
|
||||
prop = []
|
||||
@ -92,7 +92,7 @@ def test_freeze():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
conf.read_write()
|
||||
setting.append('frozen')
|
||||
name = conf.unwrap_from_path("gc.name")
|
||||
setting[name].append('frozen')
|
||||
@ -108,7 +108,7 @@ def test_freeze_multi():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
conf.read_write()
|
||||
setting.append('frozen')
|
||||
obj = conf.unwrap_from_path('boolop')
|
||||
setting[obj].append('frozen')
|
||||
@ -124,7 +124,7 @@ def test_freeze_get_multi():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
setting = conf.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
conf.read_write()
|
||||
setting.append('frozen')
|
||||
valmulti = conf.boolop
|
||||
valmulti.append(False)
|
||||
@ -141,7 +141,6 @@ def test_freeze_get_multi():
|
||||
def test_force_store_value():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
opt = conf.unwrap_from_path('wantref')
|
||||
assert conf.cfgimpl_get_values().getowner(opt) == 'default'
|
||||
assert conf.getowner('wantref') == 'default'
|
||||
conf.wantref
|
||||
assert conf.cfgimpl_get_values().getowner(opt) == 'user'
|
||||
assert conf.getowner('wantref') == 'user'
|
||||
|
@ -22,25 +22,23 @@ def make_description():
|
||||
def test_mandatory_ro():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str1
|
||||
except PropertiesOptionError, err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str1 = 'yes'
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
assert config.str1 == 'yes'
|
||||
|
||||
|
||||
def test_mandatory_rw():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
#not mandatory in rw
|
||||
config.str1
|
||||
config.str1 = 'yes'
|
||||
@ -50,17 +48,16 @@ def test_mandatory_rw():
|
||||
def test_mandatory_default():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
#not mandatory in rw
|
||||
config.str
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str = 'yes'
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
config.str
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str = None
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str
|
||||
@ -74,9 +71,8 @@ def test_mandatory_none():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.str1 = None
|
||||
setting = config.cfgimpl_get_settings()
|
||||
assert config.cfgimpl_get_values().getowner(descr.str1) == 'user'
|
||||
setting.read_only()
|
||||
assert config.getowner('str1') == 'user'
|
||||
config.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str1
|
||||
@ -89,9 +85,8 @@ def test_mandatory_empty():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.str1 = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
assert config.cfgimpl_get_values().getowner(descr.str1) == 'user'
|
||||
setting.read_only()
|
||||
assert config.getowner('str1') == 'user'
|
||||
config.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str1
|
||||
@ -103,20 +98,19 @@ def test_mandatory_empty():
|
||||
def test_mandatory_multi_none():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.str3 = [None]
|
||||
setting.read_only()
|
||||
assert config.cfgimpl_get_values().getowner(descr.str3) == 'user'
|
||||
config.read_only()
|
||||
assert config.getowner('str3') == 'user'
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
except PropertiesOptionError, err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str3 = ['yes', None]
|
||||
setting.read_only()
|
||||
assert config.cfgimpl_get_values().getowner(descr.str3) == 'user'
|
||||
config.read_only()
|
||||
assert config.getowner('str3') == 'user'
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
@ -128,20 +122,19 @@ def test_mandatory_multi_none():
|
||||
def test_mandatory_multi_empty():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.str3 = ['']
|
||||
setting.read_only()
|
||||
assert config.cfgimpl_get_values().getowner(descr.str3) == 'user'
|
||||
config.read_only()
|
||||
assert config.getowner('str3') == 'user'
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
except PropertiesOptionError, err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str3 = ['yes', '']
|
||||
setting.read_only()
|
||||
assert config.cfgimpl_get_values().getowner(descr.str3) == 'user'
|
||||
config.read_only()
|
||||
assert config.getowner('str3') == 'user'
|
||||
prop = []
|
||||
try:
|
||||
config.str3
|
||||
@ -153,9 +146,8 @@ def test_mandatory_multi_empty():
|
||||
def test_mandatory_multi_append():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.str3 = ['yes']
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str3.append(None)
|
||||
|
||||
|
||||
@ -164,7 +156,7 @@ def test_mandatory_disabled():
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.str1
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.str1
|
||||
@ -183,18 +175,17 @@ def test_mandatory_disabled():
|
||||
def test_mandatory_unicode():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.unicode2
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.unicode2
|
||||
except PropertiesOptionError, err:
|
||||
prop = err.proptype
|
||||
assert prop == ['mandatory']
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.unicode2 = u''
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
prop = []
|
||||
try:
|
||||
config.unicode2
|
||||
@ -207,8 +198,7 @@ def test_mandatory_warnings_ro():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
proc = []
|
||||
try:
|
||||
config.str
|
||||
@ -216,9 +206,9 @@ def test_mandatory_warnings_ro():
|
||||
proc = err.proptype
|
||||
assert proc == ['mandatory']
|
||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str = 'a'
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
assert list(mandatory_warnings(config)) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
@ -226,8 +216,7 @@ def test_mandatory_warnings_rw():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str
|
||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
||||
config.str = 'a'
|
||||
@ -239,7 +228,7 @@ def test_mandatory_warnings_disabled():
|
||||
config = Config(descr)
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str
|
||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
||||
setting[descr.str].append('disabled')
|
||||
@ -251,9 +240,9 @@ def test_mandatory_warnings_frozen():
|
||||
config = Config(descr)
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.str
|
||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
||||
setting[descr.str].append('frozen')
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
||||
|
@ -1,64 +1,69 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from error import ConfigError
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, 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')
|
||||
('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'),))
|
||||
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])
|
||||
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')
|
||||
('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'),))
|
||||
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)
|
||||
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
||||
# dummy3 (same name)
|
||||
gcdummy3 = BoolOption('dummy', 'dummy2', default=True)
|
||||
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])
|
||||
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(ConflictConfigError, "make_description_duplicates()")
|
||||
raises(ConflictError, "make_description_duplicates()")
|
||||
|
||||
|
||||
def make_description2():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
@ -67,7 +72,7 @@ def make_description2():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
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)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
@ -75,7 +80,7 @@ def make_description2():
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
boolop.enable_multi()
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
# second multi
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
@ -84,11 +89,12 @@ def make_description2():
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
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"
|
||||
@ -134,6 +140,8 @@ def make_description2():
|
||||
# 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)
|
||||
@ -141,7 +149,7 @@ def make_description_requires():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
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)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
@ -149,15 +157,15 @@ def make_description_requires():
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
stroption, intoption])
|
||||
stroption, intoption])
|
||||
return descr
|
||||
|
||||
|
||||
def test_hidden_if_in():
|
||||
descr = make_description_requires()
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
intoption = cfg.unwrap_from_path('int')
|
||||
cfg.read_write()
|
||||
stroption = cfg.unwrap_from_path('str')
|
||||
assert not 'hidden' in setting[stroption]
|
||||
cfg.int = 1
|
||||
@ -165,6 +173,7 @@ def test_hidden_if_in():
|
||||
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)
|
||||
@ -172,21 +181,22 @@ def test_hidden_if_in_with_group():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
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)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=(('int', 1, 'hidden'),))
|
||||
requires=(('int', 1, 'hidden'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
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)
|
||||
@ -194,50 +204,51 @@ def test_disabled_with_group():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
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)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=(('int', 1, 'disabled'),))
|
||||
requires=(('int', 1, 'disabled'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
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', callback="toto")
|
||||
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', True, 'hidden'),))
|
||||
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])
|
||||
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()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
config.bool = False
|
||||
# because dummy has a callback
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
@ -245,15 +256,15 @@ def test_has_callback():
|
||||
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()
|
||||
setting.read_write()
|
||||
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")
|
||||
#____________________________________________________________
|
||||
|
@ -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.objimpl_getdefault() is False
|
||||
assert b.optimpl_getdefault() is False
|
||||
|
||||
|
||||
def test_force_default_on_freeze():
|
||||
|
@ -1,15 +1,16 @@
|
||||
import autopath
|
||||
|
||||
from py.test import raises
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, 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,41 +22,41 @@ 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_default_owner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy == False
|
||||
dm = cfg.unwrap_from_path('dummy')
|
||||
assert cfg.cfgimpl_get_values().getowner(dm) == 'default'
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner('dummy') == 'default'
|
||||
cfg.dummy = True
|
||||
assert cfg.cfgimpl_get_values().getowner(dm) == owners.user
|
||||
assert cfg.getowner('dummy') == owners.user
|
||||
|
||||
|
||||
def test_add_owner():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy == False
|
||||
dm = cfg.unwrap_from_path('dummy')
|
||||
assert cfg.cfgimpl_get_values().getowner(dm) == 'default'
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner('dummy') == 'default'
|
||||
owners.add_owner("gen_config")
|
||||
cfg.cfgimpl_get_settings().setowner(owners.gen_config)
|
||||
cfg.dummy = True
|
||||
assert cfg.cfgimpl_get_values().getowner(dm) == owners.gen_config
|
||||
assert cfg.getowner('dummy') == owners.gen_config
|
||||
|
||||
|
||||
def test_owner_is_not_a_string():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy == False
|
||||
dm = cfg.unwrap_from_path('dummy')
|
||||
assert cfg.cfgimpl_get_values().getowner(dm) == owners.default
|
||||
assert cfg.cfgimpl_get_values().getowner(dm) == 'default'
|
||||
assert isinstance(cfg.cfgimpl_get_values().getowner(dm), owners.Owner)
|
||||
assert cfg.dummy is False
|
||||
assert cfg.getowner('dummy') == owners.default
|
||||
assert cfg.getowner('dummy') == 'default'
|
||||
assert isinstance(cfg.getowner('dummy'), owners.Owner)
|
||||
cfg.dummy = True
|
||||
assert cfg.cfgimpl_get_values().getowner(dm) == 'user'
|
||||
assert cfg.getowner('dummy') == 'user'
|
||||
|
@ -5,7 +5,7 @@ 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
|
||||
StrOption, OptionDescription, SymLinkOption
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
@ -56,10 +56,10 @@ def test_reset():
|
||||
config = Config(descr)
|
||||
config.string = "foo"
|
||||
assert config.string == "foo"
|
||||
assert config.cfgimpl_get_values().getowner(s) == owners.user
|
||||
assert config.getowner('string') == owners.user
|
||||
del(config.string)
|
||||
assert config.string == 'string'
|
||||
assert config.cfgimpl_get_values().getowner(s) == owners.default
|
||||
assert config.getowner('string') == owners.default
|
||||
|
||||
|
||||
def test_reset_with_multi():
|
||||
@ -69,13 +69,13 @@ def test_reset_with_multi():
|
||||
# config.string = []
|
||||
del(config.string)
|
||||
assert config.string == ["string"]
|
||||
assert config.cfgimpl_get_values().getowner(s) == 'default'
|
||||
assert config.getowner('string') == 'default'
|
||||
config.string = ["eggs", "spam", "foo"]
|
||||
assert config.cfgimpl_get_values().getowner(s) == 'user'
|
||||
assert config.getowner('string') == 'user'
|
||||
config.string = []
|
||||
del(config.string)
|
||||
# assert config.string == ["string"]
|
||||
assert config.cfgimpl_get_values().getowner(s) == 'default'
|
||||
assert config.getowner('string') == 'default'
|
||||
raises(ValueError, "config.string = None")
|
||||
|
||||
|
||||
@ -113,27 +113,18 @@ def test_item_access_with_multi():
|
||||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
assert config.string[0] == "foo"
|
||||
# FIXME
|
||||
config.string[0] = 'changetest'
|
||||
# assert config.string[0] == 'changetest'
|
||||
# assert config.string[
|
||||
assert config.string[0] == 'changetest'
|
||||
|
||||
|
||||
def test_access_with_multi_default():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert config._cfgimpl_values.getowner(s) == 'default'
|
||||
assert config.getowner('string') == 'default'
|
||||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
assert config._cfgimpl_values.getowner(s) == 'user'
|
||||
|
||||
#def test_attribute_access_with_multi2():
|
||||
# s = StrOption("string", "", default="string", multi=True)
|
||||
# descr = OptionDescription("options", "", [s])
|
||||
# config = Config(descr)
|
||||
# config.string = ["foo", "bar"]
|
||||
# assert config.string == ["foo", "bar"]
|
||||
assert config.getowner('string') == 'user'
|
||||
|
||||
|
||||
def test_multi_with_requires():
|
||||
@ -144,7 +135,7 @@ def test_multi_with_requires():
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
||||
@ -174,7 +165,7 @@ def test_multi_with_requires_in_another_group():
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||
@ -191,7 +182,7 @@ def test_apply_requires_from_config():
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, 'config.opt.str')
|
||||
@ -208,7 +199,7 @@ def test_apply_requires_with_disabled():
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
assert not 'disabled' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, 'config.opt.str')
|
||||
@ -225,7 +216,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
assert not 'disabled' in setting[stroption]
|
||||
config.int = 1
|
||||
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||
@ -240,7 +231,7 @@ def test_multi_with_requires_that_is_multi():
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = [1, 1]
|
||||
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
||||
@ -251,7 +242,7 @@ def test_multi_with_bool():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.objimpl_is_multi() is True
|
||||
assert descr.bool.optimpl_is_multi() is True
|
||||
config.bool = [True, False]
|
||||
assert config.cfgimpl_get_values()[s] == [True, False]
|
||||
assert config.bool == [True, False]
|
||||
@ -261,7 +252,7 @@ def test_multi_with_bool_two():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.objimpl_is_multi() is True
|
||||
assert descr.bool.optimpl_is_multi() is True
|
||||
raises(ValueError, "config.bool = True")
|
||||
|
||||
|
||||
@ -271,122 +262,40 @@ def test_choice_access_with_multi():
|
||||
config = Config(descr)
|
||||
config.t1 = ["a", "b", "a", "b"]
|
||||
assert config.t1 == ["a", "b", "a", "b"]
|
||||
# ____________________________________________________________
|
||||
|
||||
#def test_setoption_from_option():
|
||||
# "a setoption directly from the option is **not** a good practice"
|
||||
# booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
# descr = OptionDescription('descr', '', [booloption])
|
||||
# cfg = Config(descr)
|
||||
# booloption.setoption(cfg, False)
|
||||
# assert cfg.bool == False
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
#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_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_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_config_impl_values():
|
||||
# descr = make_description()
|
||||
# config = Config(descr)
|
||||
# config.bool = False
|
||||
## gcdummy.setoption(config, True, "user")
|
||||
## config.setoption("gc.dummy", True, "user")
|
||||
# #config.gc.dummy = True
|
||||
## config.setoption("bool", False, "user")
|
||||
# config.set(dummy=False)
|
||||
# assert config.gc._cfgimpl_context._cfgimpl_values.values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
||||
# ## acces to the option object
|
||||
## config.gc._cfgimpl_descr.dummy.setoption(config, True, "user")
|
||||
# assert config.gc.dummy == False
|
||||
## config.set(dummy=True)
|
||||
## assert config.gc.dummy == True
|
||||
|
||||
#____________________________________________________________
|
||||
#def test_accepts_multiple_changes_from_option():
|
||||
# s = StrOption("string", "", default="string")
|
||||
# descr = OptionDescription("options", "", [s])
|
||||
# config = Config(descr)
|
||||
# config.string = "egg"
|
||||
# assert s.getdefault() == "string"
|
||||
# assert config.string == "egg"
|
||||
# s.setoption(config, 'blah')
|
||||
# assert s.getdefault() == "string"
|
||||
# assert config.string == "blah"
|
||||
# s.setoption(config, 'bol')
|
||||
# assert config.string == 'bol'
|
||||
def test_accepts_multiple_changes_from_option():
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = "egg"
|
||||
assert s.optimpl_getdefault() == "string"
|
||||
assert config.string == "egg"
|
||||
config.string = 'blah'
|
||||
assert s.optimpl_getdefault() == "string"
|
||||
assert config.string == "blah"
|
||||
config.string = 'bol'
|
||||
assert config.string == 'bol'
|
||||
|
||||
|
||||
def test_allow_multiple_changes_from_config():
|
||||
@ -403,8 +312,6 @@ def test_allow_multiple_changes_from_config():
|
||||
assert config.string == "oh"
|
||||
config.string = "blah"
|
||||
assert config.string == "blah"
|
||||
# config.set(string2='blah')
|
||||
# assert config.bip.string2 == 'blah'
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
@ -427,6 +334,5 @@ def test_access_by_get_whith_hide():
|
||||
BoolOption("b2", ""),
|
||||
BoolOption("d1", "")])
|
||||
c = Config(descr)
|
||||
setting = c.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
c.read_write()
|
||||
raises(AttributeError, "c.find(byname='b1')")
|
||||
|
@ -43,7 +43,7 @@ def test_is_hidden():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
assert not 'frozen' in setting[dummy]
|
||||
# setattr
|
||||
@ -56,7 +56,7 @@ def test_group_is_hidden():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
gc = config.unwrap_from_path('gc')
|
||||
config.unwrap_from_path('gc.dummy')
|
||||
setting[gc].append('hidden')
|
||||
@ -80,7 +80,7 @@ def test_group_is_hidden_multi():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
obj = config.unwrap_from_path('objspace')
|
||||
objspace = config.objspace
|
||||
setting[obj].append('hidden')
|
||||
@ -101,7 +101,7 @@ def test_global_show():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
setting[dummy].append('hidden')
|
||||
assert 'hidden' in setting[dummy]
|
||||
|
@ -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('objimpl_getdoc', 'dummy', default=False)")
|
||||
raises(ValueError, "BoolOption('optimpl_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.objimpl_set_group_type(groups.family)
|
||||
interface1.optimpl_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.objimpl_set_group_type(groups.family)
|
||||
general.optimpl_set_group_type(groups.family)
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1])
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
||||
return descr
|
||||
@ -58,14 +58,26 @@ def test_base_config():
|
||||
assert config.creole.make_dict(flatten=True) == result
|
||||
|
||||
|
||||
def test_make_dict_filter():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
|
||||
'general.serveur_ntp': [], 'general.mode_conteneur_actif': False,
|
||||
'general.time_zone': 'Paris', 'general.nom_machine': 'eoleng',
|
||||
'general.activer_proxy_client': False}
|
||||
assert config.creole.make_dict(withoption='numero_etab') == result
|
||||
raises(AttributeError, "config.creole.make_dict(withoption='numero_etab', withvalue='toto')")
|
||||
assert config.creole.make_dict(withoption='numero_etab', withvalue=None) == result
|
||||
|
||||
|
||||
def test_get_group_type():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
grp = config.unwrap_from_path('creole.general')
|
||||
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)')
|
||||
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)')
|
||||
|
||||
|
||||
def test_iter_on_groups():
|
||||
@ -91,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.objimpl_set_group_type(groups.master)
|
||||
assert interface1.objimpl_get_group_type() == groups.master
|
||||
interface1.optimpl_set_group_type(groups.master)
|
||||
assert interface1.optimpl_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.objimpl_set_group_type(groups.master)
|
||||
interface1.optimpl_set_group_type(groups.master)
|
||||
Config(interface1)
|
||||
assert interface1.objimpl_get_group_type() == groups.master
|
||||
assert interface1.optimpl_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.objimpl_set_group_type('toto')")
|
||||
raises(ValueError, "interface1.optimpl_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.objimpl_set_group_type(groups.master)")
|
||||
raises(ValueError, "invalid_group.optimpl_set_group_type(groups.master)")
|
||||
|
||||
|
||||
def test_sub_group_in_master_group():
|
||||
@ -123,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.objimpl_set_group_type(groups.master)")
|
||||
raises(ValueError, "invalid_group.optimpl_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.objimpl_set_group_type(groups.master)")
|
||||
raises(ValueError, "group.optimpl_set_group_type(groups.master)")
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
@ -138,42 +150,38 @@ 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.objimpl_set_group_type(groups.master)
|
||||
interface1.optimpl_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.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 interface1.optimpl_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 == []
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owner
|
||||
assert cfg.cfgimpl_get_values().getowner(opt_slave) == owners.default
|
||||
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner
|
||||
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
|
||||
|
||||
|
||||
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.objimpl_set_group_type(groups.master)
|
||||
interface1.optimpl_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.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 interface1.optimpl_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")
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owner
|
||||
assert cfg.cfgimpl_get_values().getowner(opt_slave) == owners.default
|
||||
assert cfg.getowner("ip_admin_eth0.ip_admin_eth0") == owner
|
||||
assert cfg.getowner("ip_admin_eth0.netmask_admin_eth0") == owners.default
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owners.default
|
||||
assert cfg.cfgimpl_get_values().getowner(opt_slave) == owners.default
|
||||
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.ip_admin_eth0 == []
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
|
||||
@ -182,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.objimpl_set_group_type(groups.master)
|
||||
interface1.optimpl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
@ -204,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.objimpl_set_group_type(groups.master)
|
||||
interface1.optimpl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
|
@ -14,7 +14,7 @@ def test_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
props = []
|
||||
try:
|
||||
config.u1
|
||||
@ -43,7 +43,7 @@ def test_permissive_mandatory():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_only()
|
||||
config.read_only()
|
||||
props = []
|
||||
try:
|
||||
config.u1
|
||||
@ -65,7 +65,7 @@ def test_permissive_frozen():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.read_write()
|
||||
setting.set_permissive(('frozen', 'disabled',))
|
||||
try:
|
||||
config.u1 = 1
|
||||
|
Reference in New Issue
Block a user