From e6cbcde927942f2a6e154c91833251bca6856fea Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 13 Sep 2018 08:28:59 +0200 Subject: [PATCH] remove all properties --- test/test_option_setting.py | 10 ++++++++++ tiramisu/api.py | 6 ++++-- tiramisu/setting.py | 13 +++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/test/test_option_setting.py b/test/test_option_setting.py index 10a884f..a5e9e4e 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -421,6 +421,16 @@ def test_reset_properties(): assert api.option('gc.dummy').property.get() == set() +def test_reset_properties_all(): + descr = make_description() + api = Config(descr) + assert api.option('gc.dummy').property.get() == set() + api.option('gc.dummy').property.add('frozen') + assert api.option('gc.dummy').property.get() == {'frozen'} + api.property.reset(all=True) + assert api.option('gc.dummy').property.get() == set() + + def test_properties_cached(): b1 = BoolOption("b1", "", properties=('test',)) descr = OptionDescription("opt", "", [OptionDescription("sub", "", [b1])]) diff --git a/tiramisu/api.py b/tiramisu/api.py index 3ff308c..77c127a 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -835,11 +835,13 @@ class TiramisuContextProperty(TiramisuContext): context) del self.config_bag.properties - def reset(self): + def reset(self, + all=False): """remove configuration properties""" context = self.config_bag.context context.cfgimpl_get_settings().reset(None, - context) + context, + all_properties=all) del self.config_bag.properties def exportation(self): diff --git a/tiramisu/setting.py b/tiramisu/setting.py index af2d3b0..2e62c91 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -657,19 +657,20 @@ class Settings(object): def reset(self, option_bag, - context): + context, + all_properties=False): if option_bag is None: opt = None else: opt = option_bag.option + if all_properties and option_bag: + raise ValueError(_('opt and all_properties must not be set ' + 'together in reset')) if opt and opt.impl_is_symlinkoption(): raise TypeError(_("can't reset properties to the symlinkoption \"{}\"" "").format(opt.impl_get_display_name())) - #if all_properties and (path or opt): - # raise ValueError(_('opt and all_properties must not be set ' - # 'together in reset')) - #if all_properties: - # self._p_.reset_all_properties() + if all_properties: + self._p_.reset_all_properties() else: if opt is not None: path = option_bag.path