add force_permissive in config's method (iter_all, iter_group, find, find_first and make_dict)
rename _getattr to getattr
This commit is contained in:
@ -9,7 +9,7 @@ from py.test import raises
|
||||
from tiramisu.config import Config, SubConfig
|
||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, UnicodeOption, OptionDescription
|
||||
from tiramisu.error import ConflictError, ConfigError
|
||||
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError
|
||||
import weakref
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ def make_description():
|
||||
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", properties=('mandatory', ))
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True, properties=('hidden',))
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
@ -90,6 +90,15 @@ def test_base_config_and_groups():
|
||||
#assert nm._name == 'name'
|
||||
|
||||
|
||||
def test_base_config_force_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
raises(PropertiesOptionError, "config.getattr('boolop')")
|
||||
assert config.getattr('boolop', force_permissive=True) is True
|
||||
|
||||
|
||||
def test_base_config_in_a_tree():
|
||||
"how options are organized into a tree, see :ref:`tree`"
|
||||
descr = make_description()
|
||||
|
@ -101,9 +101,12 @@ def test_make_dict():
|
||||
"serialization of the whole config to a dict"
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False)]),
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('hidden',))]),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
d = config.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
config.int = 43
|
||||
@ -113,6 +116,8 @@ def test_make_dict():
|
||||
d2 = config.make_dict(flatten=True)
|
||||
assert d2 == {'a': True, 'int': 43}
|
||||
raises(ValueError, 'd2 = config.make_dict(withvalue="3")')
|
||||
d = config.make_dict(force_permissive=True)
|
||||
assert d == {"s1.a": True, "s1.b": False, "int": 43}
|
||||
|
||||
|
||||
def test_make_dict_with_disabled():
|
||||
@ -132,6 +137,7 @@ def test_find_in_config():
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
conf.read_only()
|
||||
conf.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
assert conf.find(byname='dummy') == [conf.unwrap_from_path('gc.dummy')]
|
||||
assert conf.find(byname='float') == [conf.unwrap_from_path('gc.float'), conf.unwrap_from_path('float')]
|
||||
assert conf.find_first(byname='bool') == conf.unwrap_from_path('gc.gc2.bool')
|
||||
@ -146,6 +152,8 @@ def test_find_in_config():
|
||||
conf.read_write()
|
||||
raises(AttributeError, "assert conf.find(byname='prop')")
|
||||
assert conf.find(byname='prop', check_properties=False) == [conf.unwrap_from_path('gc.gc2.prop'), conf.unwrap_from_path('gc.prop')]
|
||||
assert conf.find(byname='prop', force_permissive=True) == [conf.unwrap_from_path('gc.prop')]
|
||||
assert conf.find_first(byname='prop', force_permissive=True) == conf.unwrap_from_path('gc.prop')
|
||||
#assert conf.find_first(byname='prop') == conf.unwrap_from_path('gc.prop')
|
||||
# combinaison of filters
|
||||
assert conf.find(bytype=BoolOption, byname='dummy') == [conf.unwrap_from_path('gc.dummy')]
|
||||
@ -217,6 +225,20 @@ def test_iter_all():
|
||||
break
|
||||
|
||||
|
||||
def test_iter_all_force_permissive():
|
||||
s = StrOption("string", "", default="string")
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
s3 = StrOption("string3", "", default="string3", properties=('hidden',))
|
||||
descr = OptionDescription("options", "", [s, s2, s3])
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
assert list(config.iter_all(force_permissive=True)) == [('string', 'string'),
|
||||
('string2', 'string2'),
|
||||
('string3', 'string3')]
|
||||
|
||||
|
||||
def test_iter_all_prop():
|
||||
s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
|
@ -162,5 +162,5 @@ def test_force_store_value_hidden():
|
||||
conf.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
conf.read_write()
|
||||
assert conf.getowner(conf.unwrap_from_path('wantref2')) == 'default'
|
||||
conf._getattr('wantref2', force_permissive=True)
|
||||
conf.getattr('wantref2', force_permissive=True)
|
||||
assert conf.getowner(conf.unwrap_from_path('wantref2')) == 'user'
|
||||
|
@ -34,7 +34,9 @@ def make_description():
|
||||
mode_conteneur_actif, adresse_serveur_ntp,
|
||||
time_zone])
|
||||
general.impl_set_group_type(groups.family)
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1])
|
||||
new = OptionDescription('new', '', [], properties=('hidden',))
|
||||
new.impl_set_group_type(groups.family)
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1, new])
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
||||
return descr
|
||||
|
||||
@ -99,6 +101,17 @@ def test_iter_on_groups():
|
||||
break
|
||||
|
||||
|
||||
def test_iter_on_groups_force_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config.read_write()
|
||||
config.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
result = list(config.creole.iter_groups(group_type=groups.family,
|
||||
force_permissive=True))
|
||||
group_names = [res[0] for res in result]
|
||||
assert group_names == ['general', 'interface1', 'new']
|
||||
|
||||
|
||||
def test_iter_on_groups_props():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
|
Reference in New Issue
Block a user