zturner created this revision. zturner added reviewers: tfiala, tberghammer, labath. zturner added a subscriber: lldb-commits.
The specific exception types that are thrown internally by unittest2 are considered implementation details and even documented as such in the source code of the library. This patch attempts to make this correct by removing reliance on these implementation details, and deferring to the library implementation. I'm not sure I have a good grasp of how all these decorators are supposed to work, but I think I did this right. Please verify carefully that I didn't mess anything up. The goal of this patch is to make a conditionalExpectedFailure decorator that has the following behavior: 1. If the "condition" is true (i.e. this is an expected failure), reuse the library's `expectedFailure` decorator. 2. If the condition is false (i.e. this is not an expected failure), just call the method. http://reviews.llvm.org/D14406 Files: packages/Python/lldbsuite/test/lldbtest.py Index: packages/Python/lldbsuite/test/lldbtest.py =================================================================== --- packages/Python/lldbsuite/test/lldbtest.py +++ packages/Python/lldbsuite/test/lldbtest.py @@ -601,15 +601,11 @@ def wrapper(*args, **kwargs): from unittest2 import case self = args[0] - try: - func(*args, **kwargs) - except Exception: - if expected_fn(self): - raise case._ExpectedFailure(sys.exc_info(), bugnumber) - else: - raise if expected_fn(self): - raise case._UnexpectedSuccess(sys.exc_info(), bugnumber) + xfail_func = unittest2.expectedFailure(func) + xfail_func(*args, **kwargs) + else: + func(*args, **kwargs) return wrapper # if bugnumber is not-callable(incluing None), that means decorator function is called with optional arguments # return decorator in this case, so it will be used to decorating original method
Index: packages/Python/lldbsuite/test/lldbtest.py =================================================================== --- packages/Python/lldbsuite/test/lldbtest.py +++ packages/Python/lldbsuite/test/lldbtest.py @@ -601,15 +601,11 @@ def wrapper(*args, **kwargs): from unittest2 import case self = args[0] - try: - func(*args, **kwargs) - except Exception: - if expected_fn(self): - raise case._ExpectedFailure(sys.exc_info(), bugnumber) - else: - raise if expected_fn(self): - raise case._UnexpectedSuccess(sys.exc_info(), bugnumber) + xfail_func = unittest2.expectedFailure(func) + xfail_func(*args, **kwargs) + else: + func(*args, **kwargs) return wrapper # if bugnumber is not-callable(incluing None), that means decorator function is called with optional arguments # return decorator in this case, so it will be used to decorating original method
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits