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

Function test_regular_functions_serialization

python/pyfory/tests/test_function.py:49–78  ·  view source on GitHub ↗

Tests serialization of regular functions.

()

Source from the content-addressed store, hash-verified

47
48
49def test_regular_functions_serialization():
50 """Tests serialization of regular functions."""
51 fory = pyfory.Fory(
52 xlang=False,
53 compatible=False,
54 )
55 test_input = 5
56
57 def add_one(x):
58 return x + 1
59
60 def complex_function(a, b, c=10):
61 """A more complex function with default arguments."""
62 return a * b + c
63
64 # Test regular function
65 fory.register_type(type(add_one))
66 serialized = fory.serialize(add_one)
67 deserialized = fory.deserialize(serialized)
68 assert add_one(test_input) == deserialized(test_input)
69
70 # Register the necessary types for complex functions
71 fory.register_type(tuple)
72 fory.register_type(list)
73 # dict is already registered by default with MapSerializer
74
75 # Test complex function
76 serialized = fory.serialize(complex_function)
77 deserialized = fory.deserialize(serialized)
78 assert complex_function(2, 3) == deserialized(2, 3)
79
80
81def test_nested_functions_serialization():

Callers

nothing calls this directly

Calls 6

register_typeMethod · 0.95
serializeMethod · 0.95
deserializeMethod · 0.95
add_oneFunction · 0.85
complex_functionFunction · 0.85
ForyMethod · 0.45

Tested by

no test coverage detected