MCPcopy
hub / github.com/danielgtaylor/python-betterproto / test_dict_casing

Function test_dict_casing

tests/test_features.py:225–265  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

223
224
225def test_dict_casing():
226 @dataclass
227 class CasingTest(betterproto.Message):
228 pascal_case: int = betterproto.int32_field(1)
229 camel_case: int = betterproto.int32_field(2)
230 snake_case: int = betterproto.int32_field(3)
231 kabob_case: int = betterproto.int32_field(4)
232
233 # Parsing should accept almost any input
234 test = CasingTest().from_dict(
235 {"PascalCase": 1, "camelCase": 2, "snake_case": 3, "kabob-case": 4}
236 )
237
238 assert test == CasingTest(1, 2, 3, 4)
239
240 # Serializing should be strict.
241 assert test.to_dict() == {
242 "pascalCase": 1,
243 "camelCase": 2,
244 "snakeCase": 3,
245 "kabobCase": 4,
246 }
247 assert test.to_pydict() == {
248 "pascalCase": 1,
249 "camelCase": 2,
250 "snakeCase": 3,
251 "kabobCase": 4,
252 }
253
254 assert test.to_dict(casing=betterproto.Casing.SNAKE) == {
255 "pascal_case": 1,
256 "camel_case": 2,
257 "snake_case": 3,
258 "kabob_case": 4,
259 }
260 assert test.to_pydict(casing=betterproto.Casing.SNAKE) == {
261 "pascal_case": 1,
262 "camel_case": 2,
263 "snake_case": 3,
264 "kabob_case": 4,
265 }
266
267
268def test_optional_flag():

Callers

nothing calls this directly

Calls 4

CasingTestClass · 0.85
to_pydictMethod · 0.80
from_dictMethod · 0.45
to_dictMethod · 0.45

Tested by

no test coverage detected