requirement are now a dictionary (not anymore a tuple)

This commit is contained in:
Emmanuel Garette 2013-06-29 18:41:14 +02:00
parent e501c6d12d
commit 9b134c3aa7
8 changed files with 252 additions and 142 deletions

View File

@ -21,10 +21,10 @@ def make_description_freeze():
stroption = StrOption('str', 'Test string option', default="abc") stroption = StrOption('str', 'Test string option', default="abc")
boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True) boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True)
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',), wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
requires=((booloption, True, 'hidden'),)) requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
wantframework_option = BoolOption('wantframework', 'Test requires', wantframework_option = BoolOption('wantframework', 'Test requires',
default=False, default=False,
requires=((booloption, True, 'hidden'),)) requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption]) gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption, descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,

View File

@ -32,10 +32,10 @@ def make_description():
stroption = StrOption('str', 'Test string option', default="abc") stroption = StrOption('str', 'Test string option', default="abc")
boolop = BoolOption('boolop', 'Test boolean option op', default=True) boolop = BoolOption('boolop', 'Test boolean option op', default=True)
wantref_option = BoolOption('wantref', 'Test requires', default=False, wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=((boolop, True, 'hidden'),)) requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
wantframework_option = BoolOption('wantframework', 'Test requires', wantframework_option = BoolOption('wantframework', 'Test requires',
default=False, default=False,
requires=((boolop, True, 'hidden'),)) requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, intoption2]) gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, intoption2])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption, descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption, wantref_option, stroption,
@ -56,10 +56,10 @@ def make_description_duplicates():
stroption = StrOption('str', 'Test string option', default="abc") stroption = StrOption('str', 'Test string option', default="abc")
boolop = BoolOption('boolop', 'Test boolean option op', default=True) boolop = BoolOption('boolop', 'Test boolean option op', default=True)
wantref_option = BoolOption('wantref', 'Test requires', default=False, wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=((boolop, True, 'hidden'),)) requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
wantframework_option = BoolOption('wantframework', 'Test requires', wantframework_option = BoolOption('wantframework', 'Test requires',
default=False, default=False,
requires=((boolop, True, 'hidden'),)) requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
# dummy2 (same path) # dummy2 (same path)
gcdummy2 = BoolOption('dummy', 'dummy2', default=True) gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
# dummy3 (same name) # dummy3 (same name)
@ -94,11 +94,11 @@ def make_description2():
boolop = BoolOption('boolop', 'Test boolean option op', default=True) boolop = BoolOption('boolop', 'Test boolean option op', default=True)
boolop.enable_multi() boolop.enable_multi()
wantref_option = BoolOption('wantref', 'Test requires', default=False, wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=((boolop, True, 'hidden'),)) requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
# second multi # second multi
wantframework_option = BoolOption('wantframework', 'Test requires', wantframework_option = BoolOption('wantframework', 'Test requires',
default=False, default=False,
requires=((boolop, True, 'hidden'),)) requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
wantframework_option.enable_multi() wantframework_option.enable_multi()
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption]) gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
@ -167,7 +167,7 @@ def make_description_requires():
booloption = BoolOption('bool', 'Test boolean option', default=True) booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc", stroption = StrOption('str', 'Test string option', default="abc",
requires=((intoption, 1, 'hidden'),)) requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption]) gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption, descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
@ -200,7 +200,7 @@ def test_hidden_if_in_with_group():
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc") stroption = StrOption('str', 'Test string option', default="abc")
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption], gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
requires=((intoption, 1, 'hidden'),)) requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
descr = OptionDescription('constraints', '', [gcgroup, booloption, descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption]) objspaceoption, stroption, intoption])
cfg = Config(descr) cfg = Config(descr)
@ -223,7 +223,7 @@ def test_disabled_with_group():
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc") stroption = StrOption('str', 'Test string option', default="abc")
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption], gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
requires=((intoption, 1, 'disabled'),)) requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},))
descr = OptionDescription('constraints', '', [gcgroup, booloption, descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption]) objspaceoption, stroption, intoption])
cfg = Config(descr) cfg = Config(descr)
@ -245,10 +245,10 @@ def make_description_callback():
stroption = StrOption('str', 'Test string option', default="abc") stroption = StrOption('str', 'Test string option', default="abc")
boolop = BoolOption('boolop', 'Test boolean option op', default=True) boolop = BoolOption('boolop', 'Test boolean option op', default=True)
wantref_option = BoolOption('wantref', 'Test requires', default=False, wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=((boolop, True, 'hidden'),)) requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
wantframework_option = BoolOption('wantframework', 'Test requires', wantframework_option = BoolOption('wantframework', 'Test requires',
default=False, default=False,
requires=((boolop, True, 'hidden'),)) requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption]) gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption, descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption, wantref_option, stroption,

