@@ -111,13 +111,12 @@ def check_thedus_migration_log(self, expected: list):
111111 self .clickhouse .execute ("""
112112 SELECT command, revision, environment, is_skipped
113113 FROM thedus_migration_log
114- ORDER BY created_at
114+ ORDER BY version
115115 """ ),
116116 )
117117
118- def check_thedus_output (self , output : bytes , expected : List [str ]):
119- output = output .decode ().split ('\n ' )
120- output .pop ()
118+ def check_thedus_output (self , output : str , expected : List [str ]):
119+ output = output .split ('\n ' )
121120 output_log = [' ' .join (line .split (' ' )[3 :]) for line in output ]
122121 self .assertEqual (output_log , expected )
123122
@@ -187,12 +186,7 @@ def test_upgrade_downgrade(
187186 expected_thedus_logs : list ,
188187 ):
189188 os .environ ['THEDUS_ENV' ] = thedus_env
190- result = subprocess .check_output (
191- ['thedus' , 'upgrade' ],
192- env = os .environ ,
193- stderr = subprocess .PIPE ,
194- )
195-
189+ result = subprocess .getoutput ('thedus upgrade' )
196190 self .check_thedus_output (result , expected_output )
197191 expected = [
198192 self .clickhouse .execute (f'SELECT count() FROM { t } ' )
@@ -203,12 +197,7 @@ def test_upgrade_downgrade(
203197 self .check_thedus_migration_log (expected_thedus_logs )
204198
205199 # 1 downgrade
206- result = subprocess .check_output (
207- ['thedus' , 'downgrade' ],
208- env = os .environ ,
209- stderr = subprocess .PIPE ,
210- )
211-
200+ result = subprocess .getoutput ('thedus downgrade' )
212201 self .check_thedus_output (result , ['rollback 20250101000003_create_tbl_logs' , 'done' ])
213202 self .assertEqual (
214203 [],
@@ -217,28 +206,14 @@ def test_upgrade_downgrade(
217206 ))
218207
219208 def test_upgrade_to_revision (self ):
220- result = subprocess .check_output (
221- ['thedus' , 'upgrade' , '20250101000000_create_tbl_metrics' ],
222- env = os .environ ,
223- stderr = subprocess .PIPE ,
224- )
225-
209+ result = subprocess .getoutput ('thedus upgrade 20250101000000_create_tbl_metrics' )
226210 self .check_thedus_output (result , ['upgrade to 20250101000000_create_tbl_metrics' , 'done' ])
227211 self .check_thedus_migration_log ([
228212 ('upgrade 20250101000000_create_tbl_metrics' , '20250101000000_create_tbl_metrics' , 'dev' , 0 ),
229213 ])
230214
231- self .assertEqual (
232- [(0 ,)],
233- self .clickhouse .execute ('SELECT count() FROM metrics' )
234- )
235-
236- result = subprocess .check_output (
237- ['thedus' , 'upgrade' , '20250101000002_create_tbl_events' ],
238- env = os .environ ,
239- stderr = subprocess .PIPE ,
240- )
241-
215+ self .assertEqual ([(0 ,)], self .clickhouse .execute ('SELECT count() FROM metrics' ))
216+ result = subprocess .getoutput ('thedus upgrade 20250101000002_create_tbl_events' )
242217 self .check_thedus_output (
243218 result ,
244219 [
@@ -253,18 +228,11 @@ def test_upgrade_to_revision(self):
253228 ('upgrade 20250101000002_create_tbl_events' , '20250101000002_create_tbl_events' , 'dev' , 0 ),
254229 ])
255230
256- self .assertEqual (
257- [(0 ,)],
258- self .clickhouse .execute ('SELECT count() FROM events' )
259- )
231+ self .assertEqual ([(0 ,)], self .clickhouse .execute ('SELECT count() FROM events' ))
260232
261233 def test_downgrade_to_revision (self ):
262- subprocess .check_output (['thedus' , 'upgrade' ], env = os .environ )
263- result = subprocess .check_output (
264- ['thedus' , 'downgrade' , '20250101000001_insert_into_metrics' ],
265- env = os .environ ,
266- stderr = subprocess .PIPE ,
267- )
234+ subprocess .getoutput ('thedus upgrade' )
235+ result = subprocess .getoutput ('thedus downgrade 20250101000001_insert_into_metrics' )
268236
269237 self .check_thedus_output (
270238 result ,
@@ -293,17 +261,7 @@ def test_downgrade_to_revision(self):
293261 ('downgrade 20250101000001_insert_into_metrics' , '20250101000001_insert_into_metrics' , 'dev' , 0 ),
294262 ('downgrade 20250101000001_insert_into_metrics' , '20250101000000_create_tbl_metrics' , 'dev' , 1 )])
295263
296- result = subprocess .check_output (
297- ['thedus' , 'downgrade' ],
298- env = os .environ ,
299- stderr = subprocess .PIPE ,
300- )
301-
264+ result = subprocess .getoutput ('thedus downgrade' )
302265 self .check_thedus_output (result , ['rollback 20250101000000_create_tbl_metrics' , 'done' ])
303- result = subprocess .check_output (
304- ['thedus' , 'downgrade' ],
305- env = os .environ ,
306- stderr = subprocess .PIPE ,
307- )
308-
266+ result = subprocess .getoutput ('thedus downgrade' )
309267 self .check_thedus_output (result , ['done' ])
0 commit comments