11"""Generic tests for TableFunctionGenerator behavior."""
22
3+ from __future__ import annotations
4+
35import pyarrow as pa
46import pytest
57import structlog
68
9+ from tests .utils import make_schema
710from vgi .function import Arguments , Invocation
811from vgi .table_function import (
912 CardinalityInfo ,
@@ -23,7 +26,7 @@ def test_empty_process_generator(self) -> None:
2326 class EmptyFunction (TableFunctionGenerator ):
2427 @property
2528 def output_schema (self ) -> pa .Schema :
26- return pa . schema ([pa .field ("x" , pa .int64 ())])
29+ return make_schema ([pa .field ("x" , pa .int64 ())])
2730
2831 with TableFunctionTestClient (EmptyFunction ) as client :
2932 outputs = list (client .table_function ())
@@ -37,7 +40,7 @@ def test_single_batch_output(self) -> None:
3740 class SingleBatchFunction (TableFunctionGenerator ):
3841 @property
3942 def output_schema (self ) -> pa .Schema :
40- return pa . schema ([pa .field ("x" , pa .int64 ())])
43+ return make_schema ([pa .field ("x" , pa .int64 ())])
4144
4245 def process (self ) -> OutputGenerator :
4346 yield Output (
@@ -58,7 +61,7 @@ def test_multiple_batch_output(self) -> None:
5861 class MultiBatchFunction (TableFunctionGenerator ):
5962 @property
6063 def output_schema (self ) -> pa .Schema :
61- return pa . schema ([pa .field ("n" , pa .int64 ())])
64+ return make_schema ([pa .field ("n" , pa .int64 ())])
6265
6366 def process (self ) -> OutputGenerator :
6467 for i in range (3 ):
@@ -86,7 +89,7 @@ def test_setup_called_before_process(self) -> None:
8689 class LifecycleFunction (TableFunctionGenerator ):
8790 @property
8891 def output_schema (self ) -> pa .Schema :
89- return pa . schema ([pa .field ("x" , pa .int64 ())])
92+ return make_schema ([pa .field ("x" , pa .int64 ())])
9093
9194 def setup (self ) -> None :
9295 call_order .append ("setup" )
@@ -112,7 +115,7 @@ def test_teardown_called_on_exception(self) -> None:
112115 class ExceptionFunction (TableFunctionGenerator ):
113116 @property
114117 def output_schema (self ) -> pa .Schema :
115- return pa . schema ([pa .field ("x" , pa .int64 ())])
118+ return make_schema ([pa .field ("x" , pa .int64 ())])
116119
117120 def process (self ) -> OutputGenerator :
118121 raise ValueError ("test error" )
@@ -140,7 +143,7 @@ def test_valid_schema_passes(self) -> None:
140143 class ValidSchemaFunction (TableFunctionGenerator ):
141144 @property
142145 def output_schema (self ) -> pa .Schema :
143- return pa . schema ([pa .field ("x" , pa .int64 ())])
146+ return make_schema ([pa .field ("x" , pa .int64 ())])
144147
145148 def process (self ) -> OutputGenerator :
146149 yield Output (
@@ -158,11 +161,11 @@ def test_invalid_schema_raises(self) -> None:
158161 class InvalidSchemaFunction (TableFunctionGenerator ):
159162 @property
160163 def output_schema (self ) -> pa .Schema :
161- return pa . schema ([pa .field ("x" , pa .int64 ())])
164+ return make_schema ([pa .field ("x" , pa .int64 ())])
162165
163166 def process (self ) -> OutputGenerator :
164167 # Return batch with wrong column name
165- wrong_schema = pa . schema ([pa .field ("y" , pa .int64 ())])
168+ wrong_schema = make_schema ([pa .field ("y" , pa .int64 ())])
166169 wrong_batch = pa .RecordBatch .from_pydict (
167170 {"y" : [1 ]}, schema = wrong_schema
168171 )
@@ -187,7 +190,7 @@ def test_default_cardinality_is_none(self) -> None:
187190 class NoCardinalityFunction (TableFunctionGenerator ):
188191 @property
189192 def output_schema (self ) -> pa .Schema :
190- return pa . schema ([pa .field ("x" , pa .int64 ())])
193+ return make_schema ([pa .field ("x" , pa .int64 ())])
191194
192195 invocation = Invocation (
193196 function_name = "test" ,
@@ -209,7 +212,7 @@ def test_custom_cardinality(self) -> None:
209212 class CardinalityFunction (TableFunctionGenerator ):
210213 @property
211214 def output_schema (self ) -> pa .Schema :
212- return pa . schema ([pa .field ("x" , pa .int64 ())])
215+ return make_schema ([pa .field ("x" , pa .int64 ())])
213216
214217 def cardinality (self ) -> CardinalityInfo :
215218 return CardinalityInfo (estimate = 100 , max = 1000 )
@@ -244,7 +247,7 @@ class ArgFunction(TableFunctionGenerator):
244247
245248 @property
246249 def output_schema (self ) -> pa .Schema :
247- return pa . schema ([pa .field ("n" , pa .int64 ())])
250+ return make_schema ([pa .field ("n" , pa .int64 ())])
248251
249252 def process (self ) -> OutputGenerator :
250253 yield Output (
@@ -270,7 +273,7 @@ class NamedArgFunction(TableFunctionGenerator):
270273
271274 @property
272275 def output_schema (self ) -> pa .Schema :
273- return pa . schema ([pa .field ("result" , pa .int64 ())])
276+ return make_schema ([pa .field ("result" , pa .int64 ())])
274277
275278 def process (self ) -> OutputGenerator :
276279 yield Output (
@@ -299,7 +302,7 @@ def test_empty_output_batch_property(self) -> None:
299302 class TestFunction (TableFunctionGenerator ):
300303 @property
301304 def output_schema (self ) -> pa .Schema :
302- return pa . schema (
305+ return make_schema (
303306 [
304307 pa .field ("a" , pa .int64 ()),
305308 pa .field ("b" , pa .string ()),
0 commit comments