Coverage for src / questions / validators / max_length.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-11-21 16:36 +0000

1from prompt_toolkit.validation import ValidationError 

2 

3 

4def validate(value, schema): 

5 """ 

6 Return { value to use, stop (True/False) } 

7 

8 If stop is True, the rest of the validators are skipped. 

9 """ 

10 vartype = schema.get("type", "string") 

11 if vartype != "string": 

12 return value, False 

13 

14 max_length = schema.get("max_length", None) 

15 if max_length and len(value) > max_length: 

16 raise ValidationError(message=f"Answer cannot be longer than {max_length} characters") from None 

17 return value, False