11"""Tests for SchemaForge schema diffing (diff.py)."""
2+
23from __future__ import annotations
34
45import sys
@@ -16,7 +17,9 @@ def _col(name: str, col_type: ColumnType = ColumnType.STRING, **kwargs) -> Colum
1617 return Column (name = name , type = col_type , ** kwargs )
1718
1819
19- def _table (name : str , columns : list [Column ] | None = None , indexes : list [Index ] | None = None ) -> Table :
20+ def _table (
21+ name : str , columns : list [Column ] | None = None , indexes : list [Index ] | None = None
22+ ) -> Table :
2023 return Table (name = name , columns = columns or [], indexes = indexes or [])
2124
2225
@@ -30,18 +33,24 @@ def test_identical_tables(self):
3033
3134 def test_added_column (self ):
3235 ta = _table ("users" , [_col ("id" , ColumnType .INTEGER , primary_key = True )])
33- tb = _table ("users" , [
34- _col ("id" , ColumnType .INTEGER , primary_key = True ),
35- _col ("email" , ColumnType .STRING ),
36- ])
36+ tb = _table (
37+ "users" ,
38+ [
39+ _col ("id" , ColumnType .INTEGER , primary_key = True ),
40+ _col ("email" , ColumnType .STRING ),
41+ ],
42+ )
3743 diffs = _diff_tables (ta , tb )
3844 assert any ('+ column "email"' in d for d in diffs )
3945
4046 def test_removed_column (self ):
41- ta = _table ("users" , [
42- _col ("id" , ColumnType .INTEGER , primary_key = True ),
43- _col ("email" , ColumnType .STRING ),
44- ])
47+ ta = _table (
48+ "users" ,
49+ [
50+ _col ("id" , ColumnType .INTEGER , primary_key = True ),
51+ _col ("email" , ColumnType .STRING ),
52+ ],
53+ )
4554 tb = _table ("users" , [_col ("id" , ColumnType .INTEGER , primary_key = True )])
4655 diffs = _diff_tables (ta , tb )
4756 assert any ('- column "email"' in d for d in diffs )
@@ -89,29 +98,45 @@ def test_comment_change(self):
8998 def test_added_index (self ):
9099 """Added index should appear in diff output."""
91100 ta = _table ("users" , [_col ("email" , ColumnType .STRING )], indexes = [])
92- tb = _table ("users" , [_col ("email" , ColumnType .STRING )], indexes = [
93- Index (name = "idx_email" , columns = ["email" ]),
94- ])
101+ tb = _table (
102+ "users" ,
103+ [_col ("email" , ColumnType .STRING )],
104+ indexes = [
105+ Index (name = "idx_email" , columns = ["email" ]),
106+ ],
107+ )
95108 diffs = _diff_tables (ta , tb )
96109 assert any ('+ index "idx_email"' in d for d in diffs )
97110
98111 def test_removed_index (self ):
99112 """Removed index should appear in diff output."""
100- ta = _table ("users" , [_col ("email" , ColumnType .STRING )], indexes = [
101- Index (name = "idx_email" , columns = ["email" ]),
102- ])
113+ ta = _table (
114+ "users" ,
115+ [_col ("email" , ColumnType .STRING )],
116+ indexes = [
117+ Index (name = "idx_email" , columns = ["email" ]),
118+ ],
119+ )
103120 tb = _table ("users" , [_col ("email" , ColumnType .STRING )], indexes = [])
104121 diffs = _diff_tables (ta , tb )
105122 assert any ('- index "idx_email"' in d for d in diffs )
106123
107124 def test_no_index_diff_for_unnamed (self ):
108125 """Indexes with empty names should not produce spurious diffs."""
109- ta = _table ("users" , [_col ("email" , ColumnType .STRING )], indexes = [
110- Index (name = "" , columns = ["email" ]),
111- ])
112- tb = _table ("users" , [_col ("email" , ColumnType .STRING )], indexes = [
113- Index (name = "" , columns = ["email" ]),
114- ])
126+ ta = _table (
127+ "users" ,
128+ [_col ("email" , ColumnType .STRING )],
129+ indexes = [
130+ Index (name = "" , columns = ["email" ]),
131+ ],
132+ )
133+ tb = _table (
134+ "users" ,
135+ [_col ("email" , ColumnType .STRING )],
136+ indexes = [
137+ Index (name = "" , columns = ["email" ]),
138+ ],
139+ )
115140 diffs = _diff_tables (ta , tb )
116141 assert not any ("index" in d for d in diffs )
117142
0 commit comments