@@ -44,13 +44,15 @@ def setUp(self):
4444 self .tmp = self .tmpdir .name
4545
4646 def test_install_single_changelog (self ):
47+ test_dir = Path ("test" ) / "data" / "single_changelog"
48+ changelog_file = test_dir / "changelogs" / "1.2.3" / "create_northwind.sql"
4749 cfg = PumConfig ()
4850 sm = SchemaMigrations (cfg )
4951 self .assertFalse (sm .exists (self .conn ))
5052 upgrader = Upgrader (
5153 pg_service = self .pg_service ,
5254 config = cfg ,
53- dir = str ( Path ( "test" ) / "data" / "single_changelog" ) ,
55+ dir = test_dir ,
5456 )
5557 upgrader .install ()
5658 self .assertTrue (sm .exists (self .conn ))
@@ -59,24 +61,17 @@ def test_install_single_changelog(self):
5961 self .assertEqual (sm .migration_details (self .conn )["version" ], "1.2.3" )
6062 self .assertEqual (
6163 sm .migration_details (self .conn )["changelog_files" ],
62- [
63- str (
64- Path ("test" )
65- / "data"
66- / "single_changelog"
67- / "changelogs"
68- / "1.2.3"
69- / "create_northwind.sql"
70- )
71- ],
64+ [str (changelog_file )],
7265 )
7366
7467 @unittest .skipIf (
7568 os .name == "nt" and os .getenv ("CI" ) == "true" ,
7669 "Test not supported on Windows CI (postgis not installed)" ,
7770 )
7871 def test_parameters (self ):
79- cfg = PumConfig .from_yaml (str (Path ("test" ) / "data" / "parameters" / ".pum-config.yaml" ))
72+ test_dir = Path ("test" ) / "data" / "parameters"
73+ config_path = test_dir / ".pum-config.yaml"
74+ cfg = PumConfig .from_yaml (str (config_path ))
8075 self .assertEqual (
8176 cfg .parameters ()["SRID" ],
8277 MigrationParameterDefintion (
@@ -91,7 +86,7 @@ def test_parameters(self):
9186 upgrader = Upgrader (
9287 pg_service = self .pg_service ,
9388 config = cfg ,
94- dir = str ( Path ( "test" ) / "data" / "parameters" ) ,
89+ dir = test_dir ,
9590 parameters = {"SRID" : 2056 },
9691 )
9792 upgrader .install ()
@@ -102,53 +97,57 @@ def test_parameters(self):
10297 self .assertEqual (srid , 2056 )
10398
10499 def test_install_custom_directory (self ):
105- cfg = PumConfig . from_yaml (
106- str ( Path ( "test" ) / "data" / "custom_directory" / " .pum-config.yaml")
107- )
100+ test_dir = Path ( "test" ) / "data" / "custom_directory"
101+ config_path = test_dir / ".pum-config.yaml"
102+ cfg = PumConfig . from_yaml ( str ( config_path ) )
108103 sm = SchemaMigrations (cfg )
109104 self .assertFalse (sm .exists (self .conn ))
110105 upgrader = Upgrader (
111106 pg_service = self .pg_service ,
112107 config = cfg ,
113- dir = str ( Path ( "test" ) / "data" / "custom_directory" ) ,
108+ dir = test_dir ,
114109 )
115110 upgrader .install ()
116111 self .assertTrue (sm .exists (self .conn ))
117112
118113 def test_install_custom_migration_table (self ):
119- cfg = PumConfig . from_yaml (
120- str ( Path ( "test" ) / "data" / "custom_migration_schema" / " .pum-config.yaml")
121- )
114+ test_dir = Path ( "test" ) / "data" / "custom_migration_schema"
115+ config_path = test_dir / ".pum-config.yaml"
116+ cfg = PumConfig . from_yaml ( str ( config_path ) )
122117 sm = SchemaMigrations (cfg )
123118 self .assertFalse (sm .exists (self .conn ))
124119 upgrader = Upgrader (
125120 pg_service = self .pg_service ,
126121 config = cfg ,
127- dir = str ( Path ( "test" ) / "data" / "custom_migration_schema" ) ,
122+ dir = test_dir ,
128123 )
129124 upgrader .install ()
130125 self .assertTrue (sm .exists (self .conn ))
131126
132127 def test_install_complex_files_content (self ):
128+ complex_dir = Path ("test" ) / "data" / "complex_files_content"
133129 cfg = PumConfig ()
134130 sm = SchemaMigrations (cfg )
135131 self .assertFalse (sm .exists (self .conn ))
136132 upgrader = Upgrader (
137133 pg_service = self .pg_service ,
138134 config = cfg ,
139- dir = str (Path ( "test" ) / "data" / "complex_files_content" ),
135+ dir = str (complex_dir ),
140136 )
141137 upgrader .install ()
142138 self .assertTrue (sm .exists (self .conn ))
143139
144140 def test_install_multiple_changelogs (self ):
141+ test_dir = Path ("test" ) / "data" / "multiple_changelogs"
142+ changelog_file_1 = test_dir / "changelogs" / "2.0.0" / "create_second_table.sql"
143+ changelog_file_2 = test_dir / "changelogs" / "2.0.0" / "create_third_table.sql"
145144 cfg = PumConfig ()
146145 sm = SchemaMigrations (cfg )
147146 self .assertFalse (sm .exists (self .conn ))
148147 upgrader = Upgrader (
149148 pg_service = self .pg_service ,
150149 config = cfg ,
151- dir = str ( Path ( "test" ) / "data" / "multiple_changelogs" ) ,
150+ dir = test_dir ,
152151 )
153152 upgrader .install ()
154153 self .assertTrue (sm .exists (self .conn ))
@@ -160,35 +159,15 @@ def test_install_multiple_changelogs(self):
160159 self .assertEqual (sm .migration_details (self .conn )["version" ], "2.0.0" )
161160 self .assertEqual (
162161 sm .migration_details (self .conn )["changelog_files" ],
163- [
164- str (
165- Path ("test" )
166- / "data"
167- / "multiple_changelogs"
168- / "changelogs"
169- / "2.0.0"
170- / "create_second_table.sql"
171- ),
172- str (
173- Path ("test" )
174- / "data"
175- / "multiple_changelogs"
176- / "changelogs"
177- / "2.0.0"
178- / "create_third_table.sql"
179- ),
180- ],
162+ [str (changelog_file_1 ), str (changelog_file_2 )],
181163 )
182164
183165 def test_invalid_changelog (self ):
166+ test_dir = Path ("test" ) / "data" / "invalid_changelog"
184167 cfg = PumConfig ()
185168 sm = SchemaMigrations (cfg )
186169 self .assertFalse (sm .exists (self .conn ))
187- upgrader = Upgrader (
188- pg_service = self .pg_service ,
189- config = cfg ,
190- dir = str (Path ("test" ) / "data" / "invalid_changelog" ),
191- )
170+ upgrader = Upgrader (pg_service = self .pg_service , config = cfg , dir = test_dir )
192171 with self .assertRaises (Exception ) as context :
193172 upgrader .install ()
194173 self .assertTrue (
0 commit comments