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

Function test_local_class_serialization

python/pyfory/tests/test_function.py:109–137  ·  view source on GitHub ↗

Tests serialization of local classes.

()

Source from the content-addressed store, hash-verified

107
108
109def 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

Callers

nothing calls this directly

Calls 5

register_typeMethod · 0.95
serializeMethod · 0.95
deserializeMethod · 0.95
create_local_classFunction · 0.70
ForyMethod · 0.45

Tested by

no test coverage detected