11"""Tests for SchemaForge base generator utilities (_base.py)."""
2+
23from __future__ import annotations
34
45import sys
1819
1920# ── resolve_type tests ──
2021
22+
2123def test_resolve_type_normal ():
2224 """resolve_type returns the mapped type for known ColumnTypes."""
2325 col = Column (name = "id" , type = ColumnType .INTEGER )
@@ -48,6 +50,7 @@ def test_resolve_type_unknown():
4850
4951# ── build_type_string tests ──
5052
53+
5154def test_build_type_string_simple ():
5255 """build_type_string returns base type for simple columns."""
5356 col = Column (name = "id" , type = ColumnType .INTEGER )
@@ -58,32 +61,41 @@ def test_build_type_string_simple():
5861def test_build_type_string_string_with_length ():
5962 """build_type_string adds length for STRING."""
6063 col = Column (name = "name" , type = ColumnType .STRING , type_args = {"length" : 100 })
61- result = build_type_string (col , {ColumnType .STRING : "String" },
62- string_fmt = "{}({})" , string_default = "String" )
64+ result = build_type_string (
65+ col , {ColumnType .STRING : "String" }, string_fmt = "{}({})" , string_default = "String"
66+ )
6367 assert result == "String(100)"
6468
6569
6670def test_build_type_string_string_no_length ():
6771 """build_type_string returns base for STRING without length."""
6872 col = Column (name = "name" , type = ColumnType .STRING )
69- result = build_type_string (col , {ColumnType .STRING : "String" },
70- string_fmt = "{}({})" , string_default = "String" )
73+ result = build_type_string (
74+ col , {ColumnType .STRING : "String" }, string_fmt = "{}({})" , string_default = "String"
75+ )
7176 assert result == "String"
7277
7378
7479def test_build_type_string_decimal ():
7580 """build_type_string adds precision/scale for DECIMAL."""
76- col = Column (name = "price" , type = ColumnType .DECIMAL , type_args = {"precision" : 12 , "scale" : 4 })
77- result = build_type_string (col , {ColumnType .DECIMAL : "DECIMAL" },
78- decimal_fmt = "{}({},{})" , decimal_default = "DECIMAL" )
81+ col = Column (
82+ name = "price" , type = ColumnType .DECIMAL , type_args = {"precision" : 12 , "scale" : 4 }
83+ )
84+ result = build_type_string (
85+ col ,
86+ {ColumnType .DECIMAL : "DECIMAL" },
87+ decimal_fmt = "{}({},{})" ,
88+ decimal_default = "DECIMAL" ,
89+ )
7990 assert result == "DECIMAL(12,4)"
8091
8192
8293def test_build_type_string_enum ():
8394 """build_type_string formats inline ENUM values."""
84- col = Column (name = "size" , type = ColumnType .ENUM , type_args = {"values" : ["S" , "M" , "L" ]})
85- result = build_type_string (col , {ColumnType .ENUM : "Enum" },
86- enum_fmt = "Enum({})" )
95+ col = Column (
96+ name = "size" , type = ColumnType .ENUM , type_args = {"values" : ["S" , "M" , "L" ]}
97+ )
98+ result = build_type_string (col , {ColumnType .ENUM : "Enum" }, enum_fmt = "Enum({})" )
8799 assert result == "Enum('S', 'M', 'L')"
88100
89101
@@ -97,8 +109,12 @@ def test_build_type_string_custom():
97109def test_build_type_string_sql_varchar ():
98110 """build_type_string produces VARCHAR with length when type_map has VARCHAR."""
99111 col = Column (name = "name" , type = ColumnType .STRING , type_args = {"length" : 255 })
100- result = build_type_string (col , {ColumnType .STRING : "VARCHAR" },
101- string_fmt = "{}({})" , string_default = "VARCHAR" )
112+ result = build_type_string (
113+ col ,
114+ {ColumnType .STRING : "VARCHAR" },
115+ string_fmt = "{}({})" ,
116+ string_default = "VARCHAR" ,
117+ )
102118 assert result == "VARCHAR(255)"
103119
104120
@@ -119,6 +135,7 @@ def test_build_type_string_with_fn_default():
119135
120136# ── resolve_fn_default tests ──
121137
138+
122139def test_resolve_fn_default_now ():
123140 """resolve_fn_default maps CURRENT_TIMESTAMP to now()."""
124141 col = Column (name = "ts" , type = ColumnType .DATETIME , default = "fn:CURRENT_TIMESTAMP" )
@@ -186,6 +203,7 @@ def test_resolve_fn_default_all_mapped_fns():
186203
187204# ── format_literal_default tests ──
188205
206+
189207def test_format_literal_default_bool ():
190208 """format_literal_default formats boolean defaults."""
191209 col = Column (name = "active" , type = ColumnType .BOOLEAN , default = True )
@@ -230,6 +248,7 @@ def test_format_literal_default_fn():
230248
231249# ── FN_DEFAULT_MAP constants ──
232250
251+
233252def test_fn_default_map_has_expected_keys ():
234253 """FN_DEFAULT_MAP should have the core SQL function constants."""
235254 assert "CURRENT_TIMESTAMP" in FN_DEFAULT_MAP
0 commit comments