mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-23 23:03:19 -06:00
74: Finished opt.__rules_iter(); is_rule(obj) now returns False if obj is not callable; updated unit tests
This commit is contained in:
parent
8a6041b797
commit
2cc88a7a32
@ -35,9 +35,7 @@ def rule(obj):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
def is_rule(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):
|
class opt(plugable.ReadOnly):
|
||||||
@ -65,7 +63,12 @@ class opt(plugable.ReadOnly):
|
|||||||
rules = property(__get_rules)
|
rules = property(__get_rules)
|
||||||
|
|
||||||
def __rules_iter(self):
|
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):
|
def validate(self, value):
|
||||||
pass
|
pass
|
||||||
|
@ -47,27 +47,20 @@ def test_is_rule():
|
|||||||
is_rule = public.is_rule
|
is_rule = public.is_rule
|
||||||
flag = public.RULE_FLAG
|
flag = public.RULE_FLAG
|
||||||
|
|
||||||
class example(object):
|
class no_call(object):
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
assert value in (True, False)
|
assert value in (True, False)
|
||||||
setattr(self, flag, value)
|
setattr(self, flag, value)
|
||||||
|
|
||||||
obj = example(True)
|
class call(no_call):
|
||||||
assert getattr(obj, flag) is True
|
def __call__(self):
|
||||||
assert is_rule(obj)
|
pass
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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():
|
class test_opt():
|
||||||
|
Loading…
Reference in New Issue
Block a user