multipleOf for floats will always have precisions issues. This check just ensures that _some_ cases work. See https://github.com/json-schema-org/json-schema-spec/issues/312 for more info.
(self, proto)
| 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 |
| 406 | just ensures that _some_ cases work. See |
| 407 | https://github.com/json-schema-org/json-schema-spec/issues/312 for more |
| 408 | info.""" |
| 409 | |
| 410 | class Ex(msgspec.Struct): |
| 411 | x: Annotated[float, Meta(multiple_of=0.1)] |
| 412 | |
| 413 | dec = proto.Decoder(Ex) |
| 414 | |
| 415 | for x in [0, 0.0, 0.1, -0.1, 0.2, -0.2]: |
| 416 | assert dec.decode(proto.encode(Ex(x))).x == x |
| 417 | |
| 418 | err_msg = r"Expected `float` that's a multiple of 0.1 - at `\$.x`" |
| 419 | for x in [0.01, -0.15]: |
| 420 | with pytest.raises(msgspec.ValidationError, match=err_msg): |
| 421 | dec.decode(proto.encode(Ex(x))) |
| 422 | |
| 423 | @pytest.mark.parametrize( |
| 424 | "meta, good, bad", |