Created
February 28, 2011 22:41
-
-
Save clayg/848200 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
#!/usr/bin/env python | |
import unittest | |
from functools import wraps | |
def something_that_returns_true(): | |
return True | |
def something_else_that_returns_true(): | |
return False | |
def something_that_returns_ture(): | |
# raises NameError! | |
return Ture | |
def something_that_got_fixed(): | |
# return [] | |
# ^ empty list is False! | |
return [None] | |
def expected_failure(exc=None.__class__): | |
def wrap(f): | |
@wraps(f) | |
def wrapper(*args, **kwargs): | |
try: | |
rv = f(*args, **kwargs) | |
except AssertionError, e: | |
return None | |
except Exception, e: | |
if isinstance(e, exc): | |
rv = None | |
else: | |
raise | |
else: | |
raise AssertionError("%s was expected to fail, but did not" % | |
f.__name__) | |
return rv | |
return wrapper | |
return wrap | |
class TestSomething(unittest.TestCase): | |
def test_something_that_works(self): | |
self.assert_(something_that_returns_true()) | |
@expected_failure() | |
def test_something_thats_broken(self): | |
self.assert_(something_else_that_returns_true()) | |
@expected_failure(NameError) | |
def test_something_thats_way_broken(self): | |
self.assert_(something_that_returns_ture()) | |
# commiter of fix needs to remove this decorator | |
@expected_failure() | |
def test_something_that_needs_fixing(self): | |
self.assert_(something_that_got_fixed()) | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment