예제 #1
0
파일: base.py 프로젝트: phlax/playground
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),
                   ])
예제 #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])
예제 #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)
예제 #4
0
 def test_repr(self):
     """
     __repr__ is meaningful.
     """
     assert repr(matches_re("a")).startswith(
         "<matches_re validator for pattern"
     )
예제 #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)
예제 #6
0
 class ValidatedAttribute:
     x = attr.ib()
     y = attr.ib(validator=[instance_of(str), matches_re("foo.*qux")])
예제 #7
0
파일: base.py 프로젝트: phlax/playground
class ContainerDeleteAttribs(ValidatingAttribs):
    id = attr.ib(type=str, validator=[has_length(10), matches_re(RE_UUID)])
예제 #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)))
예제 #9
0
 def test_accepts_all_valid_func(self, func):
     """
     Every valid match function is accepted.
     """
     matches_re("a", func=func)
예제 #10
0
 class SearchTester:
     val = attr.ib(validator=matches_re("a", 0, re.search))
예제 #11
0
 class RePatternTester:
     val = attr.ib(validator=matches_re(pattern))
예제 #12
0
 class MatchTester:
     val = attr.ib(validator=matches_re("a", re.IGNORECASE, re.match))
예제 #13
0
 class ReTester:
     str_match = attr.ib(validator=matches_re("a|ab"))
예제 #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))
예제 #16
0
def id_attrib_factory():
    return attr.ib(type=str, validator=[has_length(10), matches_re(RE_UUID)])