optimisations and all is properties
This commit is contained in:
@ -5,20 +5,20 @@ from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
@ -27,21 +27,21 @@ def make_description():
|
||||
return descr
|
||||
|
||||
def make_description_duplicates():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
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'])
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
# dummy2 (same path)
|
||||
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
||||
# dummy3 (same name)
|
||||
@ -57,8 +57,7 @@ def test_identical_paths():
|
||||
"""If in the schema (the option description) there is something that
|
||||
have the same name, an exection is raised
|
||||
"""
|
||||
descr = make_description_duplicates()
|
||||
raises(ConflictConfigError, "cfg = Config(descr)")
|
||||
raises(ConflictConfigError, "make_description_duplicates()")
|
||||
|
||||
def make_description2():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
@ -75,11 +74,11 @@ 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'])
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
# second multi
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
wantframework_option.enable_multi()
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
@ -110,20 +109,20 @@ def make_description2():
|
||||
# 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_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_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()
|
||||
@ -135,17 +134,17 @@ def test_newoption_add_in_subdescr():
|
||||
# assert config.newoption == False
|
||||
# ____________________________________________________________
|
||||
def make_description_requires():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
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')
|
||||
('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=[('int', 1, 'hide')])
|
||||
requires=(('int', 1, 'hidden'),))
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
@ -155,72 +154,76 @@ def make_description_requires():
|
||||
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')
|
||||
stroption = cfg.unwrap_from_path('str')
|
||||
assert not stroption._is_hidden()
|
||||
assert not setting.has_property('hidden', stroption)
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.str")
|
||||
raises(PropertiesOptionError, 'cfg.str= "uvw"')
|
||||
assert stroption._is_hidden()
|
||||
assert setting.has_property('hidden', stroption)
|
||||
|
||||
def test_hidden_if_in_with_group():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
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')
|
||||
('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, 'hide')])
|
||||
requires=(('int', 1, 'hidden'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
assert not gcgroup._is_hidden()
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
assert not setting.has_property('hidden', stroption)
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.gc.name")
|
||||
assert gcgroup._is_hidden()
|
||||
|
||||
def test_disabled_with_group():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
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')
|
||||
('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, 'disable')])
|
||||
requires=(('int', 1, 'disabled'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
assert not gcgroup._is_disabled()
|
||||
setting = cfg.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
assert cfg.gc.name
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.gc.name")
|
||||
assert gcgroup._is_disabled()
|
||||
#____________________________________________________________
|
||||
|
||||
def make_description_callback():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
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'])
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
@ -232,21 +235,23 @@ 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.bool = False
|
||||
# because dummy has a callback
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
settings = config.cfgimpl_get_settings()
|
||||
settings.freeze()
|
||||
dummy.freeze()
|
||||
setting.enable_property('freeze')
|
||||
setting.add_property('frozen', dummy)
|
||||
raises(TypeError, "config.gc.dummy = True")
|
||||
|
||||
def test_freeze_and_has_callback_with_setoption():
|
||||
descr = make_description_callback()
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
config.bool = False
|
||||
settings = config.cfgimpl_get_settings()
|
||||
settings.freeze()
|
||||
config.cfgimpl_get_settings().enable_property('freeze')
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
dummy.freeze()
|
||||
config.cfgimpl_get_settings().add_property('frozen', dummy)
|
||||
raises(TypeError, "config.gc.setoption('dummy', True, 'gen_config')")
|
||||
#____________________________________________________________
|
||||
|
Reference in New Issue
Block a user