Created
November 3, 2012 10:00
-
-
Save npryce/4006859 to your computer and use it in GitHub Desktop.
QuickCheck for Python and Py.Test
This file contains 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
def dicts(d): | |
keys, value_iters = zip(*d.items()) | |
return (dict(zip(keys,values)) for values in zip(*value_iters)) | |
def property(test_fn=None, tests=100): | |
def bind_parameters(test_fn): | |
arg_bindings = dicts(test_fn.__annotations__) | |
def bound_test_fn(): | |
for args in itertools.islice(arg_bindings, tests): | |
test_fn(**args) | |
return bound_test_fn | |
# Allow @property or @property(tests=<n>) | |
return bind_parameters if test_fn is None else bind_parameters(test_fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment