Invariant – condition that can be relied upon to be true during execution of a program.
Invariant check condition in the next cases:
- Before class method execution.
- After class method execution.
- After some class attribute setting.
@deal.inv(lambda post: post.likes >= 0) class Post: likes = 0 post = Post() post.likes = 10 post.likes = -10 # InvContractError: type(post) # deal.core.PostInvarianted
Make assertions about object internal state and be sure that it always true.