diff options
author | Daniel Istrate <daniel.alexandrux.istrate@intel.com> | 2016-03-18 15:18:09 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-03-20 22:57:58 +0000 |
commit | 28c1cffacf341ad64a5b68d8a0176f92b49135c0 (patch) | |
tree | 6a680d1d165f40e8fb60058fc722ed03a1194340 /scripts/oe-selftest | |
parent | 9406a8ab8fd166b9d90b33b84b6d44f8672ab623 (diff) | |
download | openembedded-core-contrib-28c1cffacf341ad64a5b68d8a0176f92b49135c0.tar.gz |
oe-selftest: Fixed --list-tests-by tag option
Commit 35be67951305950ba797dc2efddbc7d88fc0556a broke the
--list-tests-by tag option.
This patch fixes that.
Having a module in lib/oeqa/selftest named testmodule:
class TestClass(oeSelfTest):
@tag(feature='tag1')
def test_func1(self):
pass
@tag(feature=('tag1', 'tag2'))
def test_func2(self):
pass
@tag(feature=('tag2', 'tag3'))
def test_func3(self):
pass
@tag(feature=('tag1', 'tag2', 'tag3'))
def test_func4(self):
pass
$ oe-selftest --list-tests-by tag tag1
ID TAG(s) NAME CLASS MODULE
---- ---------------- ---------- --------- --------
tag1 test_func1 TestClass testmodule
tag1, tag2 test_func2 TestClass testmodule
tag1, tag2, tag3 test_func4 TestClass testmodule
______________________________
Filtering by: tag
Looking for: tag1
Total found: 3
$ oe-selftest --list-tests-by tag tag1 tag2
ID TAG(s) NAME CLASS MODULE
---- ---------------- ---------- --------- --------
tag1 test_func1 TestClass testmodule
tag1, tag2 test_func2 TestClass testmodule
tag1, tag2, tag3 test_func4 TestClass testmodule
tag2, tag3 test_func3 TestClass testmodule
______________________________
Filtering by: tag
Looking for: tag1, tag2
Total found: 4
$ oe-selftest --list-tests-by tag tag*
ID TAG(s) NAME CLASS MODULE
---- ---------------- ---------- --------- --------
tag1 test_func1 TestClass testmodule
tag1, tag2 test_func2 TestClass testmodule
tag1, tag2, tag3 test_func4 TestClass testmodule
tag2, tag3 test_func3 TestClass testmodule
______________________________
Filtering by: tag
Looking for: tag*
Total found: 4
Signed-off-by: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Diffstat (limited to 'scripts/oe-selftest')
-rwxr-xr-x | scripts/oe-selftest | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest index 9444244e027..d18348d1c68 100755 --- a/scripts/oe-selftest +++ b/scripts/oe-selftest @@ -32,6 +32,8 @@ import logging import argparse import subprocess import time as t +import re +import fnmatch sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/lib') import scriptpath @@ -197,7 +199,7 @@ class Tc: self.tcclass = tcclass self.tcmodule = tcmodule self.tcid = tcid - # A test case can have multiple tags (as list or as tuples) otherwise str suffice + # A test case can have multiple tags (as tuples) otherwise str will suffice self.tctag = tctag self.fullpath = '.'.join(['oeqa', 'selftest', tcmodule, tcclass, tcname]) @@ -243,19 +245,17 @@ def get_all_tests(): testlist += get_tests_from_module(tmod) return testlist + def get_testsuite_by(criteria, keyword): # Get a testsuite based on 'keyword' # criteria: name, class, module, id, tag # keyword: a list of tests, classes, modules, ids, tags - import re - import fnmatch - ts = [] all_tests = get_all_tests() def get_matches(values): - # Get a items and return the ones that match with keyword(s) + # Get an item and return the ones that match with keyword(s) # values: the list of items (names, modules, classes...) result = [] remaining = values[:] @@ -267,9 +267,9 @@ def get_testsuite_by(criteria, keyword): else: # Wildcard matching pattern = re.compile(fnmatch.translate(r"%s" % key)) - added = [ x for x in remaining if pattern.match(x) ] + added = [x for x in remaining if pattern.match(x)] result.extend(added) - remaining = [ x for x in remaining if not x in added ] + remaining = [x for x in remaining if x not in added] return result @@ -292,14 +292,23 @@ def get_testsuite_by(criteria, keyword): elif criteria == 'tag': values = set() for tc in all_tests: - # tc can have multiple tags (as list or tuple) otherwise as str - if isinstance(tc.tctag, (list, tuple)): + # tc can have multiple tags (as tuple) otherwise str will suffice + if isinstance(tc.tctag, tuple): values |= { str(tag) for tag in tc.tctag } else: values.add(str(tc.tctag)) tags = get_matches(list(values)) - ts = [ tc for tc in all_tests if str(tc.tctag) in tags ] + + for tc in all_tests: + for tag in tags: + if isinstance(tc.tctag, tuple) and tag in tc.tctag: + ts.append(tc) + elif tag == tc.tctag: + ts.append(tc) + + # Remove duplicates from the list + ts = list(set(ts)) return ts |