apply_requires: add property if any property raise PropertyError if same_action is...
authorEmmanuel Garette <egarette@cadoles.com>
Thu, 13 Jun 2013 12:43:51 +0000 (14:43 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Thu, 13 Jun 2013 12:43:51 +0000 (14:43 +0200)
test/test_requires.py
tiramisu/option.py
tiramisu/setting.py

index 5fdcbdd..cfad1c3 100644 (file)
@@ -25,6 +25,37 @@ def test_requires():
     assert props == ['disabled']
 
 
+def test_requires_same_action():
+    a = BoolOption('activate_service', '', True)
+    b = BoolOption('activate_service_web', '', True,
+                   requires=[(a, False, 'new')])
+
+    d = IPOption('ip_address_service_web', '',
+                 requires=[(b, False, 'disabled', False, True, False)])
+    od = OptionDescription('service', '', [a, b, d])
+    c = Config(od)
+    c.read_write()
+    c.cfgimpl_get_settings().append('new')
+    c.activate_service
+    c.activate_service_web
+    c.ip_address_service_web
+    c.activate_service = False
+    #
+    props = []
+    try:
+        c.activate_service_web
+    except PropertiesOptionError, err:
+        props = err.proptype
+    assert props == ['new']
+    #
+    props = []
+    try:
+        c.ip_address_service_web
+    except PropertiesOptionError, err:
+        props = err.proptype
+    assert props == ['disabled']
+
+
 def test_requires_transitive():
     a = BoolOption('activate_service', '', True)
     b = BoolOption('activate_service_web', '', True,
index f392b07..2185a7d 100644 (file)
@@ -820,7 +820,7 @@ def validate_requires_arg(requires, name):
             if len(req) == 3:
                 action = req[2]
                 inverse = False
-            elif len(req) in [4, 5]:
+            elif len(req) in [4, 5, 6]:
                 action = req[2]
                 inverse = req[3]
             else:
index 52c82bf..ac50e2e 100644 (file)
@@ -356,11 +356,16 @@ def apply_requires(opt, config):
                     option, expected, action = require
                     inverse = False
                     transitive = True
+                    same_action = True
                 elif len(require) == 4:
                     option, expected, action, inverse = require
                     transitive = True
+                    same_action = True
                 elif len(require) == 5:
                     option, expected, action, inverse, transitive = require
+                    same_action = True
+                elif len(require) == 6:
+                    option, expected, action, inverse, transitive, same_action = require
                 path = descr.impl_get_path_by_opt(option)
                 if path == optpath or path.startswith(optpath + '.'):
                     raise RequirementError(_("malformed requirements "
@@ -372,9 +377,9 @@ def apply_requires(opt, config):
                     if not transitive:
                         continue
                     properties = err.proptype
-                    if action not in err.proptype:
+                    if same_action and action not in properties:
                         raise RequirementError(_("option '{0}' has requirement's property error: "
-                                                 "{1} {2}").format(opt._name, path, properties), properties)
+                                                 "{1} {2}").format(opt._name, path, properties))
                     #transitive action, force expected
                     value = expected
                     inverse = False