Tests serialization of regular functions.
()
| 47 | |
| 48 | |
| 49 | def 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 | |
| 81 | def test_nested_functions_serialization(): |
nothing calls this directly
no test coverage detected