mirror of
https://git.yoctoproject.org/poky
synced 2026-06-02 01:19:52 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
1220faf665
commit
c3625e141d
@@ -5,7 +5,7 @@
|
||||
#
|
||||
|
||||
from oeqa.core.case import OETestCase
|
||||
from oeqa.core.decorator.oetag import OETestTag
|
||||
from oeqa.core.decorator import OETestTag
|
||||
from oeqa.core.decorator.data import OETestDataDepends
|
||||
|
||||
class DataTest(OETestCase):
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
#
|
||||
|
||||
from oeqa.core.case import OETestCase
|
||||
from oeqa.core.decorator.oetag import OETestTag
|
||||
from oeqa.core.decorator import OETestTag
|
||||
|
||||
class TagTest(OETestCase):
|
||||
|
||||
@OETestTag('goodTag')
|
||||
def testTagGood(self):
|
||||
self.assertTrue(True, msg='How is this possible?')
|
||||
@@ -17,5 +16,23 @@ class TagTest(OETestCase):
|
||||
def testTagOther(self):
|
||||
self.assertTrue(True, msg='How is this possible?')
|
||||
|
||||
@OETestTag('otherTag', 'multiTag')
|
||||
def testTagOtherMulti(self):
|
||||
self.assertTrue(True, msg='How is this possible?')
|
||||
|
||||
def testTagNone(self):
|
||||
self.assertTrue(True, msg='How is this possible?')
|
||||
|
||||
@OETestTag('classTag')
|
||||
class TagClassTest(OETestCase):
|
||||
@OETestTag('otherTag')
|
||||
def testTagOther(self):
|
||||
self.assertTrue(True, msg='How is this possible?')
|
||||
|
||||
@OETestTag('otherTag', 'multiTag')
|
||||
def testTagOtherMulti(self):
|
||||
self.assertTrue(True, msg='How is this possible?')
|
||||
|
||||
def testTagNone(self):
|
||||
self.assertTrue(True, msg='How is this possible?')
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ class TestBase(unittest.TestCase):
|
||||
directory = os.path.dirname(os.path.abspath(__file__))
|
||||
self.cases_path = os.path.join(directory, 'cases')
|
||||
|
||||
def _testLoader(self, d={}, modules=[], tests=[], filters={}):
|
||||
def _testLoader(self, d={}, modules=[], tests=[], **kwargs):
|
||||
from oeqa.core.context import OETestContext
|
||||
tc = OETestContext(d, self.logger)
|
||||
tc.loadTests(self.cases_path, modules=modules, tests=tests,
|
||||
filters=filters)
|
||||
**kwargs)
|
||||
return tc
|
||||
|
||||
@@ -14,35 +14,58 @@ setup_sys_path()
|
||||
from oeqa.core.exception import OEQADependency
|
||||
from oeqa.core.utils.test import getCaseMethod, getSuiteCasesNames, getSuiteCasesIDs
|
||||
|
||||
class TestFilterDecorator(TestBase):
|
||||
|
||||
def _runFilterTest(self, modules, filters, expect, msg):
|
||||
tc = self._testLoader(modules=modules, filters=filters)
|
||||
test_loaded = set(getSuiteCasesNames(tc.suites))
|
||||
self.assertEqual(expect, test_loaded, msg=msg)
|
||||
class TestTagDecorator(TestBase):
|
||||
def _runTest(self, modules, filterfn, expect):
|
||||
tc = self._testLoader(modules = modules, tags_filter = filterfn)
|
||||
test_loaded = set(getSuiteCasesIDs(tc.suites))
|
||||
self.assertEqual(expect, test_loaded)
|
||||
|
||||
def test_oetag(self):
|
||||
# Get all cases without filtering.
|
||||
filter_all = {}
|
||||
test_all = {'testTagGood', 'testTagOther', 'testTagNone'}
|
||||
msg_all = 'Failed to get all oetag cases without filtering.'
|
||||
# get all cases without any filtering
|
||||
self._runTest(['oetag'], None, {
|
||||
'oetag.TagTest.testTagGood',
|
||||
'oetag.TagTest.testTagOther',
|
||||
'oetag.TagTest.testTagOtherMulti',
|
||||
'oetag.TagTest.testTagNone',
|
||||
'oetag.TagClassTest.testTagOther',
|
||||
'oetag.TagClassTest.testTagOtherMulti',
|
||||
'oetag.TagClassTest.testTagNone',
|
||||
})
|
||||
|
||||
# Get cases with 'goodTag'.
|
||||
filter_good = {'oetag':'goodTag'}
|
||||
test_good = {'testTagGood'}
|
||||
msg_good = 'Failed to get just one test filtering with "goodTag" oetag.'
|
||||
# exclude any case with tags
|
||||
self._runTest(['oetag'], lambda tags: tags, {
|
||||
'oetag.TagTest.testTagNone',
|
||||
})
|
||||
|
||||
# Get cases with an invalid tag.
|
||||
filter_invalid = {'oetag':'invalidTag'}
|
||||
test_invalid = set()
|
||||
msg_invalid = 'Failed to filter all test using an invalid oetag.'
|
||||
# exclude any case with otherTag
|
||||
self._runTest(['oetag'], lambda tags: "otherTag" in tags, {
|
||||
'oetag.TagTest.testTagGood',
|
||||
'oetag.TagTest.testTagNone',
|
||||
'oetag.TagClassTest.testTagNone',
|
||||
})
|
||||
|
||||
tests = ((filter_all, test_all, msg_all),
|
||||
(filter_good, test_good, msg_good),
|
||||
(filter_invalid, test_invalid, msg_invalid))
|
||||
# exclude any case with classTag
|
||||
self._runTest(['oetag'], lambda tags: "classTag" in tags, {
|
||||
'oetag.TagTest.testTagGood',
|
||||
'oetag.TagTest.testTagOther',
|
||||
'oetag.TagTest.testTagOtherMulti',
|
||||
'oetag.TagTest.testTagNone',
|
||||
})
|
||||
|
||||
for test in tests:
|
||||
self._runFilterTest(['oetag'], test[0], test[1], test[2])
|
||||
# include any case with classTag
|
||||
self._runTest(['oetag'], lambda tags: "classTag" not in tags, {
|
||||
'oetag.TagClassTest.testTagOther',
|
||||
'oetag.TagClassTest.testTagOtherMulti',
|
||||
'oetag.TagClassTest.testTagNone',
|
||||
})
|
||||
|
||||
# include any case with classTag or no tags
|
||||
self._runTest(['oetag'], lambda tags: tags and "classTag" not in tags, {
|
||||
'oetag.TagTest.testTagNone',
|
||||
'oetag.TagClassTest.testTagOther',
|
||||
'oetag.TagClassTest.testTagOtherMulti',
|
||||
'oetag.TagClassTest.testTagNone',
|
||||
})
|
||||
|
||||
class TestDependsDecorator(TestBase):
|
||||
modules = ['depends']
|
||||
|
||||
@@ -15,31 +15,6 @@ from oeqa.core.exception import OEQADependency
|
||||
from oeqa.core.utils.test import getSuiteModules, getSuiteCasesIDs
|
||||
|
||||
class TestLoader(TestBase):
|
||||
|
||||
def test_fail_empty_filter(self):
|
||||
filters = {'oetag' : ''}
|
||||
expect = 'Filter oetag specified is empty'
|
||||
msg = 'Expected TypeError exception for having invalid filter'
|
||||
try:
|
||||
# Must throw TypeError because empty filter
|
||||
tc = self._testLoader(filters=filters)
|
||||
self.fail(msg)
|
||||
except TypeError as e:
|
||||
result = True if expect in str(e) else False
|
||||
self.assertTrue(result, msg=msg)
|
||||
|
||||
def test_fail_invalid_filter(self):
|
||||
filters = {'invalid' : 'good'}
|
||||
expect = 'filter but not declared in any of'
|
||||
msg = 'Expected TypeError exception for having invalid filter'
|
||||
try:
|
||||
# Must throw TypeError because invalid filter
|
||||
tc = self._testLoader(filters=filters)
|
||||
self.fail(msg)
|
||||
except TypeError as e:
|
||||
result = True if expect in str(e) else False
|
||||
self.assertTrue(result, msg=msg)
|
||||
|
||||
@unittest.skip("invalid directory is missing oetag.py")
|
||||
def test_fail_duplicated_module(self):
|
||||
cases_path = self.cases_path
|
||||
|
||||
Reference in New Issue
Block a user