MCPcopy Index your code
hub / github.com/apache/fory / test_lambda_functions_serialization

Function test_lambda_functions_serialization

python/pyfory/tests/test_function.py:21–46  ·  view source on GitHub ↗

Tests serialization of lambda functions.

()

Source from the content-addressed store, hash-verified

19
20
21def test_lambda_functions_serialization():
22 """Tests serialization of lambda functions."""
23 fory = pyfory.Fory(
24 xlang=False,
25 compatible=False,
26 )
27 test_input = 5
28
29 # Register the necessary types
30 fory.register_type(tuple)
31 fory.register_type(list)
32 # dict is already registered by default with MapSerializer
33
34 # Simple lambda
35 simple_lambda = lambda x: x * 2 # noqa: E731
36 fory.register_type(type(simple_lambda))
37 serialized = fory.serialize(simple_lambda)
38 deserialized = fory.deserialize(serialized)
39 assert simple_lambda(test_input) == deserialized(test_input)
40
41 # Complex lambda with closure
42 multiplier = 3
43 closure_lambda = lambda x: x * multiplier # noqa: E731
44 serialized = fory.serialize(closure_lambda)
45 deserialized = fory.deserialize(serialized)
46 assert closure_lambda(test_input) == deserialized(test_input)
47
48
49def test_regular_functions_serialization():

Callers

nothing calls this directly

Calls 4

register_typeMethod · 0.95
serializeMethod · 0.95
deserializeMethod · 0.95
ForyMethod · 0.45

Tested by

no test coverage detected