None and [] are both possible

This commit is contained in:
gwen 2012-07-10 16:46:30 +02:00
parent a80b868cae
commit bd9d98fcc6
3 changed files with 29 additions and 18 deletions

View File

@ -17,7 +17,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# The original `Config` design model is unproudly borrowed from # 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 # the whole pypy projet is under MIT licence
# ____________________________________________________________ # ____________________________________________________________
from error import (HiddenOptionError, ConfigError, NotFoundError, from error import (HiddenOptionError, ConfigError, NotFoundError,
@ -155,13 +155,6 @@ class Config(object):
self._validate(name, getattr(self._cfgimpl_descr, name)) self._validate(name, getattr(self._cfgimpl_descr, name))
self.setoption(name, value, self._cfgimpl_owner) 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): def _validate(self, name, opt_or_descr):
if not type(opt_or_descr) == OptionDescription: if not type(opt_or_descr) == OptionDescription:
apply_requires(opt_or_descr, self) apply_requires(opt_or_descr, self)
@ -325,11 +318,11 @@ class Config(object):
if who == 'auto': if who == 'auto':
if not child._is_hidden(): if not child._is_hidden():
child.hide() child.hide()
if value is None and who != 'default': if (value is None and who != 'default' and not child.is_multi()):
if child.is_multi(): child.setowner(self, 'default')
child.setowner(self, ['default' for i in range(len(child.getdefault()))]) self._cfgimpl_values[name] = child.getdefault()
else: elif (value == [] and who != 'default' and child.is_multi()):
child.setowner(self, 'default') child.setowner(self, ['default' for i in range(len(child.getdefault()))])
self._cfgimpl_values[name] = child.getdefault() self._cfgimpl_values[name] = child.getdefault()
else: else:
child.setowner(self, newowner) child.setowner(self, newowner)

View File

@ -17,7 +17,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# The original `Config` design model is unproudly borrowed from # 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 # the whole pypy projet is under MIT licence
# ____________________________________________________________ # ____________________________________________________________
from autolib import special_owners from autolib import special_owners
@ -80,7 +80,6 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
if val != None: if val != None:
# None allows the reset of the value # None allows the reset of the value
return self._validate(val) return self._validate(val)
return True return True
def getdefault(self): def getdefault(self):

View File

@ -25,7 +25,6 @@ def make_description():
wantframework_option, wantframework_option,
intoption, boolop]) intoption, boolop])
return descr return descr
#____________________________________________________________ #____________________________________________________________
# change with __setattr__ # change with __setattr__
def test_attribute_access(): def test_attribute_access():
@ -36,7 +35,13 @@ def test_attribute_access():
# let's try to change it again # let's try to change it again
config.string = "foo" config.string = "foo"
assert 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(): def test_reset():
"if value is None, resets to default owner" "if value is None, resets to default owner"
@ -50,6 +55,20 @@ def test_reset():
assert config.string == 'string' assert config.string == 'string'
assert config._cfgimpl_value_owners['string'] == 'default' 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(): def test_idontexist():
descr = make_description() descr = make_description()
cfg = Config(descr) cfg = Config(descr)