labath created this revision.
labath added reviewers: zturner, tfiala, tberghammer.
labath added a subscriber: lldb-commits.
Previously the add_test_categories would simply overwrite the current set of
categories for a
method. This change makes the decorator truly "add" categories, by extending
the current set of
categories instead of replacing it.
To do this, I have:
- replaced the getCategories() property on a method (which was itself a
method), with a simple
list property "categories". This makes add_test_categories easier to
implement, and test
categories isn't something which should change between calls anyway.
- rewritten the getCategoriesForTest function to merge method categories with
the categories of
the test case. Previously, it would just use the method categories if they
were present. I have
also greatly simplified this method. Originally, it would use a lot of
introspection to enable
it being called on various types of objects. Based on my tests, it was only
ever being called
on a test case. The new function uses much less introspection then the
preivous one, so we
should easily catch any stray uses, if there are any, as they will generate
exceptions now.
http://reviews.llvm.org/D15451
Files:
packages/Python/lldbsuite/test/lldbtest.py
packages/Python/lldbsuite/test/test_categories.py
packages/Python/lldbsuite/test/test_result.py
Index: packages/Python/lldbsuite/test/test_result.py
===================================================================
--- packages/Python/lldbsuite/test/test_result.py
+++ packages/Python/lldbsuite/test/test_result.py
@@ -23,7 +23,7 @@
# LLDB Modules
import lldbsuite
-from . import configuration
+from . import configuration, test_categories
from .result_formatter import EventBuilder
@@ -101,32 +101,14 @@
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 = []
- return test_categories
-
def hardMarkAsSkipped(self,test):
getattr(test, test._testMethodName).__func__.__unittest_skip__ = True
getattr(test, test._testMethodName).__func__.__unittest_skip_why__ = "test case does not fall in any category of interest for this run"
test.__class__.__unittest_skip__ = True
test.__class__.__unittest_skip_why__ = "test case does not fall in any category of interest for this run"
def startTest(self, test):
- if configuration.shouldSkipBecauseOfCategories(self.getCategoriesForTest(test)):
+ if configuration.shouldSkipBecauseOfCategories(test_categories.getCategoriesForTest(test)):
self.hardMarkAsSkipped(test)
configuration.setCrashInfoHook("%s at %s" % (str(test),inspect.getfile(test.__class__)))
self.counter += 1
Index: packages/Python/lldbsuite/test/test_categories.py
===================================================================
--- packages/Python/lldbsuite/test/test_categories.py
+++ 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
@@ -53,3 +54,16 @@
sys.exit(1)
result.append(category)
return result
+
+def getCategoriesForTest(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
Index: packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- packages/Python/lldbsuite/test/lldbtest.py
+++ packages/Python/lldbsuite/test/lldbtest.py
@@ -507,12 +507,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 test item"""
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):
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits