This revision was automatically updated to reflect the committed changes.
Closed by commit rL255493: Make test categories composable (authored by labath).
Changed prior to commit:
http://reviews.llvm.org/D15451?vs=42522&id=42704#toc
Repository:
rL LLVM
http://reviews.llvm.org/D15451
Files:
lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
lldb/trunk/packages/Python/lldbsuite/test/test_categories.py
lldb/trunk/packages/Python/lldbsuite/test/test_result.py
Index: lldb/trunk/packages/Python/lldbsuite/test/test_result.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/test_result.py
+++ lldb/trunk/packages/Python/lldbsuite/test/test_result.py
@@ -97,22 +97,17 @@
else:
return str(test)
- def getCategoriesForTest(self,test):
- if hasattr(test,"_testMethodName"):
- test_method = getattr(test,"_testMethodName")
- test_method = getattr(test,test_method)
- else:
- test_method = None
- if test_method != None and hasattr(test_method,"getCategories"):
- test_categories = test_method.getCategories(test)
- elif hasattr(test,"getCategories"):
- test_categories = test.getCategories()
- elif inspect.ismethod(test) and test.__self__ != None and
hasattr(test.__self__,"getCategories"):
- test_categories = test.__self__.getCategories()
- else:
- test_categories = []
- if test_categories == None:
- test_categories = []
+ def getCategoriesForTest(self, test):
+ """
+ Gets all the categories for the currently running test method in test
case
+ """
+ test_categories = []
+ test_method = getattr(test, test._testMethodName)
+ if test_method != None and hasattr(test_method, "categories"):
+ test_categories.extend(test_method.categories)
+
+ test_categories.extend(test.getCategories())
+
return test_categories
def hardMarkAsSkipped(self,test):
Index: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
@@ -509,12 +509,18 @@
# Decorators for categorizing test cases.
#
from functools import wraps
+
def add_test_categories(cat):
- """Decorate an item with test categories"""
+ """Add test categories to a TestCase method"""
cat = test_categories.validate(cat, True)
def impl(func):
- func.getCategories = lambda test: cat
+ if isinstance(func, type) and issubclass(func, unittest2.TestCase):
+ raise Exception("@add_test_categories can only be used to decorate
a test method")
+ if hasattr(func, "categories"):
+ cat.extend(func.categories)
+ func.categories = cat
return func
+
return impl
def benchmarks_test(func):
Index: lldb/trunk/packages/Python/lldbsuite/test/test_categories.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/test_categories.py
+++ lldb/trunk/packages/Python/lldbsuite/test/test_categories.py
@@ -3,6 +3,7 @@
"""
from __future__ import absolute_import
+from __future__ import print_function
# System modules
import sys
Index: lldb/trunk/packages/Python/lldbsuite/test/test_result.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/test_result.py
+++ lldb/trunk/packages/Python/lldbsuite/test/test_result.py
@@ -97,22 +97,17 @@
else:
return str(test)
- def getCategoriesForTest(self,test):
- if hasattr(test,"_testMethodName"):
- test_method = getattr(test,"_testMethodName")
- test_method = getattr(test,test_method)
- else:
- test_method = None
- if test_method != None and hasattr(test_method,"getCategories"):
- test_categories = test_method.getCategories(test)
- elif hasattr(test,"getCategories"):
- test_categories = test.getCategories()
- elif inspect.ismethod(test) and test.__self__ != None and hasattr(test.__self__,"getCategories"):
- test_categories = test.__self__.getCategories()
- else:
- test_categories = []
- if test_categories == None:
- test_categories = []
+ def getCategoriesForTest(self, test):
+ """
+ Gets all the categories for the currently running test method in test case
+ """
+ test_categories = []
+ test_method = getattr(test, test._testMethodName)
+ if test_method != None and hasattr(test_method, "categories"):
+ test_categories.extend(test_method.categories)
+
+ test_categories.extend(test.getCategories())
+
return test_categories
def hardMarkAsSkipped(self,test):
Index: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
@@ -509,12 +509,18 @@
# Decorators for categorizing test cases.
#
from functools import wraps
+
def add_test_categories(cat):
- """Decorate an item with test categories"""
+ """Add test categories to a TestCase method"""
cat = test_categories.validate(cat, True)
def impl(func):
- func.getCategories = lambda test: cat
+ if isinstance(func, type) and issubclass(func, unittest2.TestCase):
+ raise Exception("@add_test_categories can only be used to decorate a test method")
+ if hasattr(func, "categories"):
+ cat.extend(func.categories)
+ func.categories = cat
return func
+
return impl
def benchmarks_test(func):
Index: lldb/trunk/packages/Python/lldbsuite/test/test_categories.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/test_categories.py
+++ lldb/trunk/packages/Python/lldbsuite/test/test_categories.py
@@ -3,6 +3,7 @@
"""
from __future__ import absolute_import
+from __future__ import print_function
# System modules
import sys
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits