selftest.py 1.8 KB

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