remove _setoption in SymLinkOption

objimpl_ => optimpl_
ConflictConfigError => ConflictError
add read_write/read_only/getowner in Config
This commit is contained in:
2013-04-22 09:19:05 +02:00
parent 682d9fe207
commit e883e5b89e
16 changed files with 355 additions and 419 deletions

View File

@ -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")
#____________________________________________________________