MCPcopy Create free account
hub / github.com/msgspec/msgspec / test_max_length

Method test_max_length

tests/unit/test_constraints.py:461–473  ·  view source on GitHub ↗
(self, proto)

Source from the content-addressed store, hash-verified

459 dec.decode(proto.encode(Ex(x)))
460
461 def test_max_length(self, proto):
462 class Ex(msgspec.Struct):
463 x: Annotated[str, Meta(max_length=2)]
464
465 dec = proto.Decoder(Ex)
466
467 for x in ["", "xx", "𝄞x"]:
468 assert dec.decode(proto.encode(Ex(x))).x == x
469
470 err_msg = r"Expected `str` of length <= 2 - at `\$.x`"
471 for x in ["xxx", "𝄞xx"]:
472 with pytest.raises(msgspec.ValidationError, match=err_msg):
473 dec.decode(proto.encode(Ex(x)))
474
475 @pytest.mark.parametrize(
476 "pattern, good, bad",

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.80
ExClass · 0.70

Tested by

no test coverage detected