View File

@ -131,7 +131,7 @@ def test_multi_with_requires():
s = StrOption("string", "", default=["string"], default_multi="string", multi=True) s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
requires=[(intoption, 1, 'hidden')], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("options", "", [s, intoption, stroption]) descr = OptionDescription("options", "", [s, intoption, stroption])
config = Config(descr) config = Config(descr)
setting = config.cfgimpl_get_settings() setting = config.cfgimpl_get_settings()
@ -146,7 +146,7 @@ def test__requires_with_inverted():
s = StrOption("string", "", default=["string"], multi=True) s = StrOption("string", "", default=["string"], multi=True)
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
requires=[(intoption, 1, 'hide', 'inverted')], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True)
descr = OptionDescription("options", "", [s, intoption, stroption]) descr = OptionDescription("options", "", [s, intoption, stroption])
config = Config(descr) config = Config(descr)
setting = config.cfgimpl_get_settings() setting = config.cfgimpl_get_settings()
@ -160,7 +160,7 @@ def test_multi_with_requires_in_another_group():
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
descr = OptionDescription("options", "", [intoption]) descr = OptionDescription("options", "", [intoption])
stroption = StrOption('str', 'Test string option', default=["abc"], stroption = StrOption('str', 'Test string option', default=["abc"],
requires=[(intoption, 1, 'hidden')], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
config = Config(descr2) config = Config(descr2)
@ -177,7 +177,7 @@ def test_apply_requires_from_config():
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
descr = OptionDescription("options", "", [intoption]) descr = OptionDescription("options", "", [intoption])
stroption = StrOption('str', 'Test string option', default=["abc"], stroption = StrOption('str', 'Test string option', default=["abc"],
requires=[(intoption, 1, 'hidden')], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
config = Config(descr2) config = Config(descr2)
@ -194,7 +194,7 @@ def test_apply_requires_with_disabled():
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
descr = OptionDescription("options", "", [intoption]) descr = OptionDescription("options", "", [intoption])
stroption = StrOption('str', 'Test string option', default=["abc"], stroption = StrOption('str', 'Test string option', default=["abc"],
requires=[(intoption, 1, 'disabled')], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
config = Config(descr2) config = Config(descr2)
@ -211,7 +211,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
descr = OptionDescription("options", "", [intoption]) descr = OptionDescription("options", "", [intoption])
stroption = StrOption('str', 'Test string option', default=["abc"], stroption = StrOption('str', 'Test string option', default=["abc"],
requires=[(intoption, 1, 'disabled')], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
config = Config(descr2) config = Config(descr2)
@ -226,7 +226,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
def test_multi_with_requires_that_is_multi(): def test_multi_with_requires_that_is_multi():
s = StrOption("string", "", default=["string"], multi=True) s = StrOption("string", "", default=["string"], multi=True)
intoption = IntOption('int', 'Test int option', default=[0], multi=True) intoption = IntOption('int', 'Test int option', default=[0], multi=True)
raises(ValueError, "StrOption('str', 'Test string option', default=['abc'], requires=[(intoption, 1, 'hidden')], multi=True)") raises(ValueError, "StrOption('str', 'Test string option', default=['abc'], requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)")
def test_multi_with_bool(): def test_multi_with_bool():

View File

@ -20,10 +20,10 @@ def make_description():
stroption = StrOption('str', 'Test string option', default="abc") stroption = StrOption('str', 'Test string option', default="abc")
wantref_option = BoolOption('wantref', 'Test requires', default=False, wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=((gcoption, 'ref', 'hidden'),)) requires=({'option': gcoption, 'expected': 'ref', 'action': 'hidden'},))
wantframework_option = BoolOption('wantframework', 'Test requires', wantframework_option = BoolOption('wantframework', 'Test requires',
default=False, default=False,
requires=((gcoption, 'framework', 'hidden'),)) requires=({'option': gcoption, 'expected': 'framework', 'action': 'hidden'},))
# ____________________________________________________________ # ____________________________________________________________
booloptiontwo = BoolOption('booltwo', 'Test boolean option two', default=False) booloptiontwo = BoolOption('booltwo', 'Test boolean option two', default=False)

View File

@ -1,5 +1,6 @@
# coding: utf-8 # coding: utf-8
import autopath import autopath
from copy import copy
from tiramisu import setting from tiramisu import setting
setting.expires_time = 1 setting.expires_time = 1
from tiramisu.option import IPOption, OptionDescription, BoolOption, IntOption from tiramisu.option import IPOption, OptionDescription, BoolOption, IntOption
@ -11,7 +12,7 @@ from py.test import raises
def test_requires(): def test_requires():
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[(a, False, 'disabled')]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -28,10 +29,12 @@ def test_requires():
def test_requires_same_action(): def test_requires_same_action():
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'new')]) requires=[{'option': a, 'expected': False, 'action': 'new'}])
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled', False, True, False)]) requires=[{'option': b, 'expected': False,
'action': 'disabled', 'inverse': False,
'transitive': True, 'same_action': False}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -59,10 +62,10 @@ def test_requires_same_action():
def test_requires_transitive(): def test_requires_transitive():
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'disabled')]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled')]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -90,10 +93,10 @@ def test_requires_transitive_bis():
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
abis = BoolOption('activate_service_bis', '', True) abis = BoolOption('activate_service_bis', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[(a, True, 'disabled', True)]) requires=[{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}])
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[(b, True, 'disabled', True)]) requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, abis, b, d]) od = OptionDescription('service', '', [a, abis, b, d])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -120,9 +123,9 @@ def test_requires_transitive_bis():
def test_requires_transitive_hidden_disabled(): def test_requires_transitive_hidden_disabled():
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'hidden')]) requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled')]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -143,9 +146,10 @@ def test_requires_transitive_hidden_disabled():
def test_requires_not_transitive(): def test_requires_not_transitive():
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'disabled')]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled', False, False)]) requires=[{'option': b, 'expected': False,
'action': 'disabled', 'transitive': False}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -167,7 +171,7 @@ def test_requires_not_transitive():
def test_requires_None(): def test_requires_None():
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[(a, None, 'disabled')]) requires=[{'option': a, 'expected': None, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -185,7 +189,8 @@ def test_requires_multi_disabled():
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[(a, True, 'disabled'), (b, 1, 'disabled')]) requires=[{'option': a, 'expected': True, 'action': 'disabled'},
{'option': b, 'expected': 1, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -219,11 +224,15 @@ def test_requires_multi_disabled():
props = err.proptype props = err.proptype
assert props == ['disabled'] assert props == ['disabled']
def test_requires_multi_disabled_inverse(): def test_requires_multi_disabled_inverse():
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[(a, True, 'disabled', True), (b, 1, 'disabled', True)]) requires=[{'option': a, 'expected': True,
'action': 'disabled', 'inverse': True},
{'option': b, 'expected': 1,
'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
@ -261,3 +270,103 @@ def test_requires_multi_disabled_inverse():
c.activate_service = True c.activate_service = True
c.ip_address_service c.ip_address_service
def test_requires_multi_disabled_2():
a = BoolOption('a', '')
b = BoolOption('b', '')
c = BoolOption('c', '')
d = BoolOption('d', '')
e = BoolOption('e', '')
f = BoolOption('f', '')
g = BoolOption('g', '')
h = BoolOption('h', '')
i = BoolOption('i', '')
j = BoolOption('j', '')
k = BoolOption('k', '')
l = BoolOption('l', '')
m = BoolOption('m', '')
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
requires = []
for boo in list_bools:
requires.append({'option': boo, 'expected': True, 'action': 'disabled'})
z = IPOption('z', '', requires=requires)
y = copy(list_bools)
y.append(z)
od = OptionDescription('service', '', y)
cfg = Config(od)
cfg.read_write()
cfg.z
for boo in list_bools:
setattr(cfg, boo._name, True)
props = []
try:
cfg.z
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
for boo in list_bools:
setattr(cfg, boo._name, False)
if boo == m:
cfg.z
else:
props = []
try:
cfg.z
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
def test_requires_multi_disabled_inverse_2():
a = BoolOption('a', '')
b = BoolOption('b', '')
c = BoolOption('c', '')
d = BoolOption('d', '')
e = BoolOption('e', '')
f = BoolOption('f', '')
g = BoolOption('g', '')
h = BoolOption('h', '')
i = BoolOption('i', '')
j = BoolOption('j', '')
k = BoolOption('k', '')
l = BoolOption('l', '')
m = BoolOption('m', '')
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
requires = []
for boo in list_bools:
requires.append({'option': boo, 'expected': True, 'action': 'disabled',
'inverse': True})
z = IPOption('z', '', requires=requires)
y = copy(list_bools)
y.append(z)
od = OptionDescription('service', '', y)
cfg = Config(od)
cfg.read_write()
props = []
try:
cfg.z
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
for boo in list_bools:
setattr(cfg, boo._name, True)
if boo == m:
cfg.z
else:
props = []
try:
cfg.z
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
for boo in list_bools:
setattr(cfg, boo._name, False)
props = []
try:
cfg.z
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']

View File

@ -30,7 +30,9 @@ def test_symlink_option():
def test_symlink_requires(): def test_symlink_requires():
boolopt = BoolOption('b', '', default=True) boolopt = BoolOption('b', '', default=True)
stropt = StrOption('s', '', requires=[(boolopt, False, 'disabled')]) stropt = StrOption('s', '', requires=[{'option': boolopt,
'expected': False,
'action': 'disabled'}])
linkopt = SymLinkOption("c", stropt) linkopt = SymLinkOption("c", stropt)
descr = OptionDescription('opt', '', [boolopt, stropt, linkopt]) descr = OptionDescription('opt', '', [boolopt, stropt, linkopt])
config = Config(descr) config = Config(descr)

View File

@ -125,7 +125,7 @@ class Option(BaseInformation):
self._name = name self._name = name
self._impl_informations = {} self._impl_informations = {}
self.impl_set_information('doc', doc) self.impl_set_information('doc', doc)
validate_requires_arg(requires, self._name) requires = validate_requires_arg(requires, self._name)
self._requires = requires self._requires = requires
self._multi = multi self._multi = multi
self._consistencies = None self._consistencies = None
@ -645,7 +645,7 @@ class OptionDescription(BaseInformation):
'{0}').format(child)) '{0}').format(child))
old = child old = child
self._children = (tuple(child_names), tuple(children)) self._children = (tuple(child_names), tuple(children))
validate_requires_arg(requires, self._name) requires = validate_requires_arg(requires, self._name)
self._requires = requires self._requires = requires
self._cache_paths = None self._cache_paths = None
self._consistencies = None self._consistencies = None
@ -812,35 +812,63 @@ class OptionDescription(BaseInformation):
def validate_requires_arg(requires, name): def validate_requires_arg(requires, name):
"check malformed requirements" """check malformed requirements
if requires is not None: and tranform dict to tuple"""
config_action = {} if requires is None:
for req in requires: return None
if not type(req) == tuple: ret_requires = []
raise ValueError(_("malformed requirements type for option:" config_action = {}
" {0}, must be a tuple").format(name)) for require in requires:
if not isinstance(req[0], Option): if not type(require) == dict:
raise ValueError(_('malformed requirements first argument ' raise ValueError(_("malformed requirements type for option:"
'must be an option in option {0}').format(name)) " {0}, must be a dict").format(name))
if req[0].impl_is_multi(): valid_keys = ('option', 'expected', 'action', 'inverse', 'transitive',
raise ValueError(_('malformed requirements option {0} ' 'same_action')
'should not be a multi').format(name)) unknown_keys = frozenset(require.keys()) - frozenset(valid_keys)
if req[1] is not None and not req[0]._validate(req[1]): if unknown_keys != frozenset():
raise ValueError(_('malformed requirements second argument ' raise ValueError('malformed requirements for option: {0}'
'must be valid for option {0}').format(name)) ' unknown keys {1}, must only '
if len(req) == 3: '{2}'.format(name,
action = req[2] unknown_keys,
inverse = False valid_keys))
elif len(req) in [4, 5, 6]: try:
action = req[2] option = require['option']
inverse = req[3] expected = require['expected']
else: action = require['action']
raise ValueError(_("malformed requirements for option: {0}" except KeyError:
" invalid len").format(name)) raise ValueError(_("malformed requirements for option: {0}"
if action in config_action: " require must have option, expected and"
if inverse != config_action[action]: " action keys").format(name))
raise ValueError(_("inconsistency in action types for option: {0}" inverse = require.get('inverse', False)
" action: {1}").format(name, action)) if inverse not in [True, False]:
else: raise ValueError(_('malformed requirements for option: {0}'
config_action[action] = inverse ' inverse must be boolean'))
return requires transitive = require.get('transitive', True)
if transitive not in [True, False]:
raise ValueError(_('malformed requirements for option: {0}'
' transitive must be boolean'))
same_action = require.get('same_action', True)
if same_action not in [True, False]:
raise ValueError(_('malformed requirements for option: {0}'
' same_action must be boolean'))
if not isinstance(option, Option):
raise ValueError(_('malformed requirements first argument '
'must be an option in option {0}').format(name))
if option.impl_is_multi():
raise ValueError(_('malformed requirements option {0} '
'should not be a multi').format(name))
if expected is not None and not option._validate(expected):
raise ValueError(_('malformed requirements second argument '
'must be valid for option {0}').format(name))
if action in config_action:
if inverse != config_action[action]:
raise ValueError(_("inconsistency in action types for option: {0}"
" action: {1}").format(name, action))
else:
config_action[action] = inverse
ret_requires.append((option, expected, action, inverse, transitive,
same_action))
return tuple(ret_requires)

