From 57a27213c913a9d561ce98b8793c1797e18acb75 Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet <nicolas.dumazet@nexedi.com> Date: Thu, 29 Oct 2009 10:55:24 +0000 Subject: [PATCH] * 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 --- product/ERP5Type/tests/runUnitTest.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/product/ERP5Type/tests/runUnitTest.py b/product/ERP5Type/tests/runUnitTest.py index e224457c19..bbb90064cb 100755 --- a/product/ERP5Type/tests/runUnitTest.py +++ b/product/ERP5Type/tests/runUnitTest.py @@ -190,9 +190,10 @@ class FilteredTestSuite(unittest.TestSuite): class ERP5TypeTestLoader(unittest.TestLoader): """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__() - 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): """This method is here for compatibility with old style arguments. @@ -223,8 +224,8 @@ class ERP5TypeTestLoader(unittest.TestLoader): for item in test_list: if isinstance(item, unittest.TestCase): test_method_name = item.id().rsplit('.', 1)[-1] - for valid_test_method_name_re in self.test_patterns_list: - if re.search(valid_test_method_name_re, test_method_name): + for valid_test_method_name_re in self.test_pattern_list: + if valid_test_method_name_re.search(test_method_name): filtered.append(item) elif isinstance(item, FilteredTestSuite): # has already been filtered, dont check it again @@ -240,7 +241,7 @@ class ERP5TypeTestLoader(unittest.TestLoader): def suiteClass(self, test_list): """Constructs a Test Suite from test lists. 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) return FilteredTestSuite(test_list) -- 2.30.9