Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | # Copyright (C) 2016 Intel Corporation |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6 | |
| 7 | from oeqa.core.exception import OEQAMissingVariable |
| 8 | |
| 9 | from . import OETestDecorator, registerDecorator |
| 10 | |
| 11 | def 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 |
| 22 | class 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 |
| 41 | class 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 60 | class 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 74 | class 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 Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 81 | msg = ('Checking if %r value contains %r to run ' |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 82 | 'the test' % (self.var, self.value)) |
| 83 | self.logger.debug(msg) |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 84 | if not self.value in (self.case.td.get(self.var) or ""): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 85 | self.case.skipTest(self.msg) |
| 86 | |
| 87 | @registerDecorator |
| 88 | class 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 |
| 100 | class 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 Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame^] | 116 | |
| 117 | @registerDecorator |
| 118 | class 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) |