blob: 12d462f2029801bba87921a801cfbcc92e0cf316 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006
7from oeqa.core.exception import OEQAMissingVariable
8
9from . import OETestDecorator, registerDecorator
10
11def has_feature(td, feature):
12 """
13 Checks for feature in DISTRO_FEATURES or IMAGE_FEATURES.
14 """
15
16 if (feature in td.get('DISTRO_FEATURES', '') or
17 feature in td.get('IMAGE_FEATURES', '')):
18 return True
19 return False
20
21@registerDecorator
22class skipIfDataVar(OETestDecorator):
23 """
24 Skip test based on value of a data store's variable.
25
26 It will get the info of var from the data store and will
27 check it against value; if are equal it will skip the test
28 with msg as the reason.
29 """
30
31 attrs = ('var', 'value', 'msg')
32
33 def setUpDecorator(self):
34 msg = ('Checking if %r value is %r to skip test' %
35 (self.var, self.value))
36 self.logger.debug(msg)
37 if self.case.td.get(self.var) == self.value:
38 self.case.skipTest(self.msg)
39
40@registerDecorator
41class skipIfNotDataVar(OETestDecorator):
42 """
43 Skip test based on value of a data store's variable.
44
45 It will get the info of var from the data store and will
46 check it against value; if are not equal it will skip the
47 test with msg as the reason.
48 """
49
50 attrs = ('var', 'value', 'msg')
51
52 def setUpDecorator(self):
53 msg = ('Checking if %r value is not %r to skip test' %
54 (self.var, self.value))
55 self.logger.debug(msg)
56 if not self.case.td.get(self.var) == self.value:
57 self.case.skipTest(self.msg)
58
59@registerDecorator
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080060class skipIfInDataVar(OETestDecorator):
61 """
62 Skip test if value is in data store's variable.
63 """
64
65 attrs = ('var', 'value', 'msg')
66 def setUpDecorator(self):
67 msg = ('Checking if %r value contains %r to skip '
68 'the test' % (self.var, self.value))
69 self.logger.debug(msg)
70 if self.value in (self.case.td.get(self.var)):
71 self.case.skipTest(self.msg)
72
73@registerDecorator
Brad Bishop6e60e8b2018-02-01 10:27:11 -050074class skipIfNotInDataVar(OETestDecorator):
75 """
76 Skip test if value is not in data store's variable.
77 """
78
79 attrs = ('var', 'value', 'msg')
80 def setUpDecorator(self):
Brad Bishopd5ae7d92018-06-14 09:52:03 -070081 msg = ('Checking if %r value contains %r to run '
Brad Bishop6e60e8b2018-02-01 10:27:11 -050082 'the test' % (self.var, self.value))
83 self.logger.debug(msg)
Brad Bishopd5ae7d92018-06-14 09:52:03 -070084 if not self.value in (self.case.td.get(self.var) or ""):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050085 self.case.skipTest(self.msg)
86
87@registerDecorator
88class OETestDataDepends(OETestDecorator):
89 attrs = ('td_depends',)
90
91 def setUpDecorator(self):
92 for v in self.td_depends:
93 try:
94 value = self.case.td[v]
95 except KeyError:
96 raise OEQAMissingVariable("Test case need %s variable but"\
97 " isn't into td" % v)
98
99@registerDecorator
100class skipIfNotFeature(OETestDecorator):
101 """
102 Skip test based on DISTRO_FEATURES.
103
104 value must be in distro features or it will skip the test
105 with msg as the reason.
106 """
107
108 attrs = ('value', 'msg')
109
110 def setUpDecorator(self):
111 msg = ('Checking if %s is in DISTRO_FEATURES '
112 'or IMAGE_FEATURES' % (self.value))
113 self.logger.debug(msg)
114 if not has_feature(self.case.td, self.value):
115 self.case.skipTest(self.msg)
Brad Bishop64c979e2019-11-04 13:55:29 -0500116
117@registerDecorator
118class skipIfFeature(OETestDecorator):
119 """
120 Skip test based on DISTRO_FEATURES.
121
122 value must not be in distro features or it will skip the test
123 with msg as the reason.
124 """
125
126 attrs = ('value', 'msg')
127
128 def setUpDecorator(self):
129 msg = ('Checking if %s is not in DISTRO_FEATURES '
130 'or IMAGE_FEATURES' % (self.value))
131 self.logger.debug(msg)
132 if has_feature(self.case.td, self.value):
133 self.case.skipTest(self.msg)