MCPcopy Index your code
hub / github.com/danielgtaylor/python-betterproto / test_json_casing

Function test_json_casing

tests/test_features.py:194–222  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

192
193
194def test_json_casing():
195 @dataclass
196 class CasingTest(betterproto.Message):
197 pascal_case: int = betterproto.int32_field(1)
198 camel_case: int = betterproto.int32_field(2)
199 snake_case: int = betterproto.int32_field(3)
200 kabob_case: int = betterproto.int32_field(4)
201
202 # Parsing should accept almost any input
203 test = CasingTest().from_dict(
204 {"PascalCase": 1, "camelCase": 2, "snake_case": 3, "kabob-case": 4}
205 )
206
207 assert test == CasingTest(1, 2, 3, 4)
208
209 # Serializing should be strict.
210 assert json.loads(test.to_json()) == {
211 "pascalCase": 1,
212 "camelCase": 2,
213 "snakeCase": 3,
214 "kabobCase": 4,
215 }
216
217 assert json.loads(test.to_json(casing=betterproto.Casing.SNAKE)) == {
218 "pascal_case": 1,
219 "camel_case": 2,
220 "snake_case": 3,
221 "kabob_case": 4,
222 }
223
224
225def test_dict_casing():

Callers

nothing calls this directly

Calls 3

CasingTestClass · 0.85
to_jsonMethod · 0.80
from_dictMethod · 0.45

Tested by

no test coverage detected