[Lldb-commits] [PATCH] D14406: Don't depend on implementation details of unittest2 for our custom decorators

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 5 16:13:14 PST 2015


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14406.39438.patch
Type: text/x-patch
Size: 1095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151106/49019d38/attachment.bin>


More information about the lldb-commits mailing list