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

Function test_nested_optional_fields

python/pyfory/tests/test_struct.py:1128–1146  ·  view source on GitHub ↗
(xlang, compatible)

Source from the content-addressed store, hash-verified

1126@pytest.mark.parametrize("xlang", [False, True])
1127@pytest.mark.parametrize("compatible", [False, True])
1128def test_nested_optional_fields(xlang, compatible):
1129 fory = Fory(xlang=xlang, ref=True, compatible=compatible, strict=False)
1130 if xlang:
1131 fory.register_type(ComplexObject, name="example.ComplexObject")
1132 fory.register_type(NestedOptionalObject, name="example.NestedOptionalObject")
1133
1134 obj_with_none = NestedOptionalObject(f1=None, f2=None, f3="test")
1135 result = ser_de(fory, obj_with_none)
1136 assert result.f1 is None
1137 assert result.f2 is None
1138 assert result.f3 == "test"
1139
1140 complex_obj = ComplexObject(f1="nested", f5=100, f8=3.14)
1141 obj_with_values = NestedOptionalObject(f1=complex_obj, f2={"a": 1, "b": 2}, f3="test")
1142 result = ser_de(fory, obj_with_values)
1143 assert result.f1.f1 == "nested"
1144 assert result.f1.f5 == 100
1145 assert result.f2 == {"a": 1, "b": 2}
1146 assert result.f3 == "test"
1147
1148
1149@dataclass

Callers

nothing calls this directly

Calls 5

register_typeMethod · 0.95
ForyClass · 0.90
ComplexObjectClass · 0.85
ser_deFunction · 0.70

Tested by

no test coverage detected