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