summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core/loader.py
diff options
context:
space:
mode:
authorNathan Rossi <nathan@nathanrossi.com>2019-09-03 16:56:41 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-09-07 21:56:43 +0100
commitc3625e141dfbb6c8b8bfa3ff05e0e87f215bf606 (patch)
tree5c2e6dbfea3d050d7929234c4a880e923795a066 /meta/lib/oeqa/core/loader.py
parent1220faf6659e404f6aa2c3155eb8840ac361c2b2 (diff)
downloadpoky-c3625e141dfbb6c8b8bfa3ff05e0e87f215bf606.tar.gz
oeqa/core: Rework OETestTag and remove unused OETestFilter
Rework OETestTag so that it does not rely on the existing decorator code base and instead inserts the tags into an attribute on the decorated target (e.g. class/type or method). This allows the use of OETestTag on classes and method. In order to filter tagged tests rework the loaders filtering code, removing the generic-ness (with validation and attributes/etc.) and replace it with a "tags_filter" parameter which is a function that filters a test based on the tags it has. This allows the loader user to filter on tags in more specific ways (e.g. include all untagged tests and any tests tagged with foo). Plumb all this through the context code and testing code. Update the associated tests to pass correctly with the changes. (From OE-Core rev: b8a4a4c2de68110d74607cb9807c9e741ca9441c) Signed-off-by: Nathan Rossi <nathan@nathanrossi.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/core/loader.py')
-rw-r--r--meta/lib/oeqa/core/loader.py61
1 files changed, 17 insertions, 44 deletions
diff --git a/meta/lib/oeqa/core/loader.py b/meta/lib/oeqa/core/loader.py
index 7fea0585c7..0d7970d49e 100644
--- a/meta/lib/oeqa/core/loader.py
+++ b/meta/lib/oeqa/core/loader.py
@@ -16,7 +16,7 @@ from oeqa.core.utils.test import getSuiteModules, getCaseID
16from oeqa.core.exception import OEQATestNotFound 16from oeqa.core.exception import OEQATestNotFound
17from oeqa.core.case import OETestCase 17from oeqa.core.case import OETestCase
18from oeqa.core.decorator import decoratorClasses, OETestDecorator, \ 18from oeqa.core.decorator import decoratorClasses, OETestDecorator, \
19 OETestFilter, OETestDiscover 19 OETestDiscover
20 20
21# When loading tests, the unittest framework stores any exceptions and 21# When loading tests, the unittest framework stores any exceptions and
22# displays them only when the run method is called. 22# displays them only when the run method is called.
@@ -68,7 +68,7 @@ class OETestLoader(unittest.TestLoader):
68 '_top_level_dir'] 68 '_top_level_dir']
69 69
70 def __init__(self, tc, module_paths, modules, tests, modules_required, 70 def __init__(self, tc, module_paths, modules, tests, modules_required,
71 filters, *args, **kwargs): 71 *args, **kwargs):
72 self.tc = tc 72 self.tc = tc
73 73
74 self.modules = _built_modules_dict(modules) 74 self.modules = _built_modules_dict(modules)
@@ -76,13 +76,7 @@ class OETestLoader(unittest.TestLoader):
76 self.tests = tests 76 self.tests = tests
77 self.modules_required = modules_required 77 self.modules_required = modules_required
78 78
79 self.filters = filters 79 self.tags_filter = kwargs.get("tags_filter", None)
80 self.decorator_filters = [d for d in decoratorClasses if \
81 issubclass(d, OETestFilter)]
82 self._validateFilters(self.filters, self.decorator_filters)
83 self.used_filters = [d for d in self.decorator_filters
84 for f in self.filters
85 if f in d.attrs]
86 80
87 if isinstance(module_paths, str): 81 if isinstance(module_paths, str):
88 module_paths = [module_paths] 82 module_paths = [module_paths]
@@ -104,28 +98,6 @@ class OETestLoader(unittest.TestLoader):
104 setattr(testCaseClass, 'td', self.tc.td) 98 setattr(testCaseClass, 'td', self.tc.td)
105 setattr(testCaseClass, 'logger', self.tc.logger) 99 setattr(testCaseClass, 'logger', self.tc.logger)
106 100
107 def _validateFilters(self, filters, decorator_filters):
108 # Validate if filter isn't empty
109 for key,value in filters.items():
110 if not value:
111 raise TypeError("Filter %s specified is empty" % key)
112
113 # Validate unique attributes
114 attr_filters = [attr for clss in decorator_filters \
115 for attr in clss.attrs]
116 dup_attr = [attr for attr in attr_filters
117 if attr_filters.count(attr) > 1]
118 if dup_attr:
119 raise TypeError('Detected duplicated attribute(s) %s in filter'
120 ' decorators' % ' ,'.join(dup_attr))
121
122 # Validate if filter is supported
123 for f in filters:
124 if f not in attr_filters:
125 classes = ', '.join([d.__name__ for d in decorator_filters])
126 raise TypeError('Found "%s" filter but not declared in any of '
127 '%s decorators' % (f, classes))
128
129 def _registerTestCase(self, case): 101 def _registerTestCase(self, case):
130 case_id = case.id() 102 case_id = case.id()
131 self.tc._registry['cases'][case_id] = case 103 self.tc._registry['cases'][case_id] = case
@@ -188,19 +160,20 @@ class OETestLoader(unittest.TestLoader):
188 return True 160 return True
189 161
190 # Decorator filters 162 # Decorator filters
191 if self.filters and isinstance(case, OETestCase): 163 if self.tags_filter is not None and callable(self.tags_filter):
192 filters = self.filters.copy() 164 alltags = set()
193 case_decorators = [cd for cd in case.decorators 165 # pull tags from the case class
194 if cd.__class__ in self.used_filters] 166 if hasattr(case, "__oeqa_testtags"):
195 167 for t in getattr(case, "__oeqa_testtags"):
196 # Iterate over case decorators to check if needs to be filtered. 168 alltags.add(t)
197 for cd in case_decorators: 169 # pull tags from the method itself
198 if cd.filtrate(filters): 170 if hasattr(case, test_name):
199 return True 171 method = getattr(case, test_name)
200 172 if hasattr(method, "__oeqa_testtags"):
201 # Case is missing one or more decorators for all the filters 173 for t in getattr(method, "__oeqa_testtags"):
202 # being used, so filter test case. 174 alltags.add(t)
203 if filters: 175
176 if self.tags_filter(alltags):
204 return True 177 return True
205 178
206 return False 179 return False