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