| 1 |
from ..check import Check |
| 2 |
|
| 3 |
class CheckFeatures(Check): |
| 4 |
'''Ensure tests specify only `features` from a list of valid values.''' |
| 5 |
ID = 'FEATURES' |
| 6 |
|
| 7 |
def __init__(self, filename): |
| 8 |
with open(filename, 'r') as f: |
| 9 |
self.valid_features = self._parse(f.read()) |
| 10 |
|
| 11 |
@staticmethod |
| 12 |
def _parse(content): |
| 13 |
features = [] |
| 14 |
for line in content.split(): |
| 15 |
if not line or line.startswith('#'): |
| 16 |
continue |
| 17 |
features.append(line) |
| 18 |
return features |
| 19 |
|
| 20 |
def run(self, name, meta, source): |
| 21 |
if not meta or 'features' not in meta: |
| 22 |
return |
| 23 |
|
| 24 |
features = meta['features'] |
| 25 |
|
| 26 |
if len(features) == 0: |
| 27 |
return 'If present, the `features` tag must have at least one member' |
| 28 |
|
| 29 |
for feature in features: |
| 30 |
if feature not in self.valid_features: |
| 31 |
return 'Unrecognized feature: "%s"' % feature |