MCPcopy Create free account
hub / github.com/apache/fory / test_basic

Function test_basic

python/pyfory/format/tests/test_encoder.py:184–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

182
183
184def test_basic():
185 cls = pyfory.record_class_factory("TestBasic", ["f" + str(i) for i in range(1, 6)])
186 s = schema(
187 [
188 field("f1", utf8()),
189 field("f2", binary()),
190 field("f3", boolean()),
191 field("f4", date32()),
192 field("f5", timestamp()),
193 ]
194 )
195 from datetime import date, datetime
196
197 obj = cls(f1="str", f2=b"123456", f3=True, f4=date(1970, 1, 1), f5=datetime.now())
198 print("obj", obj)
199 encoder = pyfory.create_row_encoder(s)
200 row = encoder.to_row(obj)
201 print("row", row)
202 new_obj = encoder.from_row(row)
203 print("new_obj", new_obj)
204 print("new_obj", type(new_obj))
205 assert new_obj.f1 == obj.f1
206 assert new_obj.f2 == obj.f2
207 assert new_obj.f3 == obj.f3
208 assert new_obj.f4 == obj.f4
209 # Timestamp precision may differ
210 assert abs((new_obj.f5 - obj.f5).total_seconds()) < 1
211
212
213@dataclass

Callers

nothing calls this directly

Calls 10

schemaFunction · 0.85
utf8Function · 0.85
date32Function · 0.85
dateFunction · 0.85
from_rowMethod · 0.80
fieldFunction · 0.50
binaryFunction · 0.50
booleanFunction · 0.50
timestampFunction · 0.50
to_rowMethod · 0.45

Tested by

no test coverage detected