File tree Expand file tree Collapse file tree 2 files changed +26
-25
lines changed Expand file tree Collapse file tree 2 files changed +26
-25
lines changed Original file line number Diff line number Diff line change 11import dataclasses
22import datetime
3- from typing import TypedDict , NamedTuple
3+ from typing import TypedDict , NamedTuple , Literal
44
55import numpy as np
66from numpy .typing import NDArray
77import pytest
88
9+ from cocoindex .typing import Vector
910from cocoindex .engine_object import dump_engine_object , load_engine_object
1011
1112# Optional Pydantic support for testing
@@ -192,6 +193,30 @@ class TestClass:
192193 pass # Expected behavior
193194
194195
196+ def test_dump_vector_type_annotation_with_dim () -> None :
197+ """Test dumping a vector type annotation with a specified dimension."""
198+ expected_dump = {
199+ "type" : {
200+ "kind" : "Vector" ,
201+ "element_type" : {"kind" : "Float32" },
202+ "dimension" : 3 ,
203+ }
204+ }
205+ assert dump_engine_object (Vector [np .float32 , Literal [3 ]]) == expected_dump
206+
207+
208+ def test_dump_vector_type_annotation_no_dim () -> None :
209+ """Test dumping a vector type annotation with no dimension."""
210+ expected_dump_no_dim = {
211+ "type" : {
212+ "kind" : "Vector" ,
213+ "element_type" : {"kind" : "Float64" },
214+ "dimension" : None ,
215+ }
216+ }
217+ assert dump_engine_object (Vector [np .float64 ]) == expected_dump_no_dim
218+
219+
195220@pytest .mark .skipif (not PYDANTIC_AVAILABLE , reason = "Pydantic not available" )
196221def test_pydantic_unsupported_type_still_fails () -> None :
197222 """Test that fields with unsupported types still cause errors when missing."""
Original file line number Diff line number Diff line change @@ -1005,30 +1005,6 @@ def test_decode_error_non_nullable_or_non_list_vector() -> None:
10051005 decoder ("not a list" )
10061006
10071007
1008- # def test_dump_vector_type_annotation_with_dim() -> None:
1009- # """Test dumping a vector type annotation with a specified dimension."""
1010- # expected_dump = {
1011- # "type": {
1012- # "kind": "Vector",
1013- # "element_type": {"kind": "Float32"},
1014- # "dimension": 3,
1015- # }
1016- # }
1017- # assert dump_engine_object(Float32VectorType) == expected_dump
1018-
1019-
1020- # def test_dump_vector_type_annotation_no_dim() -> None:
1021- # """Test dumping a vector type annotation with no dimension."""
1022- # expected_dump_no_dim = {
1023- # "type": {
1024- # "kind": "Vector",
1025- # "element_type": {"kind": "Float64"},
1026- # "dimension": None,
1027- # }
1028- # }
1029- # assert dump_engine_object(Float64VectorTypeNoDim) == expected_dump_no_dim
1030-
1031-
10321008def test_full_roundtrip_vector_numeric_types () -> None :
10331009 """Test full roundtrip for numeric vector types using NDArray."""
10341010 value_f32 = np .array ([1.0 , 2.0 , 3.0 ], dtype = np .float32 )
You can’t perform that action at this time.
0 commit comments