Skip to content

Implement Unit Tests for Engine to Python Native Format Conversion #185

Open
@badmonster0

Description

@badmonster0

Enhancement

Add Unit test to convert.py for make_engine_value_converter

Objective:

Develop unit tests to validate the functionality of the make_engine_value_converter function, ensuring it accurately converts engine-compatible data structures back into Python native data types.

Background:

This module provide conversions between two data formats:

  • Values in Python native data types
  • Values in data structure exchangeable with cocoindex core engine (in Rust)
  • Related issue for conversion from Python to Engine Format

The key difference is about how they handle Struct type

  • In Python native data formats, it's represented by a dataclass (see the doc). Example: Order(order_id='O123', name='mixed nuts', price=25.0)

  • In the exchangeable format with the core engine, it's a list of all fields. Example: ['O123', 'mixed nuts', 25.0]

  • In the engine->Python native converter, it's possible that a Struct type in engine and Python native have different fields (can be: Python dataclass has more fields, has less fields, has fields in different orders). We should initialize all matched fields (by field names, not order), and leave unmatched fields with their default values.

Scope:

  • The test need to cover different types:
    • Various basic types, struct types and collection types as listed in the doc
    • Composition of various types, e.g. list of struct, struct with list fields, struct with struct fields

Hint: make_engine_value_converter() also needs to take an engine data type (in dict[str, Any] type) as argument. A convenient way to construct it is calling typing.encode_enriched_type(), and get the 'type' in the result (i.e. ['type']).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions