summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Perez Carranza <jose.perez.carranza@linux.intel.com>2017-06-22 09:16:32 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-28 20:55:08 +0100
commitf44c923bb9993a26d2cadcdea14dcfe0be64f3dc (patch)
tree543e6d7394f17dbc316f3ce57b72a86f71ef90ba
parent3e71c5778057ec35abf5b730f05b0a84b3b60e44 (diff)
downloadpoky-f44c923bb9993a26d2cadcdea14dcfe0be64f3dc.tar.gz
selftest/seltest.py: Add test to check imports from other layers
This tests adds a check of selftest itself to verify if can add test from other layers. [YOCTO #9770] (From OE-Core rev: 4fe4c408246b9a4a563106d097876e6caefca694) Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Jose Perez Carranza <jose.perez.carranza@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta-selftest/lib/oeqa/selftest/cases/external-layer.py16
-rw-r--r--meta/lib/oeqa/selftest/cases/selftest.py51
2 files changed, 67 insertions, 0 deletions
diff --git a/meta-selftest/lib/oeqa/selftest/cases/external-layer.py b/meta-selftest/lib/oeqa/selftest/cases/external-layer.py
new file mode 100644
index 0000000000..59b1afab7d
--- /dev/null
+++ b/meta-selftest/lib/oeqa/selftest/cases/external-layer.py
@@ -0,0 +1,16 @@
1#from oeqa.selftest.base import oeSelfTest
2from oeqa.selftest.case import OESelftestTestCase
3#from oeqa.utils.decorators import testcase
4
5
6class ImportedTests(OESelftestTestCase):
7
8 def test_unconditional_pass(self):
9 """
10 Summary: Doesn't check anything, used to check import test from other layers.
11 Expected: 1. Pass unconditionally
12 Product: oe-core
13 Author: Mariano Lopez <mariano.lopez@intel.com
14 """
15
16 self.assertEqual(True, True, msg = "Impossible to fail this test")
diff --git a/meta/lib/oeqa/selftest/cases/selftest.py b/meta/lib/oeqa/selftest/cases/selftest.py
new file mode 100644
index 0000000000..4b3cb14463
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/selftest.py
@@ -0,0 +1,51 @@
1import importlib
2from oeqa.utils.commands import runCmd
3import oeqa.selftest
4from oeqa.selftest.case import OESelftestTestCase
5from oeqa.core.decorator.oeid import OETestID
6
7class ExternalLayer(OESelftestTestCase):
8
9 @OETestID(1885)
10 def test_list_imported(self):
11 """
12 Summary: Checks functionality to import tests from other layers.
13 Expected: 1. File "external-layer.py" must be in
14 oeqa.selftest.__path__
15 2. test_unconditional_pas method must exists
16 in ImportedTests class
17 Product: oe-core
18 Author: Mariano Lopez <mariano.lopez@intel.com>
19 """
20
21 test_file = "external-layer.py"
22 test_module = "oeqa.selftest.cases.external-layer"
23 method_name = "test_unconditional_pass"
24
25 # Check if "external-layer.py" is in oeqa path
26 found_file = search_test_file(test_file)
27 self.assertTrue(found_file, msg="Can't find %s in the oeqa path" % test_file)
28
29 # Import oeqa.selftest.external-layer module and search for
30 # test_unconditional_pass method of ImportedTests class
31 found_method = search_method(test_module, method_name)
32 self.assertTrue(method_name, msg="Can't find %s method" % method_name)
33
34def search_test_file(file_name):
35 for layer_path in oeqa.selftest.__path__:
36 for _, _, files in os.walk(layer_path):
37 for f in files:
38 if f == file_name:
39 return True
40 return False
41
42def search_method(module, method):
43 modlib = importlib.import_module(module)
44 for var in vars(modlib):
45 klass = vars(modlib)[var]
46 if isinstance(klass, type(OESelftestTestCase)) and issubclass(klass, OESelftestTestCase):
47 for m in dir(klass):
48 if m == method:
49 return True
50 return False
51