Commit 57a27213 authored by Nicolas Dumazet's avatar Nicolas Dumazet

* Compile the regexes once and only once: at initialization.

* rename test_patterns_list in test_pattern_list
* do not create the attribute unless it's meaningful


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30101 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a891dff6
...@@ -190,9 +190,10 @@ class FilteredTestSuite(unittest.TestSuite): ...@@ -190,9 +190,10 @@ class FilteredTestSuite(unittest.TestSuite):
class ERP5TypeTestLoader(unittest.TestLoader): class ERP5TypeTestLoader(unittest.TestLoader):
"""Load test cases from the name passed on the command line. """Load test cases from the name passed on the command line.
""" """
def __init__(self, test_patterns_list=None): def __init__(self, test_pattern_list=None):
super(ERP5TypeTestLoader, self).__init__() super(ERP5TypeTestLoader, self).__init__()
self.test_patterns_list = test_patterns_list if test_pattern_list is not None:
self.test_pattern_list = map(re.compile, test_pattern_list)
def loadTestsFromName(self, name, module=None): def loadTestsFromName(self, name, module=None):
"""This method is here for compatibility with old style arguments. """This method is here for compatibility with old style arguments.
...@@ -223,8 +224,8 @@ class ERP5TypeTestLoader(unittest.TestLoader): ...@@ -223,8 +224,8 @@ class ERP5TypeTestLoader(unittest.TestLoader):
for item in test_list: for item in test_list:
if isinstance(item, unittest.TestCase): if isinstance(item, unittest.TestCase):
test_method_name = item.id().rsplit('.', 1)[-1] test_method_name = item.id().rsplit('.', 1)[-1]
for valid_test_method_name_re in self.test_patterns_list: for valid_test_method_name_re in self.test_pattern_list:
if re.search(valid_test_method_name_re, test_method_name): if valid_test_method_name_re.search(test_method_name):
filtered.append(item) filtered.append(item)
elif isinstance(item, FilteredTestSuite): elif isinstance(item, FilteredTestSuite):
# has already been filtered, dont check it again # has already been filtered, dont check it again
...@@ -240,7 +241,7 @@ class ERP5TypeTestLoader(unittest.TestLoader): ...@@ -240,7 +241,7 @@ class ERP5TypeTestLoader(unittest.TestLoader):
def suiteClass(self, test_list): def suiteClass(self, test_list):
"""Constructs a Test Suite from test lists. """Constructs a Test Suite from test lists.
Keep only tests matching commandline parameter --run_only""" Keep only tests matching commandline parameter --run_only"""
if self.test_patterns_list: if hasattr(self, 'test_pattern_list'):
test_list = self._filterTestList(test_list) test_list = self._filterTestList(test_list)
return FilteredTestSuite(test_list) return FilteredTestSuite(test_list)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment