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

Function test_dataclass_serialize

python/pyfory/tests/test_class_serializer.py:342–369  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

340
341
342def test_dataclass_serialize():
343 fory = Fory(xlang=False, ref=True, strict=False, compatible=False)
344
345 # serialize global class
346 @dataclass
347 class LocalPerson:
348 name: str
349 age: int
350
351 def f(self, x):
352 return self.age * x
353
354 @classmethod
355 def g(cls, x):
356 return 10 * x
357
358 @staticmethod
359 def h(x):
360 return 10 * x
361
362 for cls in [LocalPerson, LocalPerson]:
363 assert str(fory.loads(fory.dumps(cls))("Bob", 25)) == str(cls("Bob", 25))
364 # serialize global class instance method
365 assert fory.loads(fory.dumps(cls("Bob", 20).f))(10) == 200
366 # serialize global class class method
367 assert fory.loads(fory.dumps(cls.g))(10) == 100
368 # serialize global class static method
369 assert fory.loads(fory.dumps(cls.h))(10) == 100

Callers

nothing calls this directly

Calls 3

loadsMethod · 0.95
dumpsMethod · 0.95
ForyClass · 0.90

Tested by

no test coverage detected