support _path for symlinkoption and root OD

This commit is contained in:
Emmanuel Garette 2018-11-17 21:31:35 +01:00
parent 7ae91b0f4e
commit c86cad227e
4 changed files with 24 additions and 4 deletions

View File

@ -273,6 +273,7 @@ def test_symlink_dependency():
assert api.option('s1.b').option.has_dependency(False) is True assert api.option('s1.b').option.has_dependency(False) is True
assert api.option('c').option.has_dependency(False) is False assert api.option('c').option.has_dependency(False) is False
def test_symlink_makedict(): def test_symlink_makedict():
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
@ -282,3 +283,20 @@ def test_symlink_makedict():
assert api.value.dict() == {'c': False, 's1.b': False} assert api.value.dict() == {'c': False, 's1.b': False}
api.option('s1.b').value.set(True) api.option('s1.b').value.set(True)
assert api.value.dict() == {'c': True, 's1.b': True} assert api.value.dict() == {'c': True, 's1.b': True}
def test_symlink_list():
boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr)
list_opt = []
for opt in api.option.list():
list_opt.append(opt.option.path())
assert list_opt == ['c']
#
list_opt = []
for opt in api.option.list(recursive=True):
list_opt.append(opt.option.path())
assert list_opt == ['c', 's1.b']

View File

@ -298,7 +298,8 @@ class Base:
_setattr(self, '_extra', tuple([tuple(extra.keys()), tuple(extra.values())])) _setattr(self, '_extra', tuple([tuple(extra.keys()), tuple(extra.values())]))
def impl_is_readonly(self) -> str: def impl_is_readonly(self) -> str:
return not isinstance(getattr(self, '_informations', dict()), dict) # _path is None when initialise SymlinkOption
return hasattr(self, '_path') and self._path is not None
def impl_getproperties(self) -> FrozenSet[str]: def impl_getproperties(self) -> FrozenSet[str]:
return getattr(self, '_properties', frozenset()) return getattr(self, '_properties', frozenset())

View File

@ -150,9 +150,8 @@ class CacheOptionDescription(BaseOption):
raise ValueError(_('malformed requirements option "{0}" ' raise ValueError(_('malformed requirements option "{0}" '
'must not be a multi for "{1}"').format( 'must not be a multi for "{1}"').format(
require_opt.impl_getname(), option.impl_getname())) require_opt.impl_getname(), option.impl_getname()))
if not hasattr(option, '_path'): option._path = subpath
option._path = subpath option._set_readonly()
option._set_readonly()
if init: if init:
if __debug__ and len(cache_option) != len(set(cache_option)): if __debug__ and len(cache_option) != len(set(cache_option)):
for idx in range(1, len(cache_option) + 1): for idx in range(1, len(cache_option) + 1):
@ -169,6 +168,7 @@ class CacheOptionDescription(BaseOption):
opt.impl_getname())) opt.impl_getname()))
self._cache_consistencies[opt] = tuple(cons) self._cache_consistencies[opt] = tuple(cons)
self._cache_force_store_values = force_store_values self._cache_force_store_values = force_store_values
self._path = subpath
self._set_readonly() self._set_readonly()
def impl_build_force_store_values(self, def impl_build_force_store_values(self,

View File

@ -38,6 +38,7 @@ class SymLinkOption(BaseOption):
_setattr(self, '_name', name) _setattr(self, '_name', name)
_setattr(self, '_opt', opt) _setattr(self, '_opt', opt)
opt._add_dependency(self) opt._add_dependency(self)
self._path = None
def __getattr__(self, def __getattr__(self,
name: str) -> Any: name: str) -> Any: