(cls, predicate, description=None)
| 207 | class Predicate: |
| 208 | @classmethod |
| 209 | def as_predicate(cls, predicate, description=None): |
| 210 | if isinstance(predicate, compound): |
| 211 | return cls.as_predicate(predicate.enabled_for_config, description) |
| 212 | elif isinstance(predicate, Predicate): |
| 213 | if description and predicate.description is None: |
| 214 | predicate.description = description |
| 215 | return predicate |
| 216 | elif isinstance(predicate, (list, set)): |
| 217 | return OrPredicate( |
| 218 | [cls.as_predicate(pred) for pred in predicate], description |
| 219 | ) |
| 220 | elif isinstance(predicate, tuple): |
| 221 | return SpecPredicate(*predicate) |
| 222 | elif isinstance(predicate, str): |
| 223 | tokens = re.match( |
| 224 | r"([\+\w]+)\s*(?:(>=|==|!=|<=|<|>)\s*([\d\.]+))?", predicate |
| 225 | ) |
| 226 | if not tokens: |
| 227 | raise ValueError( |
| 228 | "Couldn't locate DB name in predicate: %r" % predicate |
| 229 | ) |
| 230 | db = tokens.group(1) |
| 231 | op = tokens.group(2) |
| 232 | spec = ( |
| 233 | tuple(int(d) for d in tokens.group(3).split(".")) |
| 234 | if tokens.group(3) |
| 235 | else None |
| 236 | ) |
| 237 | |
| 238 | return SpecPredicate(db, op, spec, description=description) |
| 239 | elif callable(predicate): |
| 240 | return LambdaPredicate(predicate, description) |
| 241 | else: |
| 242 | assert False, "unknown predicate type: %s" % predicate |
| 243 | |
| 244 | def _format_description(self, config, negate=False): |
| 245 | bool_ = self(config) |
no test coverage detected