-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathtest_config.py
More file actions
260 lines (238 loc) · 8.04 KB
/
test_config.py
File metadata and controls
260 lines (238 loc) · 8.04 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import pathlib
import pytest
from sqlmesh.core.config import (
AutoCategorizationMode,
CategorizerConfig,
Config,
load_config_from_paths,
)
from sqlmesh.utils.errors import ConfigError
from sqlmesh.integrations.github.cicd.config import MergeMethod
from tests.utils.test_filesystem import create_temp_file
pytestmark = pytest.mark.github
def test_load_yaml_config_default(tmp_path):
create_temp_file(
tmp_path,
pathlib.Path("config.yaml"),
"""
cicd_bot:
type: github
model_defaults:
dialect: duckdb
""",
)
config = load_config_from_paths(
Config,
project_paths=[tmp_path / "config.yaml"],
)
assert config.cicd_bot.type_ == "github"
assert config.cicd_bot.invalidate_environment_after_deploy
assert config.cicd_bot.merge_method is None
assert config.cicd_bot.command_namespace is None
assert config.cicd_bot.auto_categorize_changes == CategorizerConfig.all_off()
assert config.cicd_bot.default_pr_start is None
assert not config.cicd_bot.enable_deploy_command
assert config.cicd_bot.skip_pr_backfill
assert config.cicd_bot.pr_include_unmodified is None
assert config.cicd_bot.pr_environment_name is None
assert config.cicd_bot.prod_branch_names == ["main", "master"]
assert not config.cicd_bot.pr_min_intervals
def test_load_yaml_config(tmp_path):
create_temp_file(
tmp_path,
pathlib.Path("config.yaml"),
"""
cicd_bot:
type: github
invalidate_environment_after_deploy: false
merge_method: squash
command_namespace: "#SQLMesh"
auto_categorize_changes:
external: full
python: full
sql: full
seed: full
default_pr_start:
enable_deploy_command: true
skip_pr_backfill: false
pr_include_unmodified: true
pr_environment_name: "MyOverride"
prod_branch_name: testing
pr_min_intervals: 1
model_defaults:
dialect: duckdb
""",
)
config = load_config_from_paths(
Config,
project_paths=[tmp_path / "config.yaml"],
)
assert config.cicd_bot.type_ == "github"
assert not config.cicd_bot.invalidate_environment_after_deploy
assert config.cicd_bot.merge_method == MergeMethod.SQUASH
assert config.cicd_bot.command_namespace == "#SQLMesh"
assert config.cicd_bot.auto_categorize_changes == CategorizerConfig(
external=AutoCategorizationMode.FULL,
python=AutoCategorizationMode.FULL,
sql=AutoCategorizationMode.FULL,
seed=AutoCategorizationMode.FULL,
)
assert config.cicd_bot.default_pr_start is None
assert config.cicd_bot.enable_deploy_command
assert not config.cicd_bot.skip_pr_backfill
assert config.cicd_bot.pr_include_unmodified
assert config.cicd_bot.pr_environment_name == "MyOverride"
assert config.cicd_bot.prod_branch_names == ["testing"]
assert config.cicd_bot.pr_min_intervals == 1
def test_load_python_config_defaults(tmp_path):
create_temp_file(
tmp_path,
pathlib.Path("config.py"),
"""
from sqlmesh.integrations.github.cicd.config import GithubCICDBotConfig
from sqlmesh.core.config import Config, ModelDefaultsConfig
config = Config(
cicd_bot=GithubCICDBotConfig(),
model_defaults=ModelDefaultsConfig(dialect="duckdb"),
)
""",
)
config = load_config_from_paths(
Config,
project_paths=[tmp_path / "config.py"],
)
assert config.cicd_bot.type_ == "github"
assert config.cicd_bot.invalidate_environment_after_deploy
assert config.cicd_bot.merge_method is None
assert config.cicd_bot.command_namespace is None
assert config.cicd_bot.auto_categorize_changes == CategorizerConfig.all_off()
assert config.cicd_bot.default_pr_start is None
assert not config.cicd_bot.enable_deploy_command
assert config.cicd_bot.skip_pr_backfill
assert config.cicd_bot.pr_include_unmodified is None
assert config.cicd_bot.pr_environment_name is None
assert config.cicd_bot.prod_branch_names == ["main", "master"]
assert not config.cicd_bot.pr_min_intervals
def test_load_python_config(tmp_path):
create_temp_file(
tmp_path,
pathlib.Path("config.py"),
"""
from sqlmesh.integrations.github.cicd.config import GithubCICDBotConfig, MergeMethod
from sqlmesh.core.config import AutoCategorizationMode, CategorizerConfig, Config, ModelDefaultsConfig
config = Config(
cicd_bot=GithubCICDBotConfig(
invalidate_environment_after_deploy=False,
merge_method=MergeMethod.SQUASH,
command_namespace="#SQLMesh",
auto_categorize_changes=CategorizerConfig(
external=AutoCategorizationMode.FULL,
python=AutoCategorizationMode.FULL,
sql=AutoCategorizationMode.FULL,
seed=AutoCategorizationMode.FULL,
),
default_pr_start="1 week ago",
pr_min_intervals=1,
enable_deploy_command=True,
skip_pr_backfill=False,
pr_include_unmodified=True,
pr_environment_name="MyOverride",
prod_branch_name="testing",
),
model_defaults=ModelDefaultsConfig(dialect="duckdb"),
)
""",
)
config = load_config_from_paths(
Config,
project_paths=[tmp_path / "config.py"],
)
assert config.cicd_bot.type_ == "github"
assert not config.cicd_bot.invalidate_environment_after_deploy
assert config.cicd_bot.merge_method == MergeMethod.SQUASH
assert config.cicd_bot.command_namespace == "#SQLMesh"
assert config.cicd_bot.auto_categorize_changes == CategorizerConfig(
external=AutoCategorizationMode.FULL,
python=AutoCategorizationMode.FULL,
sql=AutoCategorizationMode.FULL,
seed=AutoCategorizationMode.FULL,
)
assert config.cicd_bot.default_pr_start == "1 week ago"
assert config.cicd_bot.enable_deploy_command
assert not config.cicd_bot.skip_pr_backfill
assert config.cicd_bot.pr_include_unmodified
assert config.cicd_bot.pr_environment_name == "MyOverride"
assert config.cicd_bot.prod_branch_names == ["testing"]
assert config.cicd_bot.pr_min_intervals == 1
def test_validation(tmp_path):
create_temp_file(
tmp_path,
pathlib.Path("config.yaml"),
"""
cicd_bot:
type: github
command_namespace: "#SQLMesh"
enable_deploy_command: False
model_defaults:
dialect: duckdb
""",
)
with pytest.raises(
ConfigError, match=r".*enable_deploy_command must be set if command_namespace is set.*"
):
load_config_from_paths(Config, project_paths=[tmp_path / "config.yaml"])
create_temp_file(
tmp_path,
pathlib.Path("config.yaml"),
"""
cicd_bot:
type: github
enable_deploy_command: True
model_defaults:
dialect: duckdb
""",
)
with pytest.raises(
ConfigError, match=r".*merge_method must be set if enable_deploy_command is True.*"
):
load_config_from_paths(Config, project_paths=[tmp_path / "config.yaml"])
def test_ttl_in_past(tmp_path):
create_temp_file(
tmp_path,
pathlib.Path("config.yaml"),
"""
environment_ttl: in 1 week
model_defaults:
dialect: duckdb
""",
)
config = load_config_from_paths(Config, project_paths=[tmp_path / "config.yaml"])
assert config.environment_ttl == "in 1 week"
create_temp_file(
tmp_path,
pathlib.Path("config.yaml"),
"""
environment_ttl: 1 week
model_defaults:
dialect: duckdb
""",
)
with pytest.raises(
ConfigError,
match=r".*TTL '1 week' is in the past. Please specify a relative time in the future. Ex: `in 1 week` instead of `1 week`.*",
):
load_config_from_paths(Config, project_paths=[tmp_path / "config.yaml"])
create_temp_file(
tmp_path,
pathlib.Path("config.yaml"),
"""
snapshot_ttl: 1 week
model_defaults:
dialect: duckdb
""",
)
with pytest.raises(
ValueError,
match="TTL '1 week' is in the past. Please specify a relative time in the future. Ex: `in 1 week` instead of `1 week`.",
):
load_config_from_paths(Config, project_paths=[tmp_path / "config.yaml"])