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