From d2e790a2e2de48eb5380af3cf485a5757fe99c8d Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 24 Jan 2023 07:46:44 +0100 Subject: [PATCH] information for optiondescription --- tests/test_config.py | 23 +++++++++++++++++++++++ tiramisu/option/baseoption.py | 12 ++++++++++-- tiramisu/option/option.py | 9 --------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index ba8938a..d7164c0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -200,6 +200,29 @@ async def test_information_option(): 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): assert len(val1[0]) == len(val2[0]) for idx1, val_1 in enumerate(val1[0]): diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 496ec3c..2277288 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -221,8 +221,7 @@ class Base: return dico[key] if default is not undefined: return default - raise ValueError(_("information's item not found: {0}").format( - key)) + raise ValueError(_(f'information\'s item for "{self.impl_get_display_name()}" not found: "{key}"')) def impl_set_information(self, key: str, @@ -334,3 +333,12 @@ class BaseOption(Base): def impl_is_symlinkoption(self) -> bool: return False + + def get_dependencies_information(self, + itself=False, + ) -> List[str]: + if itself: + idx = 1 + else: + idx = 0 + return getattr(self, '_dependencies_information', [[], []])[idx] diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 6bc1873..1f791e9 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -207,15 +207,6 @@ class Option(BaseOption): def impl_is_dynsymlinkoption(self) -> bool: 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: # _display_name for compatibility with older version than 3.0rc3 return getattr(self, '_type', self._display_name)