Skip to content

Commit daefdfa

Browse files
authored
Merge pull request #23 from Query-farm/test/example-functions-serialization
Add tests for example function Arrow serialization
2 parents c8a162f + 048da88 commit daefdfa

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

tests/test_argument_spec.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,101 @@ class FunctionWithExplicit(TableInOutFunction):
676676
assert specs[0].arrow_type == pa.int32()
677677

678678

679+
class TestExampleFunctionsSerialization:
680+
"""Test that example functions can be serialized and deserialized."""
681+
682+
def test_scalar_functions(self) -> None:
683+
"""Test serialization of scalar example functions."""
684+
from vgi.examples.scalar import (
685+
AddColumnsFunction,
686+
DoubleColumnFunction,
687+
UpperCaseFunction,
688+
)
689+
690+
for func_cls in [DoubleColumnFunction, AddColumnsFunction, UpperCaseFunction]:
691+
specs = extract_argument_specs(func_cls)
692+
assert len(specs) > 0, f"{func_cls.__name__} should have arguments"
693+
694+
# All specs should have non-null arrow_type
695+
for spec in specs:
696+
assert spec.arrow_type is not None, (
697+
f"{func_cls.__name__}.{spec.name} has null arrow_type"
698+
)
699+
700+
# Schema roundtrip should work
701+
schema = argument_specs_to_schema(specs)
702+
restored = schema_to_argument_specs(schema)
703+
assert len(restored) == len(specs)
704+
705+
def test_table_functions(self) -> None:
706+
"""Test serialization of table example functions."""
707+
from vgi.examples.table import (
708+
ConstantTableFunction,
709+
RangeFunction,
710+
SequenceFunction,
711+
)
712+
713+
for func_cls in [SequenceFunction, RangeFunction, ConstantTableFunction]:
714+
specs = extract_argument_specs(func_cls)
715+
assert len(specs) > 0, f"{func_cls.__name__} should have arguments"
716+
717+
# All specs should have non-null arrow_type
718+
for spec in specs:
719+
assert spec.arrow_type is not None, (
720+
f"{func_cls.__name__}.{spec.name} has null arrow_type"
721+
)
722+
723+
# Schema roundtrip should work
724+
schema = argument_specs_to_schema(specs)
725+
restored = schema_to_argument_specs(schema)
726+
assert len(restored) == len(specs)
727+
728+
def test_table_in_out_functions(self) -> None:
729+
"""Test serialization of table-in-out example functions."""
730+
from vgi.examples.table_in_out import (
731+
BufferInputFunction,
732+
EchoFunction,
733+
RepeatInputsFunction,
734+
SumAllColumnsFunction,
735+
)
736+
737+
for func_cls in [
738+
EchoFunction,
739+
BufferInputFunction,
740+
RepeatInputsFunction,
741+
SumAllColumnsFunction,
742+
]:
743+
specs = extract_argument_specs(func_cls)
744+
assert len(specs) > 0, f"{func_cls.__name__} should have arguments"
745+
746+
# All specs should have non-null arrow_type
747+
for spec in specs:
748+
assert spec.arrow_type is not None, (
749+
f"{func_cls.__name__}.{spec.name} has null arrow_type"
750+
)
751+
752+
# Schema roundtrip should work
753+
schema = argument_specs_to_schema(specs)
754+
restored = schema_to_argument_specs(schema)
755+
assert len(restored) == len(specs)
756+
757+
def test_range_function_step_uses_int32(self) -> None:
758+
"""Verify RangeFunction.step uses explicit int32 arrow_type."""
759+
from vgi.examples.table import RangeFunction
760+
761+
specs = extract_argument_specs(RangeFunction)
762+
step_spec = next(s for s in specs if s.name == "step")
763+
assert step_spec.arrow_type == pa.int32()
764+
765+
def test_double_column_uses_explicit_utf8(self) -> None:
766+
"""Verify DoubleColumnFunction.column uses explicit utf8 arrow_type."""
767+
from vgi.examples.scalar import DoubleColumnFunction
768+
769+
specs = extract_argument_specs(DoubleColumnFunction)
770+
column_spec = next(s for s in specs if s.name == "column")
771+
assert column_spec.arrow_type == pa.utf8()
772+
773+
679774
class TestArgumentSpecRepr:
680775
"""Test ArgumentSpec __repr__ method."""
681776

0 commit comments

Comments
 (0)