Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | import importlib |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | import oeqa.selftest |
| 9 | from oeqa.selftest.case import OESelftestTestCase |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | |
| 11 | class ExternalLayer(OESelftestTestCase): |
| 12 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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 | |
| 37 | def 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 | |
| 45 | def 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 | |