selftest.py 1.7 KB

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