data.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #
  2. # Copyright (C) 2016 Intel Corporation
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. from oeqa.core.exception import OEQAMissingVariable
  7. from . import OETestDecorator, registerDecorator
  8. def has_feature(td, feature):
  9. """
  10. Checks for feature in DISTRO_FEATURES or IMAGE_FEATURES.
  11. """
  12. if (feature in td.get('DISTRO_FEATURES', '') or
  13. feature in td.get('IMAGE_FEATURES', '')):
  14. return True
  15. return False
  16. @registerDecorator
  17. class skipIfDataVar(OETestDecorator):
  18. """
  19. Skip test based on value of a data store's variable.
  20. It will get the info of var from the data store and will
  21. check it against value; if are equal it will skip the test
  22. with msg as the reason.
  23. """
  24. attrs = ('var', 'value', 'msg')
  25. def setUpDecorator(self):
  26. msg = ('Checking if %r value is %r to skip test' %
  27. (self.var, self.value))
  28. self.logger.debug(msg)
  29. if self.case.td.get(self.var) == self.value:
  30. self.case.skipTest(self.msg)
  31. @registerDecorator
  32. class skipIfNotDataVar(OETestDecorator):
  33. """
  34. Skip test based on value of a data store's variable.
  35. It will get the info of var from the data store and will
  36. check it against value; if are not equal it will skip the
  37. test with msg as the reason.
  38. """
  39. attrs = ('var', 'value', 'msg')
  40. def setUpDecorator(self):
  41. msg = ('Checking if %r value is not %r to skip test' %
  42. (self.var, self.value))
  43. self.logger.debug(msg)
  44. if not self.case.td.get(self.var) == self.value:
  45. self.case.skipTest(self.msg)
  46. @registerDecorator
  47. class skipIfInDataVar(OETestDecorator):
  48. """
  49. Skip test if value is in data store's variable.
  50. """
  51. attrs = ('var', 'value', 'msg')
  52. def setUpDecorator(self):
  53. msg = ('Checking if %r value contains %r to skip '
  54. 'the test' % (self.var, self.value))
  55. self.logger.debug(msg)
  56. if self.value in (self.case.td.get(self.var)):
  57. self.case.skipTest(self.msg)
  58. @registerDecorator
  59. class skipIfNotInDataVar(OETestDecorator):
  60. """
  61. Skip test if value is not in data store's variable.
  62. """
  63. attrs = ('var', 'value', 'msg')
  64. def setUpDecorator(self):
  65. msg = ('Checking if %r value contains %r to run '
  66. 'the test' % (self.var, self.value))
  67. self.logger.debug(msg)
  68. if not self.value in (self.case.td.get(self.var) or ""):
  69. self.case.skipTest(self.msg)
  70. @registerDecorator
  71. class OETestDataDepends(OETestDecorator):
  72. attrs = ('td_depends',)
  73. def setUpDecorator(self):
  74. for v in self.td_depends:
  75. try:
  76. value = self.case.td[v]
  77. except KeyError:
  78. raise OEQAMissingVariable("Test case need %s variable but"\
  79. " isn't into td" % v)
  80. @registerDecorator
  81. class skipIfNotFeature(OETestDecorator):
  82. """
  83. Skip test based on DISTRO_FEATURES.
  84. value must be in distro features or it will skip the test
  85. with msg as the reason.
  86. """
  87. attrs = ('value', 'msg')
  88. def setUpDecorator(self):
  89. msg = ('Checking if %s is in DISTRO_FEATURES '
  90. 'or IMAGE_FEATURES' % (self.value))
  91. self.logger.debug(msg)
  92. if not has_feature(self.case.td, self.value):
  93. self.case.skipTest(self.msg)