test_invariant_as_decorator()
Invaiants can be deined in line
>>> class IRange(interface.Interface):
... min = interface.Attribute("Lower bound")
... max = interface.Attribute("Upper bound")
...
... &
... def range_invariant(ob):
... if ob.max < ob.min:
... raise Invalid('max < min')
>>> class Range(object):
... interface.implements(IRange)
...
... def __init__(self, min, max):
... self.min, self.max = min, max
>>> IRange.validateInvariants(Range(1,2))
>>> IRange.validateInvariants(Range(1,1))
>>> IRange.validateInvariants(Range(2,1))
Traceback (most recent call last):
...
Invalid: max < min
-
|