information for optiondescription

This commit is contained in:
egarette@silique.fr 2023-01-24 07:46:44 +01:00
parent a16dbb60aa
commit d2e790a2e2
3 changed files with 33 additions and 11 deletions

View file

@ -200,6 +200,29 @@ async def test_information_option():
assert not await list_sessions() assert not await list_sessions()
@pytest.mark.asyncio
async def test_information_optiondescription():
descr = make_description()
async with await Config(descr) as cfg:
string = 'some informations'
#
assert list(await cfg.option('gc').information.list()) == ['doc']
await cfg.option('gc').information.set('info', string)
assert await cfg.option('gc').information.get('info') == string
assert set(await cfg.option('gc').information.list()) == {'doc', 'info'}
#
with pytest.raises(ValueError):
await cfg.option('gc').information.get('noinfo')
assert await cfg.option('gc').information.get('noinfo', 'default') == 'default'
await cfg.option('gc').information.reset('info')
with pytest.raises(ValueError):
await cfg.option('gc').information.get('info')
with pytest.raises(ValueError):
await cfg.option('gc').information.reset('noinfo')
assert list(await cfg.option('gc').information.list()) == ['doc']
assert not await list_sessions()
def compare(val1, val2): def compare(val1, val2):
assert len(val1[0]) == len(val2[0]) assert len(val1[0]) == len(val2[0])
for idx1, val_1 in enumerate(val1[0]): for idx1, val_1 in enumerate(val1[0]):

View file

@ -221,8 +221,7 @@ class Base:
return dico[key] return dico[key]
if default is not undefined: if default is not undefined:
return default return default
raise ValueError(_("information's item not found: {0}").format( raise ValueError(_(f'information\'s item for "{self.impl_get_display_name()}" not found: "{key}"'))
key))
def impl_set_information(self, def impl_set_information(self,
key: str, key: str,
@ -334,3 +333,12 @@ class BaseOption(Base):
def impl_is_symlinkoption(self) -> bool: def impl_is_symlinkoption(self) -> bool:
return False return False
def get_dependencies_information(self,
itself=False,
) -> List[str]:
if itself:
idx = 1
else:
idx = 0
return getattr(self, '_dependencies_information', [[], []])[idx]

View file

@ -207,15 +207,6 @@ class Option(BaseOption):
def impl_is_dynsymlinkoption(self) -> bool: def impl_is_dynsymlinkoption(self) -> bool:
return False return False
def get_dependencies_information(self,
itself=False,
) -> List[str]:
if itself:
idx = 1
else:
idx = 0
return getattr(self, '_dependencies_information', [[], []])[idx]
def get_type(self) -> str: def get_type(self) -> str:
# _display_name for compatibility with older version than 3.0rc3 # _display_name for compatibility with older version than 3.0rc3
return getattr(self, '_type', self._display_name) return getattr(self, '_type', self._display_name)