oe-selftest: Fixed --list-tests-by tag option

Commit 35be679513 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

(From OE-Core rev: 28c1cffacf341ad64a5b68d8a0176f92b49135c0)

Signed-off-by: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Daniel Istrate 2016-03-18 15:18:09 +02:00 committed by Richard Purdie
parent 068e898001
commit ee4f61b7e1
1 changed files with 19 additions and 10 deletions

View File

@ -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