Exemplo n.º 1
0
class AttribsWithName(ValidatingAttribs):
    name = attr.ib(type=str,
                   validator=[
                       instance_of(str),
                       has_length(f'>={MIN_NAME_LENGTH}'),
                       has_length(f'<={MAX_NAME_LENGTH}'),
                       matches_re(RE_NAME),
                       matches_re(RE_NOT_NAME, func=re.match),
                   ])
Exemplo n.º 2
0
    def test_catches_invalid_func(self):
        """
        Invalid match functions are caught.
        """
        with pytest.raises(ValueError) as ei:
            matches_re("a", 0, lambda: None)

        assert ("'func' must be one of None, fullmatch, match, search." ==
                ei.value.args[0])
Exemplo n.º 3
0
    def test_precompiled_pattern_no_flags(self):
        """
        A pre-compiled pattern cannot be combined with a 'flags' argument.
        """
        pattern = re.compile("")

        with pytest.raises(TypeError,
                           match="can only be used with a string pattern"):
            matches_re(pattern, flags=re.IGNORECASE)
Exemplo n.º 4
0
 def test_repr(self):
     """
     __repr__ is meaningful.
     """
     assert repr(matches_re("a")).startswith(
         "<matches_re validator for pattern"
     )
Exemplo n.º 5
0
class Marktteilnehmer(Geschaeftspartner):
    """
    Objekt zur Aufnahme der Information zu einem Marktteilnehmer
    """

    # required attributes
    bo_typ: BoTyp = attr.ib(default=BoTyp.MARKTTEILNEHMER)
    marktrolle: Marktrolle
    rollencodenummer: str = attr.ib(validator=matches_re(r"^\d{13}$"))
    rollencodetyp: Rollencodetyp

    # optional attributes
    makoadresse: str = attr.ib(default=None)
Exemplo n.º 6
0
 class ValidatedAttribute:
     x = attr.ib()
     y = attr.ib(validator=[instance_of(str), matches_re("foo.*qux")])
Exemplo n.º 7
0
class ContainerDeleteAttribs(ValidatingAttribs):
    id = attr.ib(type=str, validator=[has_length(10), matches_re(RE_UUID)])
Exemplo n.º 8
0
class UrlItem:
    """A URL in a toctree."""

    # regex should match sphinx.util.url_re
    url: str = attr.ib(validator=[instance_of(str), matches_re(r".+://.*")])
    title: Optional[str] = attr.ib(None, validator=optional(instance_of(str)))
Exemplo n.º 9
0
 def test_accepts_all_valid_func(self, func):
     """
     Every valid match function is accepted.
     """
     matches_re("a", func=func)
Exemplo n.º 10
0
 class SearchTester:
     val = attr.ib(validator=matches_re("a", 0, re.search))
Exemplo n.º 11
0
 class RePatternTester:
     val = attr.ib(validator=matches_re(pattern))
Exemplo n.º 12
0
 class MatchTester:
     val = attr.ib(validator=matches_re("a", re.IGNORECASE, re.match))
Exemplo n.º 13
0
 class ReTester:
     str_match = attr.ib(validator=matches_re("a|ab"))
Exemplo n.º 14
0
 class ReTester(object):
     str_match = attr.ib(validator=matches_re("a"))
class JsonCrudOperation(FromRequest['JsonCrudOperation']):
    operation: str = attr.ib(validator=in_(['create','update']))
    docId: str = attr.ib(validator=matches_re(r'.*\.txt'))
    text: str = attr.ib(validator=instance_of(str))
Exemplo n.º 16
0
def id_attrib_factory():
    return attr.ib(type=str, validator=[has_length(10), matches_re(RE_UUID)])