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

Method test_multiple_of

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

Source from the content-addressed store, hash-verified

302 dec.decode(proto.encode(Ex(x)))
303
304 def test_multiple_of(self, proto):
305 good = [-(2**64), -2, 0, 2, 40, 2**63 + 2, 2**65]
306 bad = [1, -1, 2**63 + 1, 2**65 + 1]
307 if proto is msgspec.msgpack:
308 # msgpack only supports int64/uint64 values
309 good = [i for i in good if -(2**63) - 1 <= i <= 2**64]
310 bad = [i for i in bad if -(2**63) - 1 <= i <= 2**64]
311
312 class Ex(msgspec.Struct):
313 x: Annotated[int, Meta(multiple_of=2)]
314
315 dec = proto.Decoder(Ex)
316
317 for x in good:
318 assert dec.decode(proto.encode(Ex(x))).x == x
319
320 err_msg = r"Expected `int` that's a multiple of 2 - at `\$.x`"
321 for x in bad:
322 with pytest.raises(msgspec.ValidationError, match=err_msg):
323 dec.decode(proto.encode(Ex(x)))
324
325 @pytest.mark.parametrize(
326 "meta, good, bad",

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.80
ExClass · 0.70

Tested by

no test coverage detected