check if permissive is in global properties before allow permissive for an option
This commit is contained in:
parent
20bef5ff04
commit
0f966f6d26
@ -5,7 +5,7 @@ from tiramisu.setting import owners
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription
|
||||
from tiramisu.error import ConfigError
|
||||
from tiramisu.error import ConfigError, ConstError
|
||||
|
||||
|
||||
def make_description():
|
||||
@ -52,6 +52,17 @@ def test_addowner():
|
||||
assert cfg.getowner(gcdummy) == owners.gen_config
|
||||
|
||||
|
||||
def test_addowner_multiple_time():
|
||||
owners.addowner("testowner")
|
||||
raises(ConstError, 'owners.addowner("testowner")')
|
||||
|
||||
|
||||
def test_delete_owner():
|
||||
owners.addowner('deleted')
|
||||
raises(ConstError, 'del(owners.deleted)')
|
||||
raises(ValueError, 'del(owners.deleted2)')
|
||||
|
||||
|
||||
def test_owner_is_not_a_string():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
|
@ -9,7 +9,8 @@ from tiramisu.error import PropertiesOptionError
|
||||
|
||||
def make_description():
|
||||
u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
|
||||
return OptionDescription('od1', '', [u1])
|
||||
u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', ))
|
||||
return OptionDescription('od1', '', [u1, u2])
|
||||
|
||||
|
||||
def test_permissive():
|
||||
@ -91,3 +92,116 @@ def test_invalid_permissive():
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
raises(TypeError, "setting.setpermissive(['frozen', 'disabled',])")
|
||||
|
||||
|
||||
def test_permissive_option():
|
||||
descr = make_description()
|
||||
u1 = descr.u1
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
|
||||
props = []
|
||||
try:
|
||||
config.u1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
try:
|
||||
config.u2
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
setting.setpermissive(('disabled',), u1)
|
||||
props = []
|
||||
try:
|
||||
config.u1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
try:
|
||||
config.u2
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
setting.append('permissive')
|
||||
config.u1
|
||||
props = []
|
||||
try:
|
||||
config.u2
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
setting.remove('permissive')
|
||||
props = []
|
||||
try:
|
||||
config.u1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
try:
|
||||
config.u2
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
|
||||
def test_permissive_option_mandatory():
|
||||
descr = make_description()
|
||||
u1 = descr.u1
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_only()
|
||||
props = []
|
||||
try:
|
||||
config.u1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['disabled', 'mandatory'])
|
||||
setting.setpermissive(('mandatory', 'disabled',), u1)
|
||||
setting.append('permissive')
|
||||
config.u1
|
||||
setting.remove('permissive')
|
||||
try:
|
||||
config.u1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['disabled', 'mandatory'])
|
||||
|
||||
|
||||
def test_permissive_option_frozen():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
u1 = descr.u1
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
setting.setpermissive(('frozen', 'disabled'), u1)
|
||||
try:
|
||||
config.u1 = 1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['frozen', 'disabled'])
|
||||
setting.append('permissive')
|
||||
config.u1 = 1
|
||||
assert config.u1 == 1
|
||||
setting.remove('permissive')
|
||||
try:
|
||||
config.u1 = 1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['frozen', 'disabled'])
|
||||
|
||||
|
||||
def test_invalid_option_permissive():
|
||||
descr = make_description()
|
||||
u1 = descr.u1
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
raises(TypeError, "setting.setpermissive(['frozen', 'disabled',], u1)")
|
||||
|
@ -243,5 +243,4 @@ def calculate(callback, args, kwargs):
|
||||
:param kwargs: in the callback's arity, the named parameters
|
||||
|
||||
"""
|
||||
print args, kwargs, callback(*args, **kwargs)
|
||||
return callback(*args, **kwargs)
|
||||
|
@ -406,10 +406,11 @@ class Settings(object):
|
||||
"""
|
||||
# opt properties
|
||||
properties = copy(self._getproperties(opt_or_descr, path))
|
||||
# remove opt permissive
|
||||
properties -= self._p_.getpermissive(path)
|
||||
# remove global permissive if need
|
||||
self_properties = copy(self._getproperties())
|
||||
# remove opt permissive
|
||||
if force_permissive is True or 'permissive' in self_properties:
|
||||
properties -= self._p_.getpermissive(path)
|
||||
# remove global permissive if need
|
||||
if force_permissive is True or 'permissive' in self_properties:
|
||||
properties -= self._p_.getpermissive()
|
||||
if force_permissives is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user