summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core/tests
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/tests
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/tests')
-rw-r--r--meta/lib/oeqa/core/tests/cases/data.py2
-rw-r--r--meta/lib/oeqa/core/tests/cases/oetag.py21
-rw-r--r--meta/lib/oeqa/core/tests/common.py4
-rwxr-xr-xmeta/lib/oeqa/core/tests/test_decorators.py77
-rwxr-xr-xmeta/lib/oeqa/core/tests/test_loader.py25
5 files changed, 72 insertions, 57 deletions
diff --git a/meta/lib/oeqa/core/tests/cases/data.py b/meta/lib/oeqa/core/tests/cases/data.py
index 0d8de87ae7..61f88547f7 100644
--- a/meta/lib/oeqa/core/tests/cases/data.py
+++ b/meta/lib/oeqa/core/tests/cases/data.py
@@ -5,7 +5,7 @@
5# 5#
6 6
7from oeqa.core.case import OETestCase 7from oeqa.core.case import OETestCase
8from oeqa.core.decorator.oetag import OETestTag 8from oeqa.core.decorator import OETestTag
9from oeqa.core.decorator.data import OETestDataDepends 9from oeqa.core.decorator.data import OETestDataDepends
10 10
11class DataTest(OETestCase): 11class DataTest(OETestCase):
diff --git a/meta/lib/oeqa/core/tests/cases/oetag.py b/meta/lib/oeqa/core/tests/cases/oetag.py
index 4e1d080985..52f97dfda6 100644
--- a/meta/lib/oeqa/core/tests/cases/oetag.py
+++ b/meta/lib/oeqa/core/tests/cases/oetag.py
@@ -5,10 +5,9 @@
5# 5#
6 6
7from oeqa.core.case import OETestCase 7from oeqa.core.case import OETestCase
8from oeqa.core.decorator.oetag import OETestTag 8from oeqa.core.decorator import OETestTag
9 9
10class TagTest(OETestCase): 10class TagTest(OETestCase):
11
12 @OETestTag('goodTag') 11 @OETestTag('goodTag')
13 def testTagGood(self): 12 def testTagGood(self):
14 self.assertTrue(True, msg='How is this possible?') 13 self.assertTrue(True, msg='How is this possible?')
@@ -17,5 +16,23 @@ class TagTest(OETestCase):
17 def testTagOther(self): 16 def testTagOther(self):
18 self.assertTrue(True, msg='How is this possible?') 17 self.assertTrue(True, msg='How is this possible?')
19 18
19 @OETestTag('otherTag', 'multiTag')
20 def testTagOtherMulti(self):
21 self.assertTrue(True, msg='How is this possible?')
22
20 def testTagNone(self): 23 def testTagNone(self):
21 self.assertTrue(True, msg='How is this possible?') 24 self.assertTrue(True, msg='How is this possible?')
25
26@OETestTag('classTag')
27class TagClassTest(OETestCase):
28 @OETestTag('otherTag')
29 def testTagOther(self):
30 self.assertTrue(True, msg='How is this possible?')
31
32 @OETestTag('otherTag', 'multiTag')
33 def testTagOtherMulti(self):
34 self.assertTrue(True, msg='How is this possible?')
35
36 def testTagNone(self):
37 self.assertTrue(True, msg='How is this possible?')
38
diff --git a/meta/lib/oeqa/core/tests/common.py b/meta/lib/oeqa/core/tests/common.py
index 39efd504c0..88cc758ad3 100644
--- a/meta/lib/oeqa/core/tests/common.py
+++ b/meta/lib/oeqa/core/tests/common.py
@@ -30,9 +30,9 @@ class TestBase(unittest.TestCase):
30 directory = os.path.dirname(os.path.abspath(__file__)) 30 directory = os.path.dirname(os.path.abspath(__file__))
31 self.cases_path = os.path.join(directory, 'cases') 31 self.cases_path = os.path.join(directory, 'cases')
32 32
33 def _testLoader(self, d={}, modules=[], tests=[], filters={}): 33 def _testLoader(self, d={}, modules=[], tests=[], **kwargs):
34 from oeqa.core.context import OETestContext 34 from oeqa.core.context import OETestContext
35 tc = OETestContext(d, self.logger) 35 tc = OETestContext(d, self.logger)
36 tc.loadTests(self.cases_path, modules=modules, tests=tests, 36 tc.loadTests(self.cases_path, modules=modules, tests=tests,
37 filters=filters) 37 **kwargs)
38 return tc 38 return tc
diff --git a/meta/lib/oeqa/core/tests/test_decorators.py b/meta/lib/oeqa/core/tests/test_decorators.py
index 499cd66ff3..b798bf7d33 100755
--- a/meta/lib/oeqa/core/tests/test_decorators.py
+++ b/meta/lib/oeqa/core/tests/test_decorators.py
@@ -14,35 +14,58 @@ setup_sys_path()
14from oeqa.core.exception import OEQADependency 14from oeqa.core.exception import OEQADependency
15from oeqa.core.utils.test import getCaseMethod, getSuiteCasesNames, getSuiteCasesIDs 15from oeqa.core.utils.test import getCaseMethod, getSuiteCasesNames, getSuiteCasesIDs
16 16
17class TestFilterDecorator(TestBase): 17class TestTagDecorator(TestBase):
18 18 def _runTest(self, modules, filterfn, expect):
19 def _runFilterTest(self, modules, filters, expect, msg): 19 tc = self._testLoader(modules = modules, tags_filter = filterfn)
20 tc = self._testLoader(modules=modules, filters=filters) 20 test_loaded = set(getSuiteCasesIDs(tc.suites))
21 test_loaded = set(getSuiteCasesNames(tc.suites)) 21 self.assertEqual(expect, test_loaded)
22 self.assertEqual(expect, test_loaded, msg=msg)
23 22
24 def test_oetag(self): 23 def test_oetag(self):
25 # Get all cases without filtering. 24 # get all cases without any filtering
26 filter_all = {} 25 self._runTest(['oetag'], None, {
27 test_all = {'testTagGood', 'testTagOther', 'testTagNone'} 26 'oetag.TagTest.testTagGood',
28 msg_all = 'Failed to get all oetag cases without filtering.' 27 'oetag.TagTest.testTagOther',
29 28 'oetag.TagTest.testTagOtherMulti',
30 # Get cases with 'goodTag'. 29 'oetag.TagTest.testTagNone',
31 filter_good = {'oetag':'goodTag'} 30 'oetag.TagClassTest.testTagOther',
32 test_good = {'testTagGood'} 31 'oetag.TagClassTest.testTagOtherMulti',
33 msg_good = 'Failed to get just one test filtering with "goodTag" oetag.' 32 'oetag.TagClassTest.testTagNone',
34 33 })
35 # Get cases with an invalid tag. 34
36 filter_invalid = {'oetag':'invalidTag'} 35 # exclude any case with tags
37 test_invalid = set() 36 self._runTest(['oetag'], lambda tags: tags, {
38 msg_invalid = 'Failed to filter all test using an invalid oetag.' 37 'oetag.TagTest.testTagNone',
39 38 })
40 tests = ((filter_all, test_all, msg_all), 39
41 (filter_good, test_good, msg_good), 40 # exclude any case with otherTag
42 (filter_invalid, test_invalid, msg_invalid)) 41 self._runTest(['oetag'], lambda tags: "otherTag" in tags, {
43 42 'oetag.TagTest.testTagGood',
44 for test in tests: 43 'oetag.TagTest.testTagNone',
45 self._runFilterTest(['oetag'], test[0], test[1], test[2]) 44 'oetag.TagClassTest.testTagNone',
45 })
46
47 # exclude any case with classTag
48 self._runTest(['oetag'], lambda tags: "classTag" in tags, {
49 'oetag.TagTest.testTagGood',
50 'oetag.TagTest.testTagOther',
51 'oetag.TagTest.testTagOtherMulti',
52 'oetag.TagTest.testTagNone',
53 })
54
55 # include any case with classTag
56 self._runTest(['oetag'], lambda tags: "classTag" not in tags, {
57 'oetag.TagClassTest.testTagOther',
58 'oetag.TagClassTest.testTagOtherMulti',
59 'oetag.TagClassTest.testTagNone',
60 })
61
62 # include any case with classTag or no tags
63 self._runTest(['oetag'], lambda tags: tags and "classTag" not in tags, {
64 'oetag.TagTest.testTagNone',
65 'oetag.TagClassTest.testTagOther',
66 'oetag.TagClassTest.testTagOtherMulti',
67 'oetag.TagClassTest.testTagNone',
68 })
46 69
47class TestDependsDecorator(TestBase): 70class TestDependsDecorator(TestBase):
48 modules = ['depends'] 71 modules = ['depends']
diff --git a/meta/lib/oeqa/core/tests/test_loader.py b/meta/lib/oeqa/core/tests/test_loader.py
index e73c91b141..cb38ac845e 100755
--- a/meta/lib/oeqa/core/tests/test_loader.py
+++ b/meta/lib/oeqa/core/tests/test_loader.py
@@ -15,31 +15,6 @@ from oeqa.core.exception import OEQADependency
15from oeqa.core.utils.test import getSuiteModules, getSuiteCasesIDs 15from oeqa.core.utils.test import getSuiteModules, getSuiteCasesIDs
16 16
17class TestLoader(TestBase): 17class TestLoader(TestBase):
18
19 def test_fail_empty_filter(self):
20 filters = {'oetag' : ''}
21 expect = 'Filter oetag specified is empty'
22 msg = 'Expected TypeError exception for having invalid filter'
23 try:
24 # Must throw TypeError because empty filter
25 tc = self._testLoader(filters=filters)
26 self.fail(msg)
27 except TypeError as e:
28 result = True if expect in str(e) else False
29 self.assertTrue(result, msg=msg)
30
31 def test_fail_invalid_filter(self):
32 filters = {'invalid' : 'good'}
33 expect = 'filter but not declared in any of'
34 msg = 'Expected TypeError exception for having invalid filter'
35 try:
36 # Must throw TypeError because invalid filter
37 tc = self._testLoader(filters=filters)
38 self.fail(msg)
39 except TypeError as e:
40 result = True if expect in str(e) else False
41 self.assertTrue(result, msg=msg)
42
43 @unittest.skip("invalid directory is missing oetag.py") 18 @unittest.skip("invalid directory is missing oetag.py")
44 def test_fail_duplicated_module(self): 19 def test_fail_duplicated_module(self):
45 cases_path = self.cases_path 20 cases_path = self.cases_path