()
| 677 | |
| 678 | |
| 679 | def test_sort_fields(): |
| 680 | @dataclass |
| 681 | class TestClass: |
| 682 | f1: pyfory.Int32 |
| 683 | f2: List[pyfory.Int16] |
| 684 | f3: Dict[str, pyfory.Float64] |
| 685 | f4: str |
| 686 | f5: pyfory.Float32 |
| 687 | f6: bytes |
| 688 | f7: bool |
| 689 | f8: Any |
| 690 | f9: Dict[pyfory.Int32, pyfory.Float64] |
| 691 | f10: List[str] |
| 692 | f11: pyfory.Int8 |
| 693 | f12: pyfory.Int64 |
| 694 | f13: pyfory.Float64 |
| 695 | f14: Set[pyfory.Int32] |
| 696 | f15: datetime.datetime |
| 697 | |
| 698 | fory = Fory(xlang=True, compatible=False, ref=True) |
| 699 | serializer = DataClassSerializer(fory.type_resolver, TestClass) |
| 700 | # Sorting order: |
| 701 | # 1. Non-compressed primitives (compress=0) by -size, then ascending type_id, then name: |
| 702 | # Float64(8), Float32(4), bool(1), Int8(1) => f13, f5, f7, f11 |
| 703 | # 2. Compressed primitives (compress=1) by -size, then name: |
| 704 | # Int64(8), Int32(4) => f12, f1 |
| 705 | # 3. All non-primitives directly by field identifier. |
| 706 | assert serializer._field_names == [ |
| 707 | "f13", |
| 708 | "f5", |
| 709 | "f7", |
| 710 | "f11", |
| 711 | "f12", |
| 712 | "f1", |
| 713 | "f10", |
| 714 | "f14", |
| 715 | "f15", |
| 716 | "f2", |
| 717 | "f3", |
| 718 | "f4", |
| 719 | "f6", |
| 720 | "f8", |
| 721 | "f9", |
| 722 | ] |
| 723 | |
| 724 | |
| 725 | def test_tagged_non_primitive_fields_sort_by_identifier(): |
nothing calls this directly
no test coverage detected