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

Method test_bounds

tests/unit/test_constraints.py:388–402  ·  view source on GitHub ↗
(self, proto, name, bound)

Source from the content-addressed store, hash-verified

386 @pytest.mark.parametrize("name", ["ge", "gt", "le", "lt"])
387 @pytest.mark.parametrize("bound", [1.5, -1.5, 10.0])
388 def test_bounds(self, proto, name, bound):
389 class Ex(msgspec.Struct):
390 x: Annotated[float, Meta(**{name: bound})]
391
392 dec = proto.Decoder(Ex)
393
394 good, bad, op = self.get_bounds_cases(name, bound)
395
396 for x in good:
397 assert dec.decode(proto.encode(Ex(x))).x == x
398
399 err_msg = rf"Expected `float` {op} {bound} - at `\$.x`"
400 for x in bad:
401 with pytest.raises(msgspec.ValidationError, match=err_msg):
402 dec.decode(proto.encode(Ex(x)))
403
404 def test_multiple_of(self, proto):
405 """multipleOf for floats will always have precisions issues. This check

Callers

nothing calls this directly

Calls 3

get_bounds_casesMethod · 0.95
decodeMethod · 0.80
ExClass · 0.70

Tested by

no test coverage detected