# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# The original `Config` design model is unproudly borrowed from
-# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
+# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from error import (HiddenOptionError, ConfigError, NotFoundError,
if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption:
self._validate(name, getattr(self._cfgimpl_descr, name))
self.setoption(name, value, self._cfgimpl_owner)
-
-# def __setitem__(self, key, value):
-# print "entering __setitem__"
-# if '.' in name:
-# homeconfig, name = self._cfgimpl_get_home_by_path(name)
-# return "hello" #setattr(homeconfig, name, value)
-# return "titi"
-
+
def _validate(self, name, opt_or_descr):
if not type(opt_or_descr) == OptionDescription:
apply_requires(opt_or_descr, self)
if who == 'auto':
if not child._is_hidden():
child.hide()
- if value is None and who != 'default':
- if child.is_multi():
- child.setowner(self, ['default' for i in range(len(child.getdefault()))])
- else:
- child.setowner(self, 'default')
+ if (value is None and who != 'default' and not child.is_multi()):
+ child.setowner(self, 'default')
+ self._cfgimpl_values[name] = child.getdefault()
+ elif (value == [] and who != 'default' and child.is_multi()):
+ child.setowner(self, ['default' for i in range(len(child.getdefault()))])
self._cfgimpl_values[name] = child.getdefault()
else:
child.setowner(self, newowner)
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# The original `Config` design model is unproudly borrowed from
-# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
+# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from autolib import special_owners
if val != None:
# None allows the reset of the value
return self._validate(val)
-
return True
def getdefault(self):
wantframework_option,
intoption, boolop])
return descr
-
#____________________________________________________________
# change with __setattr__
def test_attribute_access():
# let's try to change it again
config.string = "foo"
assert config.string == "foo"
-# raises(ConflictConfigError, 'config.string = "bar"')
+
+def test_setitem():
+ s = StrOption("string", "", default=["string"], multi=True)
+ descr = OptionDescription("options", "", [s])
+ config = Config(descr)
+ config.string = ["foo", "eggs"]
+
def test_reset():
"if value is None, resets to default owner"
assert config.string == 'string'
assert config._cfgimpl_value_owners['string'] == 'default'
+def test_reset_with_multi():
+ s = StrOption("string", "", default=["string"], default_multi="string" , multi=True)
+ descr = OptionDescription("options", "", [s])
+ config = Config(descr)
+ config.string = []
+ assert config.string == ["string"]
+ assert config._cfgimpl_value_owners['string'] == ['default']
+ config.string = ["eggs", "spam", "foo"]
+ assert config._cfgimpl_value_owners['string'] == ['user', 'user', 'user']
+ config.string = []
+ assert config.string == ["string"]
+ assert config._cfgimpl_value_owners['string'] == ['default']
+ raises(ConfigError, "config.string = None")
+
def test_idontexist():
descr = make_description()
cfg = Config(descr)