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

Method test_pattern

tests/unit/test_constraints.py:483–496  ·  view source on GitHub ↗
(self, proto, pattern, good, bad)

Source from the content-addressed store, hash-verified

481 ],
482 )
483 def test_pattern(self, proto, pattern, good, bad):
484 class Ex(msgspec.Struct):
485 x: Annotated[str, Meta(pattern=pattern)]
486
487 dec = proto.Decoder(Ex)
488
489 for x in good:
490 assert dec.decode(proto.encode(Ex(x))).x == x
491
492 err_msg = f"Expected `str` matching regex {pattern!r} - at `$.x`"
493 for x in bad:
494 with pytest.raises(msgspec.ValidationError) as rec:
495 dec.decode(proto.encode(Ex(x)))
496 assert str(rec.value) == err_msg
497
498 @pytest.mark.parametrize(
499 "meta, good, bad",

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.80
ExClass · 0.70

Tested by

no test coverage detected