()
| 91 | |
| 92 | |
| 93 | def test_enum_as_int_json(): |
| 94 | class TestEnum(betterproto.Enum): |
| 95 | ZERO = 0 |
| 96 | ONE = 1 |
| 97 | |
| 98 | @dataclass |
| 99 | class Foo(betterproto.Message): |
| 100 | bar: TestEnum = betterproto.enum_field(1) |
| 101 | |
| 102 | # JSON strings are supported, but ints should still be supported too. |
| 103 | foo = Foo().from_dict({"bar": 1}) |
| 104 | assert foo.bar == TestEnum.ONE |
| 105 | |
| 106 | # Plain-ol'-ints should serialize properly too. |
| 107 | foo.bar = 1 |
| 108 | assert foo.to_dict() == {"bar": "ONE"} |
| 109 | |
| 110 | # Similar expectations for pydict |
| 111 | foo = Foo().from_pydict({"bar": 1}) |
| 112 | assert foo.bar == TestEnum.ONE |
| 113 | assert foo.to_pydict() == {"bar": TestEnum.ONE} |
| 114 | |
| 115 | |
| 116 | def test_unknown_fields(): |
nothing calls this directly
no test coverage detected