diff options
author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2016-11-09 11:26:59 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-01-23 12:05:18 +0000 |
commit | 7bf63b28f1dee0b582769879c1727c5a1171c2b1 (patch) | |
tree | 991a4907c63df8c43199fd749546234e0c150839 | |
parent | 4da4091cee20fd425addccd0d267a5b40f1ab8cd (diff) | |
download | poky-7bf63b28f1dee0b582769879c1727c5a1171c2b1.tar.gz |
oeqa/core: Add tests for the OEQA framework
This test suite covers the current functionality for the OEQA
framework.
For run certain test suite,
$ cd meta/lib/oeqa/core/tests
$ ./test_data.py
(From OE-Core rev: 7d7d0dc3736fc12ae7848de2785f0066e6470cd1)
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/core/tests/__init__.py | 0 | ||||
-rw-r--r-- | meta/lib/oeqa/core/tests/cases/data.py | 20 | ||||
-rw-r--r-- | meta/lib/oeqa/core/tests/cases/depends.py | 38 | ||||
-rw-r--r-- | meta/lib/oeqa/core/tests/cases/loader/invalid/oeid.py | 15 | ||||
-rw-r--r-- | meta/lib/oeqa/core/tests/cases/loader/valid/another.py | 9 | ||||
-rw-r--r-- | meta/lib/oeqa/core/tests/cases/oeid.py | 18 | ||||
-rw-r--r-- | meta/lib/oeqa/core/tests/cases/oetag.py | 18 | ||||
-rw-r--r-- | meta/lib/oeqa/core/tests/cases/timeout.py | 18 | ||||
-rw-r--r-- | meta/lib/oeqa/core/tests/common.py | 35 | ||||
-rwxr-xr-x | meta/lib/oeqa/core/tests/test_data.py | 51 | ||||
-rwxr-xr-x | meta/lib/oeqa/core/tests/test_decorators.py | 135 | ||||
-rwxr-xr-x | meta/lib/oeqa/core/tests/test_loader.py | 86 | ||||
-rwxr-xr-x | meta/lib/oeqa/core/tests/test_runner.py | 38 |
13 files changed, 481 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/tests/__init__.py b/meta/lib/oeqa/core/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/meta/lib/oeqa/core/tests/__init__.py | |||
diff --git a/meta/lib/oeqa/core/tests/cases/data.py b/meta/lib/oeqa/core/tests/cases/data.py new file mode 100644 index 0000000000..88003a6adc --- /dev/null +++ b/meta/lib/oeqa/core/tests/cases/data.py | |||
@@ -0,0 +1,20 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.core.case import OETestCase | ||
5 | from oeqa.core.decorator.oetag import OETestTag | ||
6 | from oeqa.core.decorator.data import OETestDataDepends | ||
7 | |||
8 | class DataTest(OETestCase): | ||
9 | data_vars = ['IMAGE', 'ARCH'] | ||
10 | |||
11 | @OETestDataDepends(['MACHINE',]) | ||
12 | @OETestTag('dataTestOk') | ||
13 | def testDataOk(self): | ||
14 | self.assertEqual(self.td.get('IMAGE'), 'core-image-minimal') | ||
15 | self.assertEqual(self.td.get('ARCH'), 'x86') | ||
16 | self.assertEqual(self.td.get('MACHINE'), 'qemuarm') | ||
17 | |||
18 | @OETestTag('dataTestFail') | ||
19 | def testDataFail(self): | ||
20 | pass | ||
diff --git a/meta/lib/oeqa/core/tests/cases/depends.py b/meta/lib/oeqa/core/tests/cases/depends.py new file mode 100644 index 0000000000..17cdd90b15 --- /dev/null +++ b/meta/lib/oeqa/core/tests/cases/depends.py | |||
@@ -0,0 +1,38 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.core.case import OETestCase | ||
5 | from oeqa.core.decorator.depends import OETestDepends | ||
6 | |||
7 | class DependsTest(OETestCase): | ||
8 | |||
9 | def testDependsFirst(self): | ||
10 | self.assertTrue(True, msg='How is this possible?') | ||
11 | |||
12 | @OETestDepends(['testDependsFirst']) | ||
13 | def testDependsSecond(self): | ||
14 | self.assertTrue(True, msg='How is this possible?') | ||
15 | |||
16 | @OETestDepends(['testDependsSecond']) | ||
17 | def testDependsThird(self): | ||
18 | self.assertTrue(True, msg='How is this possible?') | ||
19 | |||
20 | @OETestDepends(['testDependsSecond']) | ||
21 | def testDependsFourth(self): | ||
22 | self.assertTrue(True, msg='How is this possible?') | ||
23 | |||
24 | @OETestDepends(['testDependsThird', 'testDependsFourth']) | ||
25 | def testDependsFifth(self): | ||
26 | self.assertTrue(True, msg='How is this possible?') | ||
27 | |||
28 | @OETestDepends(['testDependsCircular3']) | ||
29 | def testDependsCircular1(self): | ||
30 | self.assertTrue(True, msg='How is this possible?') | ||
31 | |||
32 | @OETestDepends(['testDependsCircular1']) | ||
33 | def testDependsCircular2(self): | ||
34 | self.assertTrue(True, msg='How is this possible?') | ||
35 | |||
36 | @OETestDepends(['testDependsCircular2']) | ||
37 | def testDependsCircular3(self): | ||
38 | self.assertTrue(True, msg='How is this possible?') | ||
diff --git a/meta/lib/oeqa/core/tests/cases/loader/invalid/oeid.py b/meta/lib/oeqa/core/tests/cases/loader/invalid/oeid.py new file mode 100644 index 0000000000..038d445931 --- /dev/null +++ b/meta/lib/oeqa/core/tests/cases/loader/invalid/oeid.py | |||
@@ -0,0 +1,15 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.core.case import OETestCase | ||
5 | |||
6 | class AnotherIDTest(OETestCase): | ||
7 | |||
8 | def testAnotherIdGood(self): | ||
9 | self.assertTrue(True, msg='How is this possible?') | ||
10 | |||
11 | def testAnotherIdOther(self): | ||
12 | self.assertTrue(True, msg='How is this possible?') | ||
13 | |||
14 | def testAnotherIdNone(self): | ||
15 | self.assertTrue(True, msg='How is this possible?') | ||
diff --git a/meta/lib/oeqa/core/tests/cases/loader/valid/another.py b/meta/lib/oeqa/core/tests/cases/loader/valid/another.py new file mode 100644 index 0000000000..c9ffd17773 --- /dev/null +++ b/meta/lib/oeqa/core/tests/cases/loader/valid/another.py | |||
@@ -0,0 +1,9 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.core.case import OETestCase | ||
5 | |||
6 | class AnotherTest(OETestCase): | ||
7 | |||
8 | def testAnother(self): | ||
9 | self.assertTrue(True, msg='How is this possible?') | ||
diff --git a/meta/lib/oeqa/core/tests/cases/oeid.py b/meta/lib/oeqa/core/tests/cases/oeid.py new file mode 100644 index 0000000000..c2d3d32f2d --- /dev/null +++ b/meta/lib/oeqa/core/tests/cases/oeid.py | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.core.case import OETestCase | ||
5 | from oeqa.core.decorator.oeid import OETestID | ||
6 | |||
7 | class IDTest(OETestCase): | ||
8 | |||
9 | @OETestID(101) | ||
10 | def testIdGood(self): | ||
11 | self.assertTrue(True, msg='How is this possible?') | ||
12 | |||
13 | @OETestID(102) | ||
14 | def testIdOther(self): | ||
15 | self.assertTrue(True, msg='How is this possible?') | ||
16 | |||
17 | def testIdNone(self): | ||
18 | self.assertTrue(True, msg='How is this possible?') | ||
diff --git a/meta/lib/oeqa/core/tests/cases/oetag.py b/meta/lib/oeqa/core/tests/cases/oetag.py new file mode 100644 index 0000000000..0cae02e75c --- /dev/null +++ b/meta/lib/oeqa/core/tests/cases/oetag.py | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.core.case import OETestCase | ||
5 | from oeqa.core.decorator.oetag import OETestTag | ||
6 | |||
7 | class TagTest(OETestCase): | ||
8 | |||
9 | @OETestTag('goodTag') | ||
10 | def testTagGood(self): | ||
11 | self.assertTrue(True, msg='How is this possible?') | ||
12 | |||
13 | @OETestTag('otherTag') | ||
14 | def testTagOther(self): | ||
15 | self.assertTrue(True, msg='How is this possible?') | ||
16 | |||
17 | def testTagNone(self): | ||
18 | self.assertTrue(True, msg='How is this possible?') | ||
diff --git a/meta/lib/oeqa/core/tests/cases/timeout.py b/meta/lib/oeqa/core/tests/cases/timeout.py new file mode 100644 index 0000000000..870c3157f7 --- /dev/null +++ b/meta/lib/oeqa/core/tests/cases/timeout.py | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from time import sleep | ||
5 | |||
6 | from oeqa.core.case import OETestCase | ||
7 | from oeqa.core.decorator.oetimeout import OETimeout | ||
8 | |||
9 | class TimeoutTest(OETestCase): | ||
10 | |||
11 | @OETimeout(1) | ||
12 | def testTimeoutPass(self): | ||
13 | self.assertTrue(True, msg='How is this possible?') | ||
14 | |||
15 | @OETimeout(1) | ||
16 | def testTimeoutFail(self): | ||
17 | sleep(2) | ||
18 | self.assertTrue(True, msg='How is this possible?') | ||
diff --git a/meta/lib/oeqa/core/tests/common.py b/meta/lib/oeqa/core/tests/common.py new file mode 100644 index 0000000000..52b18a1c3e --- /dev/null +++ b/meta/lib/oeqa/core/tests/common.py | |||
@@ -0,0 +1,35 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | import sys | ||
5 | import os | ||
6 | |||
7 | import unittest | ||
8 | import logging | ||
9 | import os | ||
10 | |||
11 | logger = logging.getLogger("oeqa") | ||
12 | logger.setLevel(logging.INFO) | ||
13 | consoleHandler = logging.StreamHandler() | ||
14 | formatter = logging.Formatter('OEQATest: %(message)s') | ||
15 | consoleHandler.setFormatter(formatter) | ||
16 | logger.addHandler(consoleHandler) | ||
17 | |||
18 | def setup_sys_path(): | ||
19 | directory = os.path.dirname(os.path.abspath(__file__)) | ||
20 | oeqa_lib = os.path.realpath(os.path.join(directory, '../../../')) | ||
21 | if not oeqa_lib in sys.path: | ||
22 | sys.path.insert(0, oeqa_lib) | ||
23 | |||
24 | class TestBase(unittest.TestCase): | ||
25 | def setUp(self): | ||
26 | self.logger = logger | ||
27 | directory = os.path.dirname(os.path.abspath(__file__)) | ||
28 | self.cases_path = os.path.join(directory, 'cases') | ||
29 | |||
30 | def _testLoader(self, d={}, modules=[], tests=[], filters={}): | ||
31 | from oeqa.core.context import OETestContext | ||
32 | tc = OETestContext(d, self.logger) | ||
33 | tc.loadTests(self.cases_path, modules=modules, tests=tests, | ||
34 | filters=filters) | ||
35 | return tc | ||
diff --git a/meta/lib/oeqa/core/tests/test_data.py b/meta/lib/oeqa/core/tests/test_data.py new file mode 100755 index 0000000000..320468cbe4 --- /dev/null +++ b/meta/lib/oeqa/core/tests/test_data.py | |||
@@ -0,0 +1,51 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | # Copyright (C) 2016 Intel Corporation | ||
4 | # Released under the MIT license (see COPYING.MIT) | ||
5 | |||
6 | import unittest | ||
7 | import logging | ||
8 | import os | ||
9 | |||
10 | from common import setup_sys_path, TestBase | ||
11 | setup_sys_path() | ||
12 | |||
13 | from oeqa.core.exception import OEQAMissingVariable | ||
14 | from oeqa.core.utils.test import getCaseMethod, getSuiteCasesNames | ||
15 | |||
16 | class TestData(TestBase): | ||
17 | modules = ['data'] | ||
18 | |||
19 | def test_data_fail_missing_variable(self): | ||
20 | expectedException = "oeqa.core.exception.OEQAMissingVariable" | ||
21 | |||
22 | tc = self._testLoader(modules=self.modules) | ||
23 | self.assertEqual(False, tc.runTests().wasSuccessful()) | ||
24 | for test, data in tc._results['errors']: | ||
25 | expect = False | ||
26 | if expectedException in data: | ||
27 | expect = True | ||
28 | |||
29 | self.assertTrue(expect) | ||
30 | |||
31 | def test_data_fail_wrong_variable(self): | ||
32 | expectedError = 'AssertionError' | ||
33 | d = {'IMAGE' : 'core-image-sato', 'ARCH' : 'arm'} | ||
34 | |||
35 | tc = self._testLoader(d=d, modules=self.modules) | ||
36 | self.assertEqual(False, tc.runTests().wasSuccessful()) | ||
37 | for test, data in tc._results['failures']: | ||
38 | expect = False | ||
39 | if expectedError in data: | ||
40 | expect = True | ||
41 | |||
42 | self.assertTrue(expect) | ||
43 | |||
44 | def test_data_ok(self): | ||
45 | d = {'IMAGE' : 'core-image-minimal', 'ARCH' : 'x86', 'MACHINE' : 'qemuarm'} | ||
46 | |||
47 | tc = self._testLoader(d=d, modules=self.modules) | ||
48 | self.assertEqual(True, tc.runTests().wasSuccessful()) | ||
49 | |||
50 | if __name__ == '__main__': | ||
51 | unittest.main() | ||
diff --git a/meta/lib/oeqa/core/tests/test_decorators.py b/meta/lib/oeqa/core/tests/test_decorators.py new file mode 100755 index 0000000000..f7d11e885a --- /dev/null +++ b/meta/lib/oeqa/core/tests/test_decorators.py | |||
@@ -0,0 +1,135 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | # Copyright (C) 2016 Intel Corporation | ||
4 | # Released under the MIT license (see COPYING.MIT) | ||
5 | |||
6 | import signal | ||
7 | import unittest | ||
8 | |||
9 | from common import setup_sys_path, TestBase | ||
10 | setup_sys_path() | ||
11 | |||
12 | from oeqa.core.exception import OEQADependency | ||
13 | from oeqa.core.utils.test import getCaseMethod, getSuiteCasesNames, getSuiteCasesIDs | ||
14 | |||
15 | class TestFilterDecorator(TestBase): | ||
16 | |||
17 | def _runFilterTest(self, modules, filters, expect, msg): | ||
18 | tc = self._testLoader(modules=modules, filters=filters) | ||
19 | test_loaded = set(getSuiteCasesNames(tc.suites)) | ||
20 | self.assertEqual(expect, test_loaded, msg=msg) | ||
21 | |||
22 | def test_oetag(self): | ||
23 | # Get all cases without filtering. | ||
24 | filter_all = {} | ||
25 | test_all = {'testTagGood', 'testTagOther', 'testTagNone'} | ||
26 | msg_all = 'Failed to get all oetag cases without filtering.' | ||
27 | |||
28 | # Get cases with 'goodTag'. | ||
29 | filter_good = {'oetag':'goodTag'} | ||
30 | test_good = {'testTagGood'} | ||
31 | msg_good = 'Failed to get just one test filtering with "goodTag" oetag.' | ||
32 | |||
33 | # Get cases with an invalid tag. | ||
34 | filter_invalid = {'oetag':'invalidTag'} | ||
35 | test_invalid = set() | ||
36 | msg_invalid = 'Failed to filter all test using an invalid oetag.' | ||
37 | |||
38 | tests = ((filter_all, test_all, msg_all), | ||
39 | (filter_good, test_good, msg_good), | ||
40 | (filter_invalid, test_invalid, msg_invalid)) | ||
41 | |||
42 | for test in tests: | ||
43 | self._runFilterTest(['oetag'], test[0], test[1], test[2]) | ||
44 | |||
45 | def test_oeid(self): | ||
46 | # Get all cases without filtering. | ||
47 | filter_all = {} | ||
48 | test_all = {'testIdGood', 'testIdOther', 'testIdNone'} | ||
49 | msg_all = 'Failed to get all oeid cases without filtering.' | ||
50 | |||
51 | # Get cases with '101' oeid. | ||
52 | filter_good = {'oeid': 101} | ||
53 | test_good = {'testIdGood'} | ||
54 | msg_good = 'Failed to get just one tes filtering with "101" oeid.' | ||
55 | |||
56 | # Get cases with an invalid id. | ||
57 | filter_invalid = {'oeid':999} | ||
58 | test_invalid = set() | ||
59 | msg_invalid = 'Failed to filter all test using an invalid oeid.' | ||
60 | |||
61 | tests = ((filter_all, test_all, msg_all), | ||
62 | (filter_good, test_good, msg_good), | ||
63 | (filter_invalid, test_invalid, msg_invalid)) | ||
64 | |||
65 | for test in tests: | ||
66 | self._runFilterTest(['oeid'], test[0], test[1], test[2]) | ||
67 | |||
68 | class TestDependsDecorator(TestBase): | ||
69 | modules = ['depends'] | ||
70 | |||
71 | def test_depends_order(self): | ||
72 | tests = ['depends.DependsTest.testDependsFirst', | ||
73 | 'depends.DependsTest.testDependsSecond', | ||
74 | 'depends.DependsTest.testDependsThird', | ||
75 | 'depends.DependsTest.testDependsFourth', | ||
76 | 'depends.DependsTest.testDependsFifth'] | ||
77 | tests2 = list(tests) | ||
78 | tests2[2], tests2[3] = tests[3], tests[2] | ||
79 | tc = self._testLoader(modules=self.modules, tests=tests) | ||
80 | test_loaded = getSuiteCasesIDs(tc.suites) | ||
81 | result = True if test_loaded == tests or test_loaded == tests2 else False | ||
82 | msg = 'Failed to order tests using OETestDepends decorator.\nTest order:'\ | ||
83 | ' %s.\nExpected: %s\nOr: %s' % (test_loaded, tests, tests2) | ||
84 | self.assertTrue(result, msg=msg) | ||
85 | |||
86 | def test_depends_fail_missing_dependency(self): | ||
87 | expect = "TestCase depends.DependsTest.testDependsSecond depends on "\ | ||
88 | "depends.DependsTest.testDependsFirst and isn't available" | ||
89 | tests = ['depends.DependsTest.testDependsSecond'] | ||
90 | try: | ||
91 | # Must throw OEQADependency because missing 'testDependsFirst' | ||
92 | tc = self._testLoader(modules=self.modules, tests=tests) | ||
93 | self.fail('Expected OEQADependency exception') | ||
94 | except OEQADependency as e: | ||
95 | result = True if expect in str(e) else False | ||
96 | msg = 'Expected OEQADependency exception missing testDependsFirst test' | ||
97 | self.assertTrue(result, msg=msg) | ||
98 | |||
99 | def test_depends_fail_circular_dependency(self): | ||
100 | expect = 'have a circular dependency' | ||
101 | tests = ['depends.DependsTest.testDependsCircular1', | ||
102 | 'depends.DependsTest.testDependsCircular2', | ||
103 | 'depends.DependsTest.testDependsCircular3'] | ||
104 | try: | ||
105 | # Must throw OEQADependency because circular dependency | ||
106 | tc = self._testLoader(modules=self.modules, tests=tests) | ||
107 | self.fail('Expected OEQADependency exception') | ||
108 | except OEQADependency as e: | ||
109 | result = True if expect in str(e) else False | ||
110 | msg = 'Expected OEQADependency exception having a circular dependency' | ||
111 | self.assertTrue(result, msg=msg) | ||
112 | |||
113 | class TestTimeoutDecorator(TestBase): | ||
114 | modules = ['timeout'] | ||
115 | |||
116 | def test_timeout(self): | ||
117 | tests = ['timeout.TimeoutTest.testTimeoutPass'] | ||
118 | msg = 'Failed to run test using OETestTimeout' | ||
119 | alarm_signal = signal.getsignal(signal.SIGALRM) | ||
120 | tc = self._testLoader(modules=self.modules, tests=tests) | ||
121 | self.assertTrue(tc.runTests().wasSuccessful(), msg=msg) | ||
122 | msg = "OETestTimeout didn't restore SIGALRM" | ||
123 | self.assertIs(alarm_signal, signal.getsignal(signal.SIGALRM), msg=msg) | ||
124 | |||
125 | def test_timeout_fail(self): | ||
126 | tests = ['timeout.TimeoutTest.testTimeoutFail'] | ||
127 | msg = "OETestTimeout test didn't timeout as expected" | ||
128 | alarm_signal = signal.getsignal(signal.SIGALRM) | ||
129 | tc = self._testLoader(modules=self.modules, tests=tests) | ||
130 | self.assertFalse(tc.runTests().wasSuccessful(), msg=msg) | ||
131 | msg = "OETestTimeout didn't restore SIGALRM" | ||
132 | self.assertIs(alarm_signal, signal.getsignal(signal.SIGALRM), msg=msg) | ||
133 | |||
134 | if __name__ == '__main__': | ||
135 | unittest.main() | ||
diff --git a/meta/lib/oeqa/core/tests/test_loader.py b/meta/lib/oeqa/core/tests/test_loader.py new file mode 100755 index 0000000000..b79b8bad4d --- /dev/null +++ b/meta/lib/oeqa/core/tests/test_loader.py | |||
@@ -0,0 +1,86 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | # Copyright (C) 2016 Intel Corporation | ||
4 | # Released under the MIT license (see COPYING.MIT) | ||
5 | |||
6 | import os | ||
7 | import unittest | ||
8 | |||
9 | from common import setup_sys_path, TestBase | ||
10 | setup_sys_path() | ||
11 | |||
12 | from oeqa.core.exception import OEQADependency | ||
13 | from oeqa.core.utils.test import getSuiteModules, getSuiteCasesIDs | ||
14 | |||
15 | class TestLoader(TestBase): | ||
16 | |||
17 | def test_fail_empty_filter(self): | ||
18 | filters = {'oetag' : ''} | ||
19 | expect = 'Filter oetag specified is empty' | ||
20 | msg = 'Expected TypeError exception for having invalid filter' | ||
21 | try: | ||
22 | # Must throw TypeError because empty filter | ||
23 | tc = self._testLoader(filters=filters) | ||
24 | self.fail(msg) | ||
25 | except TypeError as e: | ||
26 | result = True if expect in str(e) else False | ||
27 | self.assertTrue(result, msg=msg) | ||
28 | |||
29 | def test_fail_invalid_filter(self): | ||
30 | filters = {'invalid' : 'good'} | ||
31 | expect = 'filter but not declared in any of' | ||
32 | msg = 'Expected TypeError exception for having invalid filter' | ||
33 | try: | ||
34 | # Must throw TypeError because invalid filter | ||
35 | tc = self._testLoader(filters=filters) | ||
36 | self.fail(msg) | ||
37 | except TypeError as e: | ||
38 | result = True if expect in str(e) else False | ||
39 | self.assertTrue(result, msg=msg) | ||
40 | |||
41 | def test_fail_duplicated_module(self): | ||
42 | cases_path = self.cases_path | ||
43 | invalid_path = os.path.join(cases_path, 'loader', 'invalid') | ||
44 | self.cases_path = [self.cases_path, invalid_path] | ||
45 | expect = 'Duplicated oeid module found in' | ||
46 | msg = 'Expected ImportError exception for having duplicated module' | ||
47 | try: | ||
48 | # Must throw ImportEror because duplicated module | ||
49 | tc = self._testLoader() | ||
50 | self.fail(msg) | ||
51 | except ImportError as e: | ||
52 | result = True if expect in str(e) else False | ||
53 | self.assertTrue(result, msg=msg) | ||
54 | finally: | ||
55 | self.cases_path = cases_path | ||
56 | |||
57 | def test_filter_modules(self): | ||
58 | expected_modules = {'oeid', 'oetag'} | ||
59 | tc = self._testLoader(modules=expected_modules) | ||
60 | modules = getSuiteModules(tc.suites) | ||
61 | msg = 'Expected just %s modules' % ', '.join(expected_modules) | ||
62 | self.assertEqual(modules, expected_modules, msg=msg) | ||
63 | |||
64 | def test_filter_cases(self): | ||
65 | modules = ['oeid', 'oetag', 'data'] | ||
66 | expected_cases = {'data.DataTest.testDataOk', | ||
67 | 'oetag.TagTest.testTagGood', | ||
68 | 'oeid.IDTest.testIdGood'} | ||
69 | tc = self._testLoader(modules=modules, tests=expected_cases) | ||
70 | cases = set(getSuiteCasesIDs(tc.suites)) | ||
71 | msg = 'Expected just %s cases' % ', '.join(expected_cases) | ||
72 | self.assertEqual(cases, expected_cases, msg=msg) | ||
73 | |||
74 | def test_import_from_paths(self): | ||
75 | cases_path = self.cases_path | ||
76 | cases2_path = os.path.join(cases_path, 'loader', 'valid') | ||
77 | expected_modules = {'oeid', 'another'} | ||
78 | self.cases_path = [self.cases_path, cases2_path] | ||
79 | tc = self._testLoader(modules=expected_modules) | ||
80 | modules = getSuiteModules(tc.suites) | ||
81 | self.cases_path = cases_path | ||
82 | msg = 'Expected modules from two different paths' | ||
83 | self.assertEqual(modules, expected_modules, msg=msg) | ||
84 | |||
85 | if __name__ == '__main__': | ||
86 | unittest.main() | ||
diff --git a/meta/lib/oeqa/core/tests/test_runner.py b/meta/lib/oeqa/core/tests/test_runner.py new file mode 100755 index 0000000000..a3f3861fed --- /dev/null +++ b/meta/lib/oeqa/core/tests/test_runner.py | |||
@@ -0,0 +1,38 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | # Copyright (C) 2016 Intel Corporation | ||
4 | # Released under the MIT license (see COPYING.MIT) | ||
5 | |||
6 | import unittest | ||
7 | import logging | ||
8 | import tempfile | ||
9 | |||
10 | from common import setup_sys_path, TestBase | ||
11 | setup_sys_path() | ||
12 | |||
13 | from oeqa.core.runner import OEStreamLogger | ||
14 | |||
15 | class TestRunner(TestBase): | ||
16 | def test_stream_logger(self): | ||
17 | fp = tempfile.TemporaryFile(mode='w+') | ||
18 | |||
19 | logging.basicConfig(format='%(message)s', stream=fp) | ||
20 | logger = logging.getLogger() | ||
21 | logger.setLevel(logging.INFO) | ||
22 | |||
23 | oeSL = OEStreamLogger(logger) | ||
24 | |||
25 | lines = ['init', 'bigline_' * 65535, 'morebigline_' * 65535 * 4, 'end'] | ||
26 | for line in lines: | ||
27 | oeSL.write(line) | ||
28 | |||
29 | fp.seek(0) | ||
30 | fp_lines = fp.readlines() | ||
31 | for i, fp_line in enumerate(fp_lines): | ||
32 | fp_line = fp_line.strip() | ||
33 | self.assertEqual(lines[i], fp_line) | ||
34 | |||
35 | fp.close() | ||
36 | |||
37 | if __name__ == '__main__': | ||
38 | unittest.main() | ||