Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | import importlib |
| 6 | from oeqa.utils.commands import runCmd |
| 7 | import oeqa.selftest |
| 8 | from oeqa.selftest.case import OESelftestTestCase |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9 | |
| 10 | class ExternalLayer(OESelftestTestCase): |
| 11 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | 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 | |
| 36 | def 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 | |
| 44 | def 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 | |