|
| 1 | +import pytest |
| 2 | + |
| 3 | +from cattrs import BaseConverter, Converter |
| 4 | + |
| 5 | +HETERO_TUPLE = tuple[int, str, float, int, str, float] |
| 6 | +HETERO_RAW = [1.0, 2, "3", 4.0, 5, "6"] |
| 7 | +HETERO_VALUE = (1, "2", 3.0, 4, "5", 6.0) |
| 8 | +HOMO_TUPLE = tuple[int, ...] |
| 9 | +HOMO_RAW = ["1", 2, 3.0, 4, 5.0, "6"] |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter]) |
| 13 | +@pytest.mark.parametrize("detailed_validation", [True, False]) |
| 14 | +def test_structure_hetero_tuple(benchmark, converter_cls, detailed_validation): |
| 15 | + """Benchmark steady-state heterogeneous tuple structuring.""" |
| 16 | + c = converter_cls(detailed_validation=detailed_validation) |
| 17 | + |
| 18 | + benchmark(c.structure, HETERO_RAW, HETERO_TUPLE) |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter]) |
| 22 | +def test_unstructure_hetero_tuple(benchmark, converter_cls): |
| 23 | + """Benchmark heterogeneous tuple unstructuring.""" |
| 24 | + c = converter_cls() |
| 25 | + |
| 26 | + benchmark(c.unstructure, HETERO_VALUE, HETERO_TUPLE) |
| 27 | + |
| 28 | + |
| 29 | +@pytest.mark.parametrize("converter_cls", [BaseConverter, Converter]) |
| 30 | +@pytest.mark.parametrize("detailed_validation", [True, False]) |
| 31 | +def test_structure_homo_tuple(benchmark, converter_cls, detailed_validation): |
| 32 | + """Benchmark homogeneous tuple structuring.""" |
| 33 | + c = converter_cls(detailed_validation=detailed_validation) |
| 34 | + |
| 35 | + benchmark(c.structure, HOMO_RAW, HOMO_TUPLE) |
0 commit comments