MCPcopy Index your code
hub / github.com/msgspec/msgspec / test_max_length

Method test_max_length

tests/unit/test_constraints.py:651–662  ·  view source on GitHub ↗
(self, proto, typ)

Source from the content-addressed store, hash-verified

649
650 @pytest.mark.parametrize("typ", [bytes, bytearray, memoryview])
651 def test_max_length(self, proto, typ):
652 class Ex(msgspec.Struct):
653 x: Annotated[typ, Meta(max_length=2)]
654
655 dec = proto.Decoder(Ex)
656
657 for x in [b"", b"xx"]:
658 assert bytes(dec.decode(proto.encode(Ex(x))).x) == x
659
660 err_msg = r"Expected `bytes` of length <= 2 - at `\$.x`"
661 with pytest.raises(msgspec.ValidationError, match=err_msg):
662 dec.decode(proto.encode(Ex(b"xxx")))
663
664 @pytest.mark.parametrize("typ", [bytes, bytearray, memoryview])
665 def test_combinations(self, proto, typ):

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.80
ExClass · 0.70

Tested by

no test coverage detected