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