• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LeanderCS / flask-inputfilter / #68

16 Jan 2025 11:08PM CUT coverage: 99.252% (-0.09%) from 99.337%
#68

Pull #20

coveralls-python

LeanderCS
16 | Add functionality to filter and validate in a custom order
Pull Request #20: 16 | Add functionality to filter and validate in a custom order

16 of 17 new or added lines in 1 file covered. (94.12%)

1062 of 1070 relevant lines covered (99.25%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/flask_inputfilter/Validator/ArrayElementValidator.py
1
from typing import TYPE_CHECKING, Any, Optional
1✔
2

3
from ..Exception import ValidationError
1✔
4
from .BaseValidator import BaseValidator
1✔
5

6
if TYPE_CHECKING:
1✔
7
    from ..InputFilter import InputFilter
×
8

9

10
class ArrayElementValidator(BaseValidator):
1✔
11
    """
12
    Validator to validate each element in an array.
13
    """
14

15
    def __init__(
1✔
16
        self,
17
        elementFilter: "InputFilter",
18
        error_message: Optional[str] = None,
19
    ) -> None:
20
        self.elementFilter = elementFilter
1✔
21
        self.error_message = error_message
1✔
22

23
    def validate(self, value: Any) -> None:
1✔
24
        if not isinstance(value, list):
1✔
25
            raise ValidationError(f"Value '{value}' is not an array")
1✔
26

27
        for i, element in enumerate(value):
1✔
28
            try:
1✔
29
                validated_element = self.elementFilter.validateData(element)
1✔
30
                value[i] = validated_element
1✔
31

32
            except ValidationError:
1✔
33
                raise ValidationError(
1✔
34
                    self.error_message
35
                    or f"Value '{element}' is not in '{self.elementFilter}'"
36
                )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc