owners are *real* objects now
This commit is contained in:
@ -3,6 +3,7 @@ from py.test import raises
|
||||
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from tiramisu.setting import settings
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
@ -60,14 +61,6 @@ def test_identical_paths():
|
||||
descr = make_description_duplicates()
|
||||
raises(ConflictConfigError, "cfg = Config(descr)")
|
||||
|
||||
#def test_identical_for_names():
|
||||
# """if there is something that
|
||||
# have the same name, an exection is raised
|
||||
# """
|
||||
# descr = make_description_duplicates()
|
||||
# raises(ConflictConfigError, "cfg = Config(descr)")
|
||||
|
||||
|
||||
def make_description2():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
@ -97,8 +90,7 @@ def make_description2():
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
# FIXME: XXX would you mind putting the multi validations anywhere else
|
||||
# than in the requires !!!
|
||||
# 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()
|
||||
@ -213,3 +205,47 @@ def test_disabled_with_group():
|
||||
cfg.int = 1
|
||||
raises(PropertiesOptionError, "cfg.gc.name")
|
||||
assert gcgroup._is_disabled()
|
||||
#____________________________________________________________
|
||||
|
||||
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')
|
||||
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'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
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)
|
||||
config.bool = False
|
||||
# because dummy has a callback
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
settings.freeze()
|
||||
dummy.freeze()
|
||||
raises(TypeError, "config.gc.dummy = True")
|
||||
|
||||
def test_freeze_and_has_callback_with_setoption():
|
||||
descr = make_description_callback()
|
||||
config = Config(descr)
|
||||
config.bool = False
|
||||
settings.freeze()
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
dummy.freeze()
|
||||
raises(TypeError, "config.gc.setoption('dummy', True, 'gen_config')")
|
||||
#____________________________________________________________
|
||||
|
@ -3,31 +3,9 @@ import autopath
|
||||
from py.test import raises
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from tiramisu.setting import settings
|
||||
from tiramisu.setting import settings, owners
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', callback="toto")
|
||||
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'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def make_description2():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
@ -37,35 +15,36 @@ def make_description2():
|
||||
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'])
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
default=False)
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def test_has_callback():
|
||||
descr = make_description()
|
||||
# here the owner is 'default'
|
||||
config = Config(descr)
|
||||
config.bool = False
|
||||
# because dummy has a callback
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
settings.freeze()
|
||||
dummy.freeze()
|
||||
raises(TypeError, "config.gc.dummy = True")
|
||||
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 dm.getowner(cfg) == 'default'
|
||||
dm.setowner(cfg, owners.user)
|
||||
assert dm.getowner(cfg) == owners.user
|
||||
|
||||
#____________________________________________________________
|
||||
def test_freeze_and_has_callback_with_setoption():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.bool = False
|
||||
settings.freeze()
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
dummy.freeze()
|
||||
raises(TypeError, "config.gc.setoption('dummy', True, '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 dm.getowner(cfg) == owners.default
|
||||
assert dm.getowner(cfg) == 'default'
|
||||
assert isinstance(dm.getowner(cfg), owners.Owner)
|
||||
dm.setowner(cfg, owners.user)
|
||||
|
||||
assert dm.getowner(cfg) == 'user'
|
||||
|
@ -51,10 +51,10 @@ def test_reset():
|
||||
config = Config(descr)
|
||||
config.string = "foo"
|
||||
assert config.string == "foo"
|
||||
assert config._cfgimpl_value_owners['string'] == 'user'
|
||||
assert config._cfgimpl_value_owners['string'] == owners.user
|
||||
config.unwrap_from_path("string").reset(config)
|
||||
assert config.string == 'string'
|
||||
assert config._cfgimpl_value_owners['string'] == 'default'
|
||||
assert config._cfgimpl_value_owners['string'] == owners.default
|
||||
|
||||
def test_reset_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string" , multi=True)
|
||||
@ -250,7 +250,7 @@ def test_setoption_from_option():
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
descr = OptionDescription('descr', '', [booloption])
|
||||
cfg = Config(descr)
|
||||
booloption.setoption(cfg, False, 'owner')
|
||||
booloption.setoption(cfg, False)
|
||||
assert cfg.bool == False
|
||||
#____________________________________________________________
|
||||
def test_dwim_set():
|
||||
@ -348,14 +348,11 @@ def test_accepts_multiple_changes_from_option():
|
||||
config.string = "egg"
|
||||
assert s.getdefault() == "string"
|
||||
assert config.string == "egg"
|
||||
s.setoption(config, 'blah', "default")
|
||||
s.setoption(config, 'blah')
|
||||
assert s.getdefault() == "string"
|
||||
assert config.string == "blah"
|
||||
s.setoption(config, 'bol', "user")
|
||||
s.setoption(config, 'bol')
|
||||
assert config.string == 'bol'
|
||||
# config.override({'string': "blurp"})
|
||||
# assert config.string == 'blurp'
|
||||
# assert s.getdefault() == 'blurp'
|
||||
|
||||
def test_allow_multiple_changes_from_config():
|
||||
"""
|
||||
@ -367,28 +364,13 @@ def test_allow_multiple_changes_from_config():
|
||||
suboption = OptionDescription("bip", "", [s2])
|
||||
descr = OptionDescription("options", "", [s, suboption])
|
||||
config = Config(descr)
|
||||
config.setoption("string", 'blah', "user")
|
||||
config.setoption("string", "oh", "user")
|
||||
config.setoption("string", 'blah', owners.user)
|
||||
config.setoption("string", "oh", owners.user)
|
||||
assert config.string == "oh"
|
||||
config.set(string2= 'blah')
|
||||
assert config.bip.string2 == 'blah'
|
||||
# ____________________________________________________________
|
||||
|
||||
#def test_overrides_are_defaults():
|
||||
# descr = OptionDescription("test", "", [
|
||||
# BoolOption("b1", "", default=False),
|
||||
# BoolOption("b2", "", default=False),
|
||||
# ])
|
||||
# # overrides here
|
||||
# config = Config(descr)
|
||||
# config.b2 = True
|
||||
# assert config.b2
|
||||
# # test with a require
|
||||
# config.b1 = True
|
||||
# assert config.b2
|
||||
|
||||
# ____________________________________________________________
|
||||
# accessing a value by the get method
|
||||
# accessing a value by the get method
|
||||
def test_access_by_get():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
|
@ -57,7 +57,13 @@ def test_get_group_type():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
grp = config.unwrap_from_path('creole.general')
|
||||
assert grp.get_group_type() == "family"
|
||||
assert grp.get_group_type() == groups.family
|
||||
assert grp.get_group_type() == 'family'
|
||||
assert isinstance(grp.get_group_type(), groups.GroupName)
|
||||
grp.set_group_type(groups.default)
|
||||
assert isinstance(grp.get_group_type(), groups.DefaultGroupName)
|
||||
assert grp.get_group_type() == groups.default
|
||||
assert grp.get_group_type() == 'default'
|
||||
|
||||
def test_iter_on_groups():
|
||||
descr = make_description()
|
||||
|
Reference in New Issue
Block a user