Skip to content

Commit 071d6a8

Browse files
authored
chore: publish sqlmesh tests (#2270)
1 parent dfd321a commit 071d6a8

File tree

5 files changed

+83
-22
lines changed

5 files changed

+83
-22
lines changed

.circleci/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ jobs:
2424
- run:
2525
name: Publish Python package
2626
command: make publish
27-
27+
- run:
28+
name: Publish Python Tests package
29+
command: make publish-tests
2830
gh-release:
2931
docker:
3032
- image: cimg/node:16.14

.circleci/update-pypirc.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
echo "[distutils]" >> ~/.pypirc
4+
echo "index-servers = tobiko-private" >> ~/.pypirc
5+
echo "[tobiko-private]" >> ~/.pypirc
6+
echo "repository = $TOBIKO_PRIVATE_PYPI_URL" >> ~/.pypirc
7+
echo "username = _json_key_base64" >> ~/.pypirc
8+
echo "password = $TOBIKO_PRIVATE_PYPI_KEY" >> ~/.pypirc

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ package:
3333
publish: package
3434
pip3 install twine && python3 -m twine upload dist/*
3535

36+
package-tests:
37+
pip3 install wheel && python3 tests/setup.py sdist bdist_wheel
38+
39+
publish-tests: package-tests
40+
pip3 install twine && python3 -m twine upload -r tobiko-private tests/dist/*
41+
3642
develop:
3743
python3 setup.py develop
3844

tests/core/test_state_sync.py

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Snapshot,
2929
SnapshotChangeCategory,
3030
SnapshotId,
31+
SnapshotIntervals,
3132
SnapshotTableCleanupTask,
3233
missing_intervals,
3334
)
@@ -211,12 +212,21 @@ def test_snapshots_exists(state_sync: EngineAdapterStateSync, snapshots: t.List[
211212
assert state_sync.snapshots_exist(snapshot_ids) == snapshot_ids
212213

213214

214-
def get_snapshot_intervals(state_sync, snapshot):
215-
intervals = state_sync._get_snapshot_intervals([snapshot])[-1]
216-
return intervals[0] if intervals else None
215+
@pytest.fixture
216+
def get_snapshot_intervals(state_sync) -> t.Callable[[Snapshot], t.Optional[SnapshotIntervals]]:
217+
218+
def _get_snapshot_intervals(snapshot: Snapshot) -> t.Optional[SnapshotIntervals]:
219+
intervals = state_sync._get_snapshot_intervals([snapshot])[-1]
220+
return intervals[0] if intervals else None
221+
222+
return _get_snapshot_intervals
217223

218224

219-
def test_add_interval(state_sync: EngineAdapterStateSync, make_snapshot: t.Callable) -> None:
225+
def test_add_interval(
226+
state_sync: EngineAdapterStateSync,
227+
make_snapshot: t.Callable,
228+
get_snapshot_intervals: t.Callable,
229+
) -> None:
220230
snapshot = make_snapshot(
221231
SqlModel(
222232
name="a",
@@ -229,24 +239,24 @@ def test_add_interval(state_sync: EngineAdapterStateSync, make_snapshot: t.Calla
229239
state_sync.push_snapshots([snapshot])
230240

231241
state_sync.add_interval(snapshot, "2020-01-01", "20200101")
232-
assert get_snapshot_intervals(state_sync, snapshot).intervals == [
242+
assert get_snapshot_intervals(snapshot).intervals == [
233243
(to_timestamp("2020-01-01"), to_timestamp("2020-01-02")),
234244
]
235245

236246
state_sync.add_interval(snapshot, "20200101", to_datetime("2020-01-04"))
237-
assert get_snapshot_intervals(state_sync, snapshot).intervals == [
247+
assert get_snapshot_intervals(snapshot).intervals == [
238248
(to_timestamp("2020-01-01"), to_timestamp("2020-01-04")),
239249
]
240250

241251
state_sync.add_interval(snapshot, to_datetime("2020-01-05"), "2020-01-10")
242-
assert get_snapshot_intervals(state_sync, snapshot).intervals == [
252+
assert get_snapshot_intervals(snapshot).intervals == [
243253
(to_timestamp("2020-01-01"), to_timestamp("2020-01-04")),
244254
(to_timestamp("2020-01-05"), to_timestamp("2020-01-11")),
245255
]
246256

247257
snapshot.change_category = SnapshotChangeCategory.FORWARD_ONLY
248258
state_sync.add_interval(snapshot, to_datetime("2020-01-16"), "2020-01-20", is_dev=True)
249-
intervals = get_snapshot_intervals(state_sync, snapshot)
259+
intervals = get_snapshot_intervals(snapshot)
250260
assert intervals.intervals == [
251261
(to_timestamp("2020-01-01"), to_timestamp("2020-01-04")),
252262
(to_timestamp("2020-01-05"), to_timestamp("2020-01-11")),
@@ -257,7 +267,9 @@ def test_add_interval(state_sync: EngineAdapterStateSync, make_snapshot: t.Calla
257267

258268

259269
def test_add_interval_partial(
260-
state_sync: EngineAdapterStateSync, make_snapshot: t.Callable
270+
state_sync: EngineAdapterStateSync,
271+
make_snapshot: t.Callable,
272+
get_snapshot_intervals: t.Callable,
261273
) -> None:
262274
snapshot = make_snapshot(
263275
SqlModel(
@@ -271,10 +283,10 @@ def test_add_interval_partial(
271283
state_sync.push_snapshots([snapshot])
272284

273285
state_sync.add_interval(snapshot, "2023-01-01", to_timestamp("2023-01-01") + 1000)
274-
assert get_snapshot_intervals(state_sync, snapshot) is None
286+
assert get_snapshot_intervals(snapshot) is None
275287

276288
state_sync.add_interval(snapshot, "2023-01-01", to_timestamp("2023-01-02") + 1000)
277-
assert get_snapshot_intervals(state_sync, snapshot).intervals == [
289+
assert get_snapshot_intervals(snapshot).intervals == [
278290
(to_timestamp("2023-01-01"), to_timestamp("2023-01-02")),
279291
]
280292

@@ -338,7 +350,7 @@ def test_refresh_snapshot_intervals(
338350

339351

340352
def test_get_snapshot_intervals(
341-
state_sync: EngineAdapterStateSync, make_snapshot: t.Callable
353+
state_sync: EngineAdapterStateSync, make_snapshot: t.Callable, get_snapshot_intervals
342354
) -> None:
343355
state_sync.SNAPSHOT_BATCH_SIZE = 1
344356

@@ -372,16 +384,20 @@ def test_get_snapshot_intervals(
372384
),
373385
version="c",
374386
)
375-
state_sync.add_interval(snapshot_c, "2020-01-03", "2020-01-03")
376387
state_sync.push_snapshots([snapshot_c])
388+
state_sync.add_interval(snapshot_c, "2020-01-03", "2020-01-03")
377389

378-
_, intervals = state_sync._get_snapshot_intervals([snapshot_b, snapshot_c])
379-
assert len(intervals) == 2
380-
assert intervals[0].intervals == [(to_timestamp("2020-01-01"), to_timestamp("2020-01-02"))]
381-
assert intervals[1].intervals == [(to_timestamp("2020-01-03"), to_timestamp("2020-01-04"))]
390+
a_intervals = get_snapshot_intervals(snapshot_a)
391+
c_intervals = get_snapshot_intervals(snapshot_c)
392+
assert a_intervals.intervals == [(to_timestamp("2020-01-01"), to_timestamp("2020-01-02"))]
393+
assert c_intervals.intervals == [(to_timestamp("2020-01-03"), to_timestamp("2020-01-04"))]
382394

383395

384-
def test_compact_intervals(state_sync: EngineAdapterStateSync, make_snapshot: t.Callable) -> None:
396+
def test_compact_intervals(
397+
state_sync: EngineAdapterStateSync,
398+
make_snapshot: t.Callable,
399+
get_snapshot_intervals: t.Callable,
400+
) -> None:
385401
snapshot = make_snapshot(
386402
SqlModel(
387403
name="a",
@@ -408,14 +424,14 @@ def test_compact_intervals(state_sync: EngineAdapterStateSync, make_snapshot: t.
408424
(to_timestamp("2020-01-12"), to_timestamp("2020-01-14")),
409425
]
410426

411-
assert get_snapshot_intervals(state_sync, snapshot).intervals == expected_intervals
427+
assert get_snapshot_intervals(snapshot).intervals == expected_intervals
412428

413429
state_sync.compact_intervals()
414-
assert get_snapshot_intervals(state_sync, snapshot).intervals == expected_intervals
430+
assert get_snapshot_intervals(snapshot).intervals == expected_intervals
415431

416432
# Make sure compaction is idempotent.
417433
state_sync.compact_intervals()
418-
assert get_snapshot_intervals(state_sync, snapshot).intervals == expected_intervals
434+
assert get_snapshot_intervals(snapshot).intervals == expected_intervals
419435

420436

421437
def test_promote_snapshots(state_sync: EngineAdapterStateSync, make_snapshot: t.Callable):
@@ -1248,13 +1264,17 @@ def test_unpause_snapshots_remove_intervals(
12481264
),
12491265
version="a",
12501266
)
1267+
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
1268+
snapshot.version = "a"
12511269
state_sync.push_snapshots([snapshot])
12521270
state_sync.add_interval(snapshot, "2023-01-01", "2023-01-05")
12531271

12541272
new_snapshot = make_snapshot(
12551273
SqlModel(name="test_snapshot", query=parse_one("select 2, ds"), cron="@daily"),
12561274
version="a",
12571275
)
1276+
new_snapshot.categorize_as(SnapshotChangeCategory.FORWARD_ONLY)
1277+
new_snapshot.version = "a"
12581278
new_snapshot.effective_from = "2023-01-03"
12591279
state_sync.push_snapshots([new_snapshot])
12601280
state_sync.add_interval(snapshot, "2023-01-06", "2023-01-06")

tests/setup.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
from distutils.core import run_setup, setup
3+
4+
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
5+
sqlmesh_dist = run_setup("setup.py", stop_after="init")
6+
requirements = sqlmesh_dist.install_requires + sqlmesh_dist.extras_require["dev"] # type: ignore
7+
os.chdir(os.path.dirname(__file__))
8+
9+
setup(
10+
name="sqlmesh-tests",
11+
description="Tests for SQLMesh",
12+
url="https://github.com/TobikoData/sqlmesh",
13+
author="TobikoData Inc.",
14+
author_email="engineering@tobikodata.com",
15+
license="Apache License 2.0",
16+
package_dir={"sqlmesh_tests": ""},
17+
package_data={"": ["fixtures/**"]},
18+
use_scm_version={
19+
"write_to": "_version.py",
20+
"fallback_version": "0.0.0",
21+
"local_scheme": "no-local-version",
22+
},
23+
setup_requires=["setuptools_scm"],
24+
install_requires=requirements,
25+
)

0 commit comments

Comments
 (0)