11"""Test schema validation for table-valued functions."""
22
3- from typing import Iterator
3+ from collections . abc import Iterator
44
55import pytest
66
@@ -141,28 +141,32 @@ def test_invalid_schema_none(tmp_path):
141141 def gen_function ():
142142 return [("test" , 1 )]
143143
144- with duckdb .connect (tmp_path / "test.duckdb" ) as conn :
145- with pytest .raises (duckdb .InvalidInputException , match = "Table functions require a schema" ):
146- conn .create_table_function (
147- name = "gen_function" ,
148- callable = gen_function ,
149- schema = None ,
150- type = "tuples" ,
151- )
144+ with (
145+ duckdb .connect (tmp_path / "test.duckdb" ) as conn ,
146+ pytest .raises (duckdb .InvalidInputException , match = "Table functions require a schema" ),
147+ ):
148+ conn .create_table_function (
149+ name = "gen_function" ,
150+ callable = gen_function ,
151+ schema = None ,
152+ type = "tuples" ,
153+ )
152154
153155
154156def test_invalid_schema_empty_dict (tmp_path ):
155157 def gen_function ():
156158 return [("test" , 1 )]
157159
158- with duckdb .connect (tmp_path / "test.duckdb" ) as conn :
159- with pytest .raises (duckdb .InvalidInputException , match = "schema cannot be empty" ):
160- conn .create_table_function (
161- name = "gen_function" ,
162- callable = gen_function ,
163- schema = {},
164- type = "tuples" ,
165- )
160+ with (
161+ duckdb .connect (tmp_path / "test.duckdb" ) as conn ,
162+ pytest .raises (duckdb .InvalidInputException , match = "schema cannot be empty" ),
163+ ):
164+ conn .create_table_function (
165+ name = "gen_function" ,
166+ callable = gen_function ,
167+ schema = {},
168+ type = "tuples" ,
169+ )
166170
167171
168172def test_invalid_schema_list_format (tmp_path ):
@@ -207,7 +211,7 @@ def gen_function():
207211 # String types should be rejected
208212 schema = {"name" : "VARCHAR" , "id" : "INT" }
209213
210- with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb.sqltype" ):
214+ with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb\\ .sqltype" ):
211215 conn .create_table_function (
212216 name = "gen_function" ,
213217 callable = gen_function ,
@@ -223,7 +227,7 @@ def gen_function():
223227 with duckdb .connect (tmp_path / "test.duckdb" ) as conn :
224228 schema = {"name" : sqltypes .VARCHAR , "id" : 123 }
225229
226- with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb.sqltype" ):
230+ with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb\\ .sqltype" ):
227231 conn .create_table_function (
228232 name = "gen_function" ,
229233 callable = gen_function ,
@@ -239,7 +243,7 @@ def gen_function():
239243 with duckdb .connect (tmp_path / "test.duckdb" ) as conn :
240244 schema = {"name" : sqltypes .VARCHAR , "id" : None }
241245
242- with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb.sqltype" ):
246+ with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb\\ .sqltype" ):
243247 conn .create_table_function (
244248 name = "gen_function" ,
245249 callable = gen_function ,
@@ -258,7 +262,7 @@ def gen_function():
258262 # Mix of DuckDBPyType and string - should reject strings
259263 schema = {"name" : sqltypes .VARCHAR , "id" : "INT" , "value" : sqltypes .DOUBLE }
260264
261- with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb.sqltype" ):
265+ with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb\\ .sqltype" ):
262266 conn .create_table_function (
263267 name = "gen_function" ,
264268 callable = gen_function ,
@@ -274,7 +278,7 @@ def gen_function():
274278 with duckdb .connect (tmp_path / "test.duckdb" ) as conn :
275279 schema = {"name" : str , "id" : int }
276280
277- with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb.sqltype" ):
281+ with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb\\ .sqltype" ):
278282 conn .create_table_function (
279283 name = "gen_function" ,
280284 callable = gen_function ,
@@ -399,7 +403,7 @@ def gen_function():
399403 with duckdb .connect (tmp_path / "test.duckdb" ) as conn :
400404 schema = {"name" : sqltypes .VARCHAR , "id" : 123 } # int is not valid
401405
402- with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb.sqltype" ):
406+ with pytest .raises (duckdb .InvalidInputException , match = "must be a duckdb\\ .sqltype" ):
403407 conn .create_table_function (
404408 name = "gen_function" ,
405409 callable = gen_function ,
0 commit comments