Last active
August 29, 2015 14:08
-
-
Save lykkin/a5cbff5873234cc13104 to your computer and use it in GitHub Desktop.
pre and post condition wrappers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 def pre(f, preds): | |
43 | |
44 @wraps(f) | |
45 def inner(*args, **kwargs): | |
46 for pred in preds: | |
47 assert pred(*args, **kwargs) | |
48 return f(*args, **kwargs) | |
49 | |
50 return inner | |
51 | |
52 | |
53 def post(f, preds): | |
54 | |
55 @wraps(f) | |
56 def inner(*args, **kwargs): | |
57 res = f(*args, **kwargs) | |
58 for pred in preds: | |
59 assert pred(res) | |
60 return res | |
61 | |
62 return inner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment