From 736a1c77b66dbefea993c559949a7858f03c9771 Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 11 Jul 2012 15:31:59 +0200 Subject: [PATCH] add getowner method --- option.py | 5 +++++ test/test_option_setting.py | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/option.py b/option.py index e680389..3493200 100644 --- a/option.py +++ b/option.py @@ -104,6 +104,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType): return self.callback_params def setowner(self, config, owner): + # config *must* be only the **parent** config (not the toplevel config) # owner is a **real* owner, a list is actually allowable here name = self._name if self._frozen: @@ -118,6 +119,10 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType): "option: {0}".format(self._name)) config._cfgimpl_value_owners[name] = owner + def getowner(self, config): + # config *must* be only the **parent** config (not the toplevel config) + return config._cfgimpl_owner[self._name] + def setoption(self, config, value, who): "who is **not necessarily** a owner because it cannot be a list" name = self._name diff --git a/test/test_option_setting.py b/test/test_option_setting.py index de01f74..3c6d2d1 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -37,14 +37,13 @@ def test_attribute_access(): assert config.string == "foo" def test_setitem(): - s = StrOption("string", "", default=["string", None, "sdfsdf"], default_multi="prout", multi=True) + s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True) descr = OptionDescription("options", "", [s]) config = Config(descr) - config._cfgimpl_values['string'].append("eggs") -# config.string = ["string"].append("eggs") - print config.string -# config.string[1] = "titi" - + print config.string[1] + config.string[1] = "titi" + print config.string[1] + def test_reset(): "if value is None, resets to default owner" s = StrOption("string", "", default="string")