blob: a80a8651a5b2bd5851c6356bb653680dc6eb5209 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007import importlib
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008import oeqa.selftest
9from oeqa.selftest.case import OESelftestTestCase
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010
11class ExternalLayer(OESelftestTestCase):
12
Brad Bishopd7bf8c12018-02-25 22:55:05 -050013 def test_list_imported(self):
14 """
15 Summary: Checks functionality to import tests from other layers.
16 Expected: 1. File "external-layer.py" must be in
17 oeqa.selftest.__path__
18 2. test_unconditional_pas method must exists
19 in ImportedTests class
20 Product: oe-core
21 Author: Mariano Lopez <mariano.lopez@intel.com>
22 """
23
24 test_file = "external-layer.py"
25 test_module = "oeqa.selftest.cases.external-layer"
26 method_name = "test_unconditional_pass"
27
28 # Check if "external-layer.py" is in oeqa path
29 found_file = search_test_file(test_file)
30 self.assertTrue(found_file, msg="Can't find %s in the oeqa path" % test_file)
31
32 # Import oeqa.selftest.external-layer module and search for
33 # test_unconditional_pass method of ImportedTests class
34 found_method = search_method(test_module, method_name)
35 self.assertTrue(method_name, msg="Can't find %s method" % method_name)
36
37def search_test_file(file_name):
38 for layer_path in oeqa.selftest.__path__:
39 for _, _, files in os.walk(layer_path):
40 for f in files:
41 if f == file_name:
42 return True
43 return False
44
45def search_method(module, method):
46 modlib = importlib.import_module(module)
47 for var in vars(modlib):
48 klass = vars(modlib)[var]
49 if isinstance(klass, type(OESelftestTestCase)) and issubclass(klass, OESelftestTestCase):
50 for m in dir(klass):
51 if m == method:
52 return True
53 return False
54