MCPcopy Create free account
hub / github.com/apache/fory / test_named_simple_struct

Function test_named_simple_struct

python/pyfory/tests/xlang_test_main.py:504–535  ·  view source on GitHub ↗

Test named simple struct serialization.

()

Source from the content-addressed store, hash-verified

502
503
504def test_named_simple_struct():
505 """Test named simple struct serialization."""
506 data_file = get_data_file()
507 with open(data_file, "rb") as f:
508 data_bytes = f.read()
509
510 fory = pyfory.Fory(xlang=True, compatible=True)
511 fory.register_type(Color, name="demo.color")
512 fory.register_type(Item, name="demo.item")
513 fory.register_type(SimpleStruct, name="demo.simple_struct")
514
515 expected = SimpleStruct(
516 f1={1: 1.0, 2: 2.0},
517 f2=39,
518 f3=Item(name="item"),
519 f4="f4",
520 f5=Color.White,
521 f6=["f6"],
522 f7=40,
523 f8=41,
524 last=42,
525 )
526
527 obj = fory.deserialize(data_bytes)
528 debug_print(f"Deserialized: {obj}")
529 assert obj == expected, f"Mismatch: {obj} != {expected}"
530
531 new_bytes = fory.serialize(obj)
532 assert fory.deserialize(new_bytes) == expected
533
534 with open(data_file, "wb") as f:
535 f.write(new_bytes)
536
537
538def test_struct_evolving_override():

Callers

nothing calls this directly

Calls 10

register_typeMethod · 0.95
deserializeMethod · 0.95
serializeMethod · 0.95
get_data_fileFunction · 0.70
SimpleStructClass · 0.70
ItemClass · 0.70
debug_printFunction · 0.70
readMethod · 0.65
writeMethod · 0.65
ForyMethod · 0.45

Tested by

no test coverage detected