Tests serialization of nested functions.
()
| 79 | |
| 80 | |
| 81 | def test_nested_functions_serialization(): |
| 82 | """Tests serialization of nested functions.""" |
| 83 | fory = pyfory.Fory( |
| 84 | xlang=False, |
| 85 | compatible=False, |
| 86 | ) |
| 87 | |
| 88 | # Register the necessary types |
| 89 | fory.register_type(tuple) |
| 90 | fory.register_type(list) |
| 91 | # dict is already registered by default with MapSerializer |
| 92 | |
| 93 | def outer_function(x): |
| 94 | def inner_function(y): |
| 95 | return x + y |
| 96 | |
| 97 | return inner_function |
| 98 | |
| 99 | # Create a nested function |
| 100 | nested_func = outer_function(10) |
| 101 | fory.register_type(type(nested_func)) |
| 102 | |
| 103 | serialized = fory.serialize(nested_func) |
| 104 | deserialized = fory.deserialize(serialized) |
| 105 | |
| 106 | assert nested_func(5) == deserialized(5) |
| 107 | |
| 108 | |
| 109 | def test_local_class_serialization(): |
nothing calls this directly
no test coverage detected