Last active
May 10, 2017 04:57
-
-
Save milesrout/e0ffc2695fbe2e8bc95bf0cf02b0c89f to your computer and use it in GitHub Desktop.
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
import builtins | |
def testable(f): | |
def run_test(test): | |
print(test.__doc__) | |
args = {name: value for (name, value) in test.__annotations__.items() | |
if name != 'return'} | |
assert f(**args) == test.__annotations__['return'] | |
return test | |
f.test = run_test | |
return f | |
@testable | |
def sum(iterable, start=0): | |
return builtins.sum(iterable, start) | |
@sum.test | |
def test_list(iterable: [1, 2, 3]) -> 6: | |
"The sum of a list should work" | |
@sum.test | |
def test_gen(iterable: range(5)) -> 10: | |
"Ranges are just iterables" | |
@sum.test | |
def test_failure(iterable: range(1000)) -> 505050: | |
"This should fail" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment