diff --git a/test/test_option_owner.py b/test/test_option_owner.py index 8131c84..0a751be 100644 --- a/test/test_option_owner.py +++ b/test/test_option_owner.py @@ -36,6 +36,17 @@ def test_default_owner(): dm.setowner(cfg, owners.user) assert dm.getowner(cfg) == owners.user +def test_add_owner(): + gcdummy = BoolOption('dummy', 'dummy', default=False) + descr = OptionDescription('tiramisu', '', [gcdummy]) + cfg = Config(descr) + assert cfg.dummy == False + dm = cfg.unwrap_from_path('dummy') + assert dm.getowner(cfg) == 'default' + owners.add_owner("gen_config") + dm.setowner(cfg, owners.gen_config) + assert dm.getowner(cfg) == owners.gen_config + def test_owner_is_not_a_string(): gcdummy = BoolOption('dummy', 'dummy', default=False) descr = OptionDescription('tiramisu', '', [gcdummy]) diff --git a/test/test_parsing_group.py b/test/test_parsing_group.py index 10c7a93..bfb0df8 100644 --- a/test/test_parsing_group.py +++ b/test/test_parsing_group.py @@ -59,9 +59,9 @@ def test_get_group_type(): grp = config.unwrap_from_path('creole.general') assert grp.get_group_type() == groups.family assert grp.get_group_type() == 'family' - assert isinstance(grp.get_group_type(), groups.GroupName) + assert isinstance(grp.get_group_type(), groups.GroupType) grp.set_group_type(groups.default) - assert isinstance(grp.get_group_type(), groups.DefaultGroupName) + assert isinstance(grp.get_group_type(), groups.DefaultGroupType) assert grp.get_group_type() == groups.default assert grp.get_group_type() == 'default' diff --git a/tiramisu/config.py b/tiramisu/config.py index fbfdb69..ff8b9cc 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -329,7 +329,6 @@ class Config(object): if not isinstance(who, owners.Owner): raise TypeError("invalid owner [{0}] for option: {1}".format( str(who), name)) - print "ssdfsdfsdfsdfsdf", type(child) child.setoption(self, value) child.setowner(self, who) else: @@ -458,13 +457,13 @@ class Config(object): """iteration on groups objects only. All groups are returned if `group_type` is `None`, otherwise the groups can be filtered by categories (families, or whatever). - :param group_type: if defined, is an instance of `groups.GroupName` - or `groups.MasterGroupName` that lives in + :param group_type: if defined, is an instance of `groups.GroupType` + or `groups.MasterGroupType` that lives in `settings.groups` """ if group_type is not None: - if not isinstance(group_type, groups.GroupName): + if not isinstance(group_type, groups.GroupType): raise TypeError("Unknown group_type: {0}".format(group_type)) for child in self._cfgimpl_descr._children: if isinstance(child, OptionDescription): diff --git a/tiramisu/option.py b/tiramisu/option.py index 7f78717..989d4ba 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -539,12 +539,12 @@ class OptionDescription(HiddenBaseType, DisabledBaseType): def set_group_type(self, group_type, master=None): """sets a given group object to an OptionDescription - :param group_type: an instance of `GroupName` or `MasterGroupName` + :param group_type: an instance of `GroupType` or `MasterGroupType` that lives in `setting.groups` """ - if isinstance(group_type, groups.GroupName): + if isinstance(group_type, groups.GroupType): self.group_type = group_type - if isinstance(group_type, groups.MasterGroupName): + if isinstance(group_type, groups.MasterGroupType): if master is None: raise ConfigError('this group type ({0}) needs a master ' 'for OptionDescription {1}'.format(group_type, diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 39e84f9..dedf27a 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -37,16 +37,16 @@ class _const: # ____________________________________________________________ class GroupModule(_const): "emulates a module to manage unique group (OptionDescription) names" - class GroupName(str): + class GroupType(str): """allowed normal group (OptionDescription) names *normal* means : groups that are not master """ pass - class DefaultGroupName(GroupName): + class DefaultGroupType(GroupType): """groups that are default (typically 'default')""" pass - class MasterGroupName(GroupName): + class MasterGroupType(GroupType): """allowed normal group (OptionDescription) names *master* means : groups that have the 'master' attribute set """ @@ -62,11 +62,11 @@ def populate_groups(): # populates normal or master groups for grp in _available_group_names: if grp in _available_groups_with_a_master: - setattr(groups, grp, groups.MasterGroupName(grp)) + setattr(groups, grp, groups.MasterGroupType(grp)) elif grp in _available_default_groups: - setattr(groups, grp, groups.DefaultGroupName(grp)) + setattr(groups, grp, groups.DefaultGroupType(grp)) else: - setattr(groups, grp, groups.GroupName(grp)) + setattr(groups, grp, groups.GroupType(grp)) # names are in the module now populate_groups() # ____________________________________________________________ @@ -93,6 +93,13 @@ def populate_owners(): """ setattr(owners, 'default', owners.DefaultOwner('default')) setattr(owners,'user', owners.Owner('user')) + def add_owner(name): + """ + :param name: the name of the new owner + """ + setattr(owners, name, owners.Owner(name)) + setattr(owners, 'add_owner', add_owner) + # names are in the module now populate_owners() #____________________________________________________________