support multi requires with inverse set to True
This commit is contained in:
parent
75f7e7ce5d
commit
e501c6d12d
|
@ -2,7 +2,7 @@
|
||||||
import autopath
|
import autopath
|
||||||
from tiramisu import setting
|
from tiramisu import setting
|
||||||
setting.expires_time = 1
|
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.config import Config
|
||||||
from tiramisu.error import PropertiesOptionError, RequirementError
|
from tiramisu.error import PropertiesOptionError, RequirementError
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
@ -179,3 +179,85 @@ def test_requires_None():
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
c.activate_service = False
|
c.activate_service = False
|
||||||
c.ip_address_service
|
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: "
|
raise AttributeError(_("required option not found: "
|
||||||
"{0}").format(path))
|
"{0}").format(path))
|
||||||
if value == expected:
|
if value == expected:
|
||||||
|
matches = True
|
||||||
if inverse:
|
if inverse:
|
||||||
|
#temporary remove, definitive if no value != expected
|
||||||
|
#matches
|
||||||
setting.remove(action)
|
setting.remove(action)
|
||||||
else:
|
else:
|
||||||
setting.append(action)
|
setting.append(action)
|
||||||
|
## the calculation cannot be carried out
|
||||||
|
break
|
||||||
|
if value != expected:
|
||||||
matches = True
|
matches = True
|
||||||
|
if inverse:
|
||||||
|
setting.append(action)
|
||||||
# the calculation cannot be carried out
|
# the calculation cannot be carried out
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
#temporary remove, definitive if no value != expected
|
||||||
|
#matches
|
||||||
|
setting.remove(action)
|
||||||
# no requirement has been triggered, then just reverse the action
|
# no requirement has been triggered, then just reverse the action
|
||||||
if not matches:
|
if not matches:
|
||||||
if inverse:
|
if inverse:
|
||||||
|
|
Loading…
Reference in New Issue