more tests

This commit is contained in:
2014-02-06 22:17:20 +01:00
parent 72f06bc29d
commit e7531e1fda
5 changed files with 93 additions and 48 deletions

View File

@@ -354,9 +354,6 @@ class Option(BaseOption):
"""
if context is not None:
descr = context.cfgimpl_get_description()
#option is also in all_cons_opts
if option not in all_cons_opts:
raise ConfigError(_('option not in all_cons_opts'))
all_cons_vals = []
for opt in all_cons_opts:
@@ -587,31 +584,15 @@ class Option(BaseOption):
consistencies = self._state_consistencies
else:
consistencies = self._consistencies
if isinstance(consistencies, list):
new_value = []
for consistency in consistencies:
values = []
for obj in consistency[1]:
if load:
values.append(descr.impl_get_opt_by_path(obj))
else:
values.append(descr.impl_get_path_by_opt(obj))
new_value.append((consistency[0], tuple(values)))
else:
new_value = {}
for key, _consistencies in consistencies.items():
new_value[key] = []
for key_cons, _cons in _consistencies:
_list_cons = []
for _con in _cons:
if load:
_list_cons.append(
descr.impl_get_opt_by_path(_con))
else:
_list_cons.append(
descr.impl_get_path_by_opt(_con))
new_value[key].append((key_cons, tuple(_list_cons)))
new_value = []
for consistency in consistencies:
values = []
for obj in consistency[1]:
if load:
values.append(descr.impl_get_opt_by_path(obj))
else:
values.append(descr.impl_get_path_by_opt(obj))
new_value.append((consistency[0], tuple(values)))
if load:
del(self._state_consistencies)
self._consistencies = new_value
@@ -932,19 +913,14 @@ class NetmaskOption(Option):
IP('{0}/{1}'.format(val_ipnetwork, val_netmask),
make_net=not make_net)
except ValueError:
if not make_net:
msg = _("invalid network {0} ({1}) "
"with netmask {2},"
" this network is an IP")
pass
else:
if make_net:
msg = _("invalid IP {0} ({1}) with netmask {2},"
" this IP is a network")
except ValueError:
if make_net:
msg = _('invalid IP {0} ({1}) with netmask {2}')
else:
if not make_net:
msg = _('invalid network {0} ({1}) with netmask {2}')
if msg is not None:
raise ValueError(msg.format(val_ipnetwork, opts[1]._name,
@@ -1035,8 +1011,8 @@ class DomainnameOption(Option):
if self._type == 'domainname' and not self._allow_without_dot and \
'.' not in value:
raise ValueError(_("invalid domainname, must have dot"))
if len(value) > 255:
raise ValueError(_("invalid domainname's length (max 255)"))
if len(value) > 255:
raise ValueError(_("invalid domainname's length (max 255)"))
if len(value) < 2:
raise ValueError(_("invalid domainname's length (min 2)"))
if not self._domain_re.search(value):
@@ -1313,13 +1289,10 @@ class OptionDescription(BaseOption):
if consistencies is not None:
for func, all_cons_opts in consistencies:
#all_cons_opts[0] is the option where func is set
ret = all_cons_opts[0]._launch_consistency(func, option,
value,
context, index,
all_cons_opts)
if ret is False:
return False
return True
all_cons_opts[0]._launch_consistency(func, option,
value,
context, index,
all_cons_opts)
def _impl_getstate(self, descr=None):
"""enables us to export into a dict