-
Notifications
You must be signed in to change notification settings - Fork 377
Expand file tree
/
Copy pathtest_operations.py
More file actions
71 lines (51 loc) · 2.34 KB
/
test_operations.py
File metadata and controls
71 lines (51 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from pathlib import Path
import pytest
from sqlmesh_dbt.operations import create
from sqlmesh.utils import yaml
from sqlmesh.utils.errors import SQLMeshError
import time_machine
pytestmark = pytest.mark.slow
def test_create_sets_and_persists_default_start_date(jaffle_shop_duckdb: Path):
with time_machine.travel("2020-01-02 00:00:00 UTC"):
from sqlmesh.utils.date import yesterday_ds, to_ds
assert yesterday_ds() == "2020-01-01"
operations = create()
assert operations.context.config.model_defaults.start
assert to_ds(operations.context.config.model_defaults.start) == "2020-01-01"
assert all(
to_ds(model.start) if model.start else None == "2020-01-01"
for model in operations.context.models.values()
if not model.kind.is_seed
)
# check that the date set on the first invocation persists to future invocations
from sqlmesh.utils.date import yesterday_ds, to_ds
assert yesterday_ds() != "2020-01-01"
operations = create()
assert operations.context.config.model_defaults.start
assert to_ds(operations.context.config.model_defaults.start) == "2020-01-01"
assert all(
to_ds(model.start) if model.start else None == "2020-01-01"
for model in operations.context.models.values()
if not model.kind.is_seed
)
def test_create_uses_configured_start_date_if_supplied(jaffle_shop_duckdb: Path):
sqlmesh_yaml = jaffle_shop_duckdb / "sqlmesh.yml"
with sqlmesh_yaml.open("w") as f:
yaml.dump({"model_defaults": {"start": "2023-12-12"}}, f)
operations = create()
assert operations.context.config.model_defaults.start == "2023-12-12"
assert all(
model.start == "2023-12-12"
for model in operations.context.models.values()
if not model.kind.is_seed
)
def test_create_can_specify_profile_and_target(jaffle_shop_duckdb: Path):
with pytest.raises(SQLMeshError, match=r"Profile 'foo' not found"):
create(profile="foo")
with pytest.raises(
SQLMeshError, match=r"Target 'prod' not specified in profiles for 'jaffle_shop'"
):
create(profile="jaffle_shop", target="prod")
dbt_project = create(profile="jaffle_shop", target="dev").project
assert dbt_project.context.profile_name == "jaffle_shop"
assert dbt_project.context.target_name == "dev"