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

andreoliwa / nitpick / 9594924093

20 Jun 2024 09:21AM UTC coverage: 96.746%. Remained the same
9594924093

push

github

andreoliwa
build(deps): bump urllib3 from 2.0.7 to 2.2.2

Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.0.7 to 2.2.2.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/2.0.7...2.2.2)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

788 of 827 branches covered (95.28%)

Branch coverage included in aggregate %.

2096 of 2154 relevant lines covered (97.31%)

4.86 hits per line

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

92.31
/src/nitpick/fields.py
1
"""Custom Marshmallow fields and validators."""
2

3
import json
5✔
4

5
from marshmallow import ValidationError, fields
5✔
6
from marshmallow.fields import URL, Dict, Field, List, Nested, String
5✔
7
from marshmallow.validate import Length
5✔
8
from more_itertools import always_iterable
5✔
9

10
from nitpick.constants import DOT
5✔
11
from nitpick.exceptions import pretty_exception
5✔
12

13
__all__ = ("Dict", "Field", "List", "Nested", "String", "URL")
5✔
14

15
MAX_PARTS = 2
5✔
16

17

18
def is_valid_json(json_string: str) -> bool:
5✔
19
    """Validate the string as JSON."""
20
    try:
5✔
21
        json.loads(json_string)
5✔
22
    except json.JSONDecodeError as err:
5✔
23
        raise ValidationError(pretty_exception(err, "Invalid JSON")) from err
5✔
24
    return True
5✔
25

26

27
class TrimmedLength(Length):  # pylint: disable=too-few-public-methods
5✔
28
    """Trim the string before validating the length."""
29

30
    def __call__(self, value):
5✔
31
        """Validate the trimmed string."""
32
        return super().__call__(value.strip())
5✔
33

34

35
class NonEmptyString(fields.String):
5✔
36
    """A string field that must not be empty even after trimmed."""
37

38
    def __init__(self, **kwargs) -> None:
5✔
39
        validate = list(always_iterable(kwargs.pop("validate", None)))
5✔
40
        validate.append(TrimmedLength(min=1))
5✔
41
        super().__init__(validate=validate, **kwargs)
5✔
42

43

44
class JsonString(fields.String):
5✔
45
    """A string field with valid JSON content."""
46

47
    def __init__(self, **kwargs) -> None:
5✔
48
        validate = kwargs.pop("validate", [])
5✔
49
        validate.append(is_valid_json)
5✔
50
        super().__init__(validate=validate, **kwargs)
5✔
51

52

53
def string_or_list_field(object_dict, parent_object_dict):  # pylint: disable=unused-argument # noqa: ARG001
5✔
54
    """Detect if the field is a string or a list."""
55
    if isinstance(object_dict, list):
5✔
56
        return fields.List(NonEmptyString(required=True, allow_none=False))
5✔
57
    return NonEmptyString()
5✔
58

59

60
def validate_section_dot_field(section_field: str) -> bool:
5✔
61
    """Validate if the combination section/field has a dot separating them."""
62
    common = "Use <section_name>.<field_name>"
5✔
63
    msg = ""
5✔
64
    if DOT not in section_field:
5✔
65
        msg = f"Dot is missing. {common}"
5✔
66
    else:
67
        parts = section_field.split(DOT)
5✔
68
        if len(parts) > MAX_PARTS:
5✔
69
            msg = f"There's more than one dot. {common}"
5✔
70
        elif not parts[0].strip():
5✔
71
            msg = f"Empty section name. {common}"
5✔
72
        elif not parts[1].strip():
5✔
73
            msg = f"Empty field name. {common}"
5✔
74
    if msg:
5✔
75
        raise ValidationError(msg)
5✔
76
    return True
5✔
77

78

79
def boolean_or_dict_field(object_dict, parent_object_dict):  # pylint: disable=unused-argument # noqa: ARG001
5✔
80
    """Detect if the field is a boolean or a dict."""
81
    if isinstance(object_dict, dict):
×
82
        return fields.Dict
×
83
    return fields.Bool
×
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