(self, proto)
| 817 | dec.decode(msgspec.msgpack.encode(key)) |
| 818 | |
| 819 | def test_enum_missing(self, proto): |
| 820 | class Ex(enum.Enum): |
| 821 | A = "a" |
| 822 | B = "b" |
| 823 | |
| 824 | @classmethod |
| 825 | def _missing_(cls, val): |
| 826 | if val == "return-A": |
| 827 | return cls.A |
| 828 | elif val == "return-B": |
| 829 | return cls.B |
| 830 | elif val == "error": |
| 831 | raise ValueError("oh no!") |
| 832 | else: |
| 833 | return None |
| 834 | |
| 835 | dec = proto.Decoder(Ex) |
| 836 | |
| 837 | def roundtrip(msg): |
| 838 | return dec.decode(proto.encode(msg)) |
| 839 | |
| 840 | assert roundtrip("a") is Ex.A |
| 841 | assert roundtrip("return-A") is Ex.A |
| 842 | assert roundtrip("return-B") is Ex.B |
| 843 | with pytest.raises(ValidationError, match="Invalid enum value 'error'"): |
| 844 | roundtrip("error") |
| 845 | with pytest.raises(ValidationError, match="Invalid enum value 'other'"): |
| 846 | roundtrip("other") |
| 847 | |
| 848 | |
| 849 | class TestLiterals: |
nothing calls this directly
no test coverage detected