requirements: calculate all requirements for an option
This commit is contained in:
parent
52a6705fbf
commit
4636a977cc
|
@ -88,6 +88,30 @@ def test_multiple_requires():
|
|||
c.ip_address_service
|
||||
|
||||
|
||||
def test_multiple_requires_cumulative():
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
||||
{'option': a, 'expected': 'yes', 'action': 'hidden'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.ip_address_service
|
||||
c.activate_service = 'yes'
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert set(props) == set(['hidden', 'disabled'])
|
||||
|
||||
c.activate_service = 'ok'
|
||||
c.ip_address_service
|
||||
|
||||
c.activate_service = 'no'
|
||||
c.ip_address_service
|
||||
|
||||
|
||||
def test_multiple_requires_inverse():
|
||||
a = StrOption('activate_service', '')
|
||||
b = IPOption('ip_address_service', '',
|
||||
|
|
|
@ -1045,6 +1045,8 @@ def validate_requires_arg(requires, name):
|
|||
ret_requires = {}
|
||||
config_action = {}
|
||||
|
||||
# start parsing all requires given by user (has dict)
|
||||
# transforme it to a tuple
|
||||
for require in requires:
|
||||
if not type(require) == dict:
|
||||
raise ValueError(_("malformed requirements type for option:"
|
||||
|
@ -1058,6 +1060,7 @@ def validate_requires_arg(requires, name):
|
|||
'{2}'.format(name,
|
||||
unknown_keys,
|
||||
valid_keys))
|
||||
# prepare all attributes
|
||||
try:
|
||||
option = require['option']
|
||||
expected = require['expected']
|
||||
|
@ -1106,12 +1109,12 @@ def validate_requires_arg(requires, name):
|
|||
inverse, transitive, same_action)
|
||||
else:
|
||||
ret_requires[action][option][1].append(expected)
|
||||
# transform dict to tuple
|
||||
ret = []
|
||||
for opt_requires in ret_requires.values():
|
||||
ret_action = []
|
||||
for require in opt_requires.values():
|
||||
req = (require[0], tuple(require[1]), require[2], require[3],
|
||||
require[4], require[5])
|
||||
ret_action.append(req)
|
||||
ret_action.append((require[0], tuple(require[1]), require[2],
|
||||
require[3], require[4], require[5]))
|
||||
ret.append(tuple(ret_action))
|
||||
return frozenset(config_action.keys()), tuple(ret)
|
||||
|
|
Loading…
Reference in New Issue