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

Method test_lax_int_enum

tests/unit/test_common.py:4428–4441  ·  view source on GitHub ↗
(self, proto)

Source from the content-addressed store, hash-verified

4426 proto.decode(msg, type=typ, strict=False)
4427
4428 def test_lax_int_enum(self, proto):
4429 class Ex(enum.IntEnum):
4430 x = 1
4431 y = -2
4432
4433 def roundtrip(msg):
4434 return proto.decode(proto.encode(msg), type=Ex, strict=False)
4435
4436 assert roundtrip("1") is Ex.x
4437 assert roundtrip("-2") is Ex.y
4438 with pytest.raises(ValidationError, match="Invalid enum value 3"):
4439 roundtrip("3")
4440 with pytest.raises(ValidationError, match="Expected `int`, got `str`"):
4441 roundtrip("A")
4442
4443 def test_lax_int_literal(self, proto):
4444 typ = Literal[1, -2]

Callers

nothing calls this directly

Calls 1

roundtripFunction · 0.85

Tested by

no test coverage detected