()
| 169 | |
| 170 | |
| 171 | def test_struct(): |
| 172 | fory = Fory(xlang=True, compatible=False, ref=True) |
| 173 | fory.register_type(SimpleObject, name="SimpleObject") |
| 174 | fory.register_type(ComplexObject, name="example.ComplexObject") |
| 175 | o = SimpleObject(f1={1: 1.0 / 3}) |
| 176 | assert ser_de(fory, o) == o |
| 177 | |
| 178 | o = ComplexObject( |
| 179 | f1="str", |
| 180 | f2={"k1": -1, "k2": [1, 2]}, |
| 181 | f3=2**7 - 1, |
| 182 | f4=2**15 - 1, |
| 183 | f5=2**31 - 1, |
| 184 | f6=2**63 - 1, |
| 185 | f7=1.0 / 2, |
| 186 | f8=2.0 / 3, |
| 187 | f9=[1, 2], |
| 188 | f10={1: 1.0 / 3, 100: 2 / 7.0}, |
| 189 | ) |
| 190 | assert ser_de(fory, o) == o |
| 191 | with pytest.raises(AssertionError): |
| 192 | assert ser_de(fory, ComplexObject(f7=1.0 / 3)) == ComplexObject(f7=1.0 / 3) |
| 193 | with pytest.raises(OverflowError): |
| 194 | assert ser_de(fory, ComplexObject(f3=2**8)) == ComplexObject(f3=2**8) |
| 195 | with pytest.raises(OverflowError): |
| 196 | assert ser_de(fory, ComplexObject(f4=2**16)) == ComplexObject(f4=2**16) |
| 197 | with pytest.raises(OverflowError): |
| 198 | assert ser_de(fory, ComplexObject(f5=2**32)) == ComplexObject(f5=2**32) |
| 199 | with pytest.raises(OverflowError): |
| 200 | assert ser_de(fory, ComplexObject(f6=2**64)) == ComplexObject(f6=2**64) |
| 201 | |
| 202 | |
| 203 | @dataclass |
nothing calls this directly
no test coverage detected