Tests serialization of local classes.
()
| 107 | |
| 108 | |
| 109 | def test_local_class_serialization(): |
| 110 | """Tests serialization of local classes.""" |
| 111 | fory = pyfory.Fory( |
| 112 | xlang=False, |
| 113 | compatible=False, |
| 114 | ) |
| 115 | |
| 116 | # Register the necessary types |
| 117 | fory.register_type(tuple) |
| 118 | fory.register_type(list) |
| 119 | # dict is already registered by default with MapSerializer |
| 120 | |
| 121 | def create_local_class(): |
| 122 | from dataclasses import dataclass |
| 123 | |
| 124 | @dataclass |
| 125 | class LocalClass: |
| 126 | value: int |
| 127 | name: str |
| 128 | |
| 129 | return LocalClass(42, "test") |
| 130 | |
| 131 | local_obj = create_local_class() |
| 132 | fory.register_type(type(local_obj)) |
| 133 | |
| 134 | serialized = fory.serialize(local_obj) |
| 135 | deserialized = fory.deserialize(serialized) |
| 136 | |
| 137 | assert local_obj == deserialized |
nothing calls this directly
no test coverage detected