feat: .identifiers can return convert value
This commit is contained in:
parent
d1add3dc5a
commit
47c84895f7
3 changed files with 42 additions and 1 deletions
|
|
@ -28,6 +28,8 @@ def display_name(kls, subconfig, with_quote=False) -> str:
|
||||||
class ConvertDynOptionDescription(DynOptionDescription):
|
class ConvertDynOptionDescription(DynOptionDescription):
|
||||||
def convert_identifier_to_path(self, identifier):
|
def convert_identifier_to_path(self, identifier):
|
||||||
# remove dot with is illegal
|
# remove dot with is illegal
|
||||||
|
if not identifier:
|
||||||
|
return identifier
|
||||||
return identifier.replace('.', '')
|
return identifier.replace('.', '')
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2140,6 +2142,10 @@ def test_leadership_dyndescription_convert():
|
||||||
assert cfg.option('od.stval2.st1.st1').value.get() == []
|
assert cfg.option('od.stval2.st1.st1').value.get() == []
|
||||||
assert cfg.option('od.stval1.st1.st1').owner.isdefault()
|
assert cfg.option('od.stval1.st1.st1').owner.isdefault()
|
||||||
assert cfg.option('od.stval2.st1.st1').owner.isdefault()
|
assert cfg.option('od.stval2.st1.st1').owner.isdefault()
|
||||||
|
assert cfg.option('od.stval2.st1.st1').identifiers() == ["val.2"]
|
||||||
|
assert cfg.option('od.stval2.st1.st1').identifiers(convert=True) == ["val2"]
|
||||||
|
assert cfg.option('od.stval2').identifiers(only_self=True) == ["val.1", "val.2"]
|
||||||
|
assert cfg.option('od.stval2').identifiers(only_self=True, convert=True) == ["val1", "val2"]
|
||||||
#
|
#
|
||||||
cfg.option('od.stval1.st1.st1').value.set(['yes'])
|
cfg.option('od.stval1.st1.st1').value.set(['yes'])
|
||||||
assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []}
|
assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []}
|
||||||
|
|
@ -2184,6 +2190,23 @@ def test_leadership_dyndescription_convert():
|
||||||
# assert not list_sessions()
|
# assert not list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
def test_leadership_dyndescription_convert_2():
|
||||||
|
identifier = StrOption("identifier", "", ['val.1', 'val.2', None], multi=True)
|
||||||
|
st1 = StrOption('st1', "", multi=True)
|
||||||
|
st2 = StrOption('st2', "", multi=True)
|
||||||
|
stm = Leadership('st1', '', [st1, st2])
|
||||||
|
st = ConvertDynOptionDescription('st', '', [stm], identifiers=Calculation(calc_value, Params((ParamOption(identifier),))))
|
||||||
|
od = OptionDescription('od', '', [st])
|
||||||
|
od1 = OptionDescription('od', '', [od, identifier])
|
||||||
|
cfg = Config(od1)
|
||||||
|
owner = cfg.owner.get()
|
||||||
|
#
|
||||||
|
assert cfg.option('od.stval2.st1.st1').identifiers() == ["val.2"]
|
||||||
|
assert cfg.option('od.stval2.st1.st1').identifiers(convert=True) == ["val2"]
|
||||||
|
assert cfg.option('od.stval2').identifiers(only_self=True) == ["val.1", "val.2"]
|
||||||
|
assert cfg.option('od.stval2').identifiers(only_self=True, convert=True) == ["val1", "val2"]
|
||||||
|
|
||||||
|
|
||||||
def test_leadership_callback_samegroup_dyndescription_convert():
|
def test_leadership_callback_samegroup_dyndescription_convert():
|
||||||
st1 = StrOption('st1', "", multi=True)
|
st1 = StrOption('st1', "", multi=True)
|
||||||
st2 = StrOption('st2', "", multi=True)
|
st2 = StrOption('st2', "", multi=True)
|
||||||
|
|
|
||||||
|
|
@ -569,12 +569,26 @@ class _TiramisuOptionOptionDescription:
|
||||||
self,
|
self,
|
||||||
only_self: bool = False,
|
only_self: bool = False,
|
||||||
uncalculated: bool = False,
|
uncalculated: bool = False,
|
||||||
|
convert: bool = False,
|
||||||
):
|
):
|
||||||
"""Get identifiers for dynamic option"""
|
"""Get identifiers for dynamic option"""
|
||||||
if not only_self:
|
if not only_self:
|
||||||
if self._subconfig.is_dynamic_without_identifiers and not uncalculated:
|
if self._subconfig.is_dynamic_without_identifiers and not uncalculated:
|
||||||
raise AttributeOptionError(self._subconfig.path, "option-dynamic")
|
raise AttributeOptionError(self._subconfig.path, "option-dynamic")
|
||||||
|
if not convert:
|
||||||
return self._subconfig.identifiers
|
return self._subconfig.identifiers
|
||||||
|
identifiers = []
|
||||||
|
dynconfig = None
|
||||||
|
subconfig = self._subconfig
|
||||||
|
while not dynconfig:
|
||||||
|
if subconfig.option.impl_is_optiondescription() and subconfig.option.impl_is_dynoptiondescription():
|
||||||
|
dynconfig = subconfig
|
||||||
|
subconfig = subconfig.parent
|
||||||
|
for identifier in self._subconfig.identifiers:
|
||||||
|
if identifier is None:
|
||||||
|
continue
|
||||||
|
identifiers.append(dynconfig.option.convert_identifier_to_path(identifier))
|
||||||
|
return identifiers
|
||||||
if (
|
if (
|
||||||
not self._subconfig.option.impl_is_optiondescription()
|
not self._subconfig.option.impl_is_optiondescription()
|
||||||
or not self._subconfig.option.impl_is_dynoptiondescription()
|
or not self._subconfig.option.impl_is_dynoptiondescription()
|
||||||
|
|
@ -587,6 +601,7 @@ class _TiramisuOptionOptionDescription:
|
||||||
return self._subconfig.option.get_identifiers(
|
return self._subconfig.option.get_identifiers(
|
||||||
self._subconfig.parent,
|
self._subconfig.parent,
|
||||||
uncalculated=uncalculated,
|
uncalculated=uncalculated,
|
||||||
|
convert=convert,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ class DynOptionDescription(OptionDescription):
|
||||||
*,
|
*,
|
||||||
uncalculated: bool = False,
|
uncalculated: bool = False,
|
||||||
from_display_name: bool = False,
|
from_display_name: bool = False,
|
||||||
|
convert: bool = False,
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
"""get dynamic identifiers"""
|
"""get dynamic identifiers"""
|
||||||
subconfig = parent.get_child(
|
subconfig = parent.get_child(
|
||||||
|
|
@ -150,6 +151,8 @@ class DynOptionDescription(OptionDescription):
|
||||||
cval, self.impl_get_display_name(subconfig, with_quote=True)
|
cval, self.impl_get_display_name(subconfig, with_quote=True)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
elif convert:
|
||||||
|
values_.append(cval)
|
||||||
else:
|
else:
|
||||||
values_.append(val)
|
values_.append(val)
|
||||||
if (
|
if (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue