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

Function test_struct

python/pyfory/tests/test_struct.py:171–200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

169
170
171def 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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected