"""Tests para duckdb_table_schema.""" import os import sys sys.path.insert(0, os.path.dirname(__file__)) import duckdb # noqa: E402 from duckdb_table_schema import duckdb_table_schema # noqa: E402 def _make_db(path: str) -> None: con = duckdb.connect(str(path)) con.execute( "CREATE TABLE ventas (id BIGINT, region VARCHAR, total DOUBLE, ok BOOLEAN)" ) con.close() def test_schema_devuelve_columnas_y_tipos(tmp_path): db = tmp_path / "v.duckdb" _make_db(str(db)) res = duckdb_table_schema(str(db), "ventas") assert res["status"] == "ok" assert res["table"] == "ventas" names = [c["name"] for c in res["columns"]] types = {c["name"]: c["type"] for c in res["columns"]} assert names == ["id", "region", "total", "ok"] assert types["id"] == "BIGINT" assert types["region"] == "VARCHAR" assert types["total"] == "DOUBLE" assert types["ok"] == "BOOLEAN" def test_identificador_invalido_devuelve_status_error(tmp_path): db = tmp_path / "v.duckdb" _make_db(str(db)) res = duckdb_table_schema(str(db), "ventas; DROP TABLE ventas") assert res["status"] == "error" assert "invalid table identifier" in res["error"] def test_tabla_inexistente_devuelve_status_error(tmp_path): db = tmp_path / "v.duckdb" _make_db(str(db)) res = duckdb_table_schema(str(db), "no_existe") assert res["status"] == "error" def test_db_inexistente_devuelve_status_error(tmp_path): res = duckdb_table_schema(str(tmp_path / "noexiste.duckdb"), "ventas") assert res["status"] == "error"