None and [] are both possible
This commit is contained in:
parent
a80b868cae
commit
bd9d98fcc6
19
config.py
19
config.py
|
@ -17,7 +17,7 @@
|
|||
# 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,
|
||||
|
@ -155,13 +155,6 @@ class Config(object):
|
|||
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)
|
||||
|
@ -325,11 +318,11 @@ class Config(object):
|
|||
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)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# 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
|
||||
|
@ -80,7 +80,6 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
|||
if val != None:
|
||||
# None allows the reset of the value
|
||||
return self._validate(val)
|
||||
|
||||
return True
|
||||
|
||||
def getdefault(self):
|
||||
|
|
|
@ -25,7 +25,6 @@ def make_description():
|
|||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
#____________________________________________________________
|
||||
# change with __setattr__
|
||||
def test_attribute_access():
|
||||
|
@ -36,7 +35,13 @@ 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"
|
||||
|
@ -50,6 +55,20 @@ def test_reset():
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue