(xlang, compatible)
| 1126 | @pytest.mark.parametrize("xlang", [False, True]) |
| 1127 | @pytest.mark.parametrize("compatible", [False, True]) |
| 1128 | def 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 |
nothing calls this directly
no test coverage detected