support multi requires with inverse set to True
This commit is contained in:
parent
75f7e7ce5d
commit
e501c6d12d
2 changed files with 97 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
|||
import autopath
|
||||
from tiramisu import setting
|
||||
setting.expires_time = 1
|
||||
from tiramisu.option import IPOption, OptionDescription, BoolOption
|
||||
from tiramisu.option import IPOption, OptionDescription, BoolOption, IntOption
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import PropertiesOptionError, RequirementError
|
||||
from py.test import raises
|
||||
|
@ -179,3 +179,85 @@ def test_requires_None():
|
|||
assert props == ['disabled']
|
||||
c.activate_service = False
|
||||
c.ip_address_service
|
||||
|
||||
|
||||
def test_requires_multi_disabled():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[(a, True, 'disabled'), (b, 1, 'disabled')])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
|
||||
c.ip_address_service
|
||||
|
||||
c.activate_service = True
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
c.activate_service = False
|
||||
c.ip_address_service
|
||||
|
||||
c.num_service = 1
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
c.activate_service = True
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
def test_requires_multi_disabled_inverse():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
c = IPOption('ip_address_service', '',
|
||||
requires=[(a, True, 'disabled', True), (b, 1, 'disabled', True)])
|
||||
od = OptionDescription('service', '', [a, b, c])
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
c.activate_service = True
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
c.activate_service = False
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
c.num_service = 1
|
||||
props = []
|
||||
try:
|
||||
c.ip_address_service
|
||||
except PropertiesOptionError, err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
c.activate_service = True
|
||||
c.ip_address_service
|
||||
|
|
|
@ -387,13 +387,25 @@ def apply_requires(opt, config):
|
|||
raise AttributeError(_("required option not found: "
|
||||
"{0}").format(path))
|
||||
if value == expected:
|
||||
matches = True
|
||||
if inverse:
|
||||
#temporary remove, definitive if no value != expected
|
||||
#matches
|
||||
setting.remove(action)
|
||||
else:
|
||||
setting.append(action)
|
||||
## the calculation cannot be carried out
|
||||
break
|
||||
if value != expected:
|
||||
matches = True
|
||||
if inverse:
|
||||
setting.append(action)
|
||||
# the calculation cannot be carried out
|
||||
break
|
||||
else:
|
||||
#temporary remove, definitive if no value != expected
|
||||
#matches
|
||||
setting.remove(action)
|
||||
# no requirement has been triggered, then just reverse the action
|
||||
if not matches:
|
||||
if inverse:
|
||||
|
|
Loading…
Reference in a new issue