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

Function test_optional_fields

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

Source from the content-addressed store, hash-verified

1087@pytest.mark.parametrize("xlang", [False, True])
1088@pytest.mark.parametrize("compatible", [False, True])
1089def test_optional_fields(xlang, compatible):
1090 fory = Fory(xlang=xlang, ref=True, compatible=compatible, strict=False)
1091 if xlang:
1092 fory.register_type(OptionalFieldsObject, name="example.OptionalFieldsObject")
1093
1094 obj_with_none = OptionalFieldsObject(f1=None, f2=None, f3=None, f4=42, f5="test")
1095 result = ser_de(fory, obj_with_none)
1096 assert result.f1 is None
1097 assert result.f2 is None
1098 assert result.f3 is None
1099 assert result.f4 == 42
1100 assert result.f5 == "test"
1101
1102 obj_with_values = OptionalFieldsObject(f1=100, f2="hello", f3=[1, 2, 3], f4=42, f5="test")
1103 result = ser_de(fory, obj_with_values)
1104 assert result.f1 == 100
1105 assert result.f2 == "hello"
1106 assert result.f3 == [1, 2, 3]
1107 assert result.f4 == 42
1108 assert result.f5 == "test"
1109
1110 obj_mixed = OptionalFieldsObject(f1=100, f2=None, f3=[1, 2, 3], f4=42, f5="test")
1111 result = ser_de(fory, obj_mixed)
1112 assert result.f1 == 100
1113 assert result.f2 is None
1114 assert result.f3 == [1, 2, 3]
1115 assert result.f4 == 42
1116 assert result.f5 == "test"
1117
1118
1119@dataclass

Callers

nothing calls this directly

Calls 4

register_typeMethod · 0.95
ForyClass · 0.90
ser_deFunction · 0.70

Tested by

no test coverage detected