summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/public.py11
-rw-r--r--ipalib/tests/test_public.py23
2 files changed, 15 insertions, 19 deletions
diff --git a/ipalib/public.py b/ipalib/public.py
index b43e0af9..baae83e4 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -35,9 +35,7 @@ def rule(obj):
return obj
def is_rule(obj):
- return getattr(obj, RULE_FLAG, False) is True
-
-
+ return callable(obj) and getattr(obj, RULE_FLAG, False) is True
class opt(plugable.ReadOnly):
@@ -65,7 +63,12 @@ class opt(plugable.ReadOnly):
rules = property(__get_rules)
def __rules_iter(self):
- pass
+ for name in dir(self):
+ if name.startswith('_'):
+ continue
+ attr = getattr(self, name)
+ if is_rule(attr):
+ yield attr
def validate(self, value):
pass
diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py
index 122f489d..ef2ded17 100644
--- a/ipalib/tests/test_public.py
+++ b/ipalib/tests/test_public.py
@@ -47,27 +47,20 @@ def test_is_rule():
is_rule = public.is_rule
flag = public.RULE_FLAG
- class example(object):
+ class no_call(object):
def __init__(self, value):
if value is not None:
assert value in (True, False)
setattr(self, flag, value)
- obj = example(True)
- assert getattr(obj, flag) is True
- assert is_rule(obj)
-
- obj = example(False)
- assert getattr(obj, flag) is False
- assert not is_rule(obj)
-
- obj = example(None)
- assert not hasattr(obj, flag)
- assert not is_rule(obj)
-
-
-
+ class call(no_call):
+ def __call__(self):
+ pass
+ assert is_rule(call(True))
+ assert not is_rule(no_call(True))
+ assert not is_rule(call(False))
+ assert not is_rule(call(None))
class test_opt():