View File

@ -334,6 +334,9 @@ class Setting(object):
def apply_requires(opt, config): def apply_requires(opt, config):
"carries out the jit (just in time requirements between options" "carries out the jit (just in time requirements between options"
if opt._requires is None:
return
def build_actions(requires): def build_actions(requires):
"action are hide, show, enable, disable..." "action are hide, show, enable, disable..."
trigger_actions = {} trigger_actions = {}
@ -341,74 +344,42 @@ def apply_requires(opt, config):
action = require[2] action = require[2]
trigger_actions.setdefault(action, []).append(require) trigger_actions.setdefault(action, []).append(require)
return trigger_actions return trigger_actions
#for symlink
if hasattr(opt, '_requires') and opt._requires is not None: # filters the callbacks
# filters the callbacks settings = config.cfgimpl_get_settings()
settings = config.cfgimpl_get_settings() setting = Property(settings, settings._get_properties(opt, False), opt)
setting = Property(settings, settings._get_properties(opt, False), opt) trigger_actions = build_actions(opt._requires)
trigger_actions = build_actions(opt._requires) descr = config.cfgimpl_get_context().cfgimpl_get_description()
descr = config.cfgimpl_get_context().cfgimpl_get_description() optpath = descr.impl_get_path_by_opt(opt)
optpath = descr.impl_get_path_by_opt(opt) for requires in trigger_actions.values():
for requires in trigger_actions.values(): matches = False
matches = False for require in requires:
for require in requires: option, expected, action, inverse, transitive, same_action = require
if len(require) == 3: path = descr.impl_get_path_by_opt(option)
option, expected, action = require if path == optpath or path.startswith(optpath + '.'):
inverse = False raise RequirementError(_("malformed requirements "
transitive = True "imbrication detected for option: '{0}' "
same_action = True "with requirement on: '{1}'").format(optpath, path))
elif len(require) == 4: try:
option, expected, action, inverse = require value = config.cfgimpl_get_context()._getattr(path, force_permissive=True)
transitive = True except PropertiesOptionError, err:
same_action = True if not transitive:
elif len(require) == 5: continue
option, expected, action, inverse, transitive = require properties = err.proptype
same_action = True if same_action and action not in properties:
elif len(require) == 6: raise RequirementError(_("option '{0}' has requirement's property error: "
option, expected, action, inverse, transitive, same_action = require "{1} {2}").format(opt._name, path, properties))
path = descr.impl_get_path_by_opt(option) #transitive action, force expected
if path == optpath or path.startswith(optpath + '.'): value = expected
raise RequirementError(_("malformed requirements " inverse = False
"imbrication detected for option: '{0}' " except AttributeError:
"with requirement on: '{1}'").format(optpath, path)) raise AttributeError(_("required option not found: "
try: "{0}").format(path))
value = config.cfgimpl_get_context()._getattr(path, force_permissive=True) if not inverse and value == expected or inverse and value != expected:
except PropertiesOptionError, err: matches = True
if not transitive: setting.append(action)
continue ## the calculation cannot be carried out
properties = err.proptype break
if same_action and action not in properties: # no requirement has been triggered, then just reverse the action
raise RequirementError(_("option '{0}' has requirement's property error: " if not matches:
"{1} {2}").format(opt._name, path, properties)) setting.remove(action)
#transitive action, force expected
value = expected
inverse = False
except AttributeError:
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:
setting.append(action)
else:
setting.remove(action)