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

Function test_classmethod_serialization

python/pyfory/tests/test_method.py:197–223  ·  view source on GitHub ↗

Standalone test for classmethod serialization - reproduces the original error.

()

Source from the content-addressed store, hash-verified

195
196
197def test_classmethod_serialization():
198 """Standalone test for classmethod serialization - reproduces the original error."""
199 fory = pyfory.Fory(xlang=False, strict=False, ref=True, compatible=False)
200
201 class A:
202 @classmethod
203 def f(cls):
204 pass
205
206 @staticmethod
207 def g():
208 return A
209
210 method = A.f
211 serialized = fory.serialize(method)
212 deserialized = fory.deserialize(serialized)
213
214 assert isinstance(deserialized, type(method))
215 # Check that the class names are the same (the classes might be different instances due to deserialization)
216 assert deserialized.__self__.__name__ == method.__self__.__name__
217 assert deserialized.__func__.__name__ == method.__func__.__name__
218
219 # Most importantly, check that the deserialized method is callable and has the same behavior
220 # Both should return None for this test case
221 original_result = method()
222 deserialized_result = deserialized()
223 assert original_result == deserialized_result
224
225
226def test_staticmethod_serialization():

Callers

nothing calls this directly

Calls 3

serializeMethod · 0.95
deserializeMethod · 0.95
ForyMethod · 0.45

Tested by

no test coverage detected