From c86cad227e6cff13b2a2a37acb16805ff4a2ea2e Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 17 Nov 2018 21:31:35 +0100 Subject: [PATCH] support _path for symlinkoption and root OD --- test/test_symlink.py | 18 ++++++++++++++++++ tiramisu/option/baseoption.py | 3 ++- tiramisu/option/optiondescription.py | 6 +++--- tiramisu/option/symlinkoption.py | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/test/test_symlink.py b/test/test_symlink.py index d92f0bf..e2b412a 100644 --- a/test/test_symlink.py +++ b/test/test_symlink.py @@ -273,6 +273,7 @@ def test_symlink_dependency(): assert api.option('s1.b').option.has_dependency(False) is True assert api.option('c').option.has_dependency(False) is False + def test_symlink_makedict(): boolopt = BoolOption("b", "", default=False) linkopt = SymLinkOption("c", boolopt) @@ -282,3 +283,20 @@ def test_symlink_makedict(): assert api.value.dict() == {'c': False, 's1.b': False} api.option('s1.b').value.set(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'] diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index c882c58..73e73f7 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -298,7 +298,8 @@ class Base: _setattr(self, '_extra', tuple([tuple(extra.keys()), tuple(extra.values())])) 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]: return getattr(self, '_properties', frozenset()) diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index 244626d..1c0aed5 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -150,9 +150,8 @@ class CacheOptionDescription(BaseOption): raise ValueError(_('malformed requirements option "{0}" ' 'must not be a multi for "{1}"').format( require_opt.impl_getname(), option.impl_getname())) - if not hasattr(option, '_path'): - option._path = subpath - option._set_readonly() + option._path = subpath + option._set_readonly() if init: if __debug__ and len(cache_option) != len(set(cache_option)): for idx in range(1, len(cache_option) + 1): @@ -169,6 +168,7 @@ class CacheOptionDescription(BaseOption): opt.impl_getname())) self._cache_consistencies[opt] = tuple(cons) self._cache_force_store_values = force_store_values + self._path = subpath self._set_readonly() def impl_build_force_store_values(self, diff --git a/tiramisu/option/symlinkoption.py b/tiramisu/option/symlinkoption.py index 8476afa..d26eb96 100644 --- a/tiramisu/option/symlinkoption.py +++ b/tiramisu/option/symlinkoption.py @@ -38,6 +38,7 @@ class SymLinkOption(BaseOption): _setattr(self, '_name', name) _setattr(self, '_opt', opt) opt._add_dependency(self) + self._path = None def __getattr__(self, name: str) -> Any: