Coverage for src / questions / validators / allowed.py: 100%
9 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-21 16:36 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-21 16:36 +0000
1from prompt_toolkit.validation import ValidationError
4def validate(value, schema):
5 """
6 Return { value to use, stop (True/False) }
8 If stop is True, the rest of the validators are skipped.
9 """
10 allowed = schema.get("allowed")
11 if allowed is None:
12 return value, False
14 if value not in allowed:
15 allowed = ", ".join(allowed)
16 raise ValidationError(message=f"Answer must be within [{allowed}]")
18 return value, False