1# 2# Copyright OpenEmbedded Contributors 3# 4# SPDX-License-Identifier: MIT 5# 6 7import importlib 8import oeqa.selftest 9from oeqa.selftest.case import OESelftestTestCase 10 11class ExternalLayer(OESelftestTestCase): 12 13 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 55