Skip to content

Commit 7b5b0d4

Browse files
committed
ci_cd tests
1 parent 04bad97 commit 7b5b0d4

File tree

4 files changed

+24
-67
lines changed

4 files changed

+24
-67
lines changed

.github/workflows/ci_cd.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,29 @@ jobs:
6262
fail-fast: false
6363
matrix:
6464
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
65-
env:
66-
UV_PYTHON: ${{ matrix.python-version }}
6765

6866
steps:
6967
- uses: actions/checkout@v4
7068
- uses: astral-sh/setup-uv@v5
7169
with:
7270
python-version: ${{ matrix.python-version }}
7371

74-
- name: Download thedus package
72+
- name: Install dependencies
73+
run: uv sync --dev
74+
75+
- name: Download thedus dist
7576
uses: actions/download-artifact@v4
7677
with:
7778
name: dist
7879

79-
- name: Install dependencies
80-
run: uv sync --dev
81-
82-
- name: Install thedus
80+
- name: Install thedus from dist
8381
run: uv pip install dist/$(ls ./dist/ | grep ".tar.gz")
8482

85-
- name: Run tests
83+
- name: Test with python ${{ matrix.python-version }}
8684
run: |
8785
mkdir -p ./tests/migrations
8886
pytest tests
87+
8988

9089
publish_to_PyPi:
9190
runs-on: ubuntu-22.04

tests/test_cli.py

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -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'])

thedus/cmd/clickhouse_cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import logging
55
from datetime import datetime
6-
from typing import List
6+
from typing import List, Union
77

88
from ripley import ClickhouseProtocol
99
from rich.console import Console
@@ -81,7 +81,7 @@ def __init__(
8181
sys.path.append(thedus_dir)
8282

8383
self._clickhouse = clickhouse
84-
self._migration_files: List[str] | None = None
84+
self._migration_files: Union[List[str], None] = None
8585
self._to_revision = to_revision
8686
self._thedus_env = thedus_env
8787

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)