Skip to content

Commit 927090c

Browse files
committed
fixed linters issues
1 parent a01870e commit 927090c

File tree

2 files changed

+113
-68
lines changed

2 files changed

+113
-68
lines changed

integration_tests/tests/dbt_project.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,6 @@ def assert_table_exists(self, table_name: str):
290290
table_exists_result = []
291291
except Exception as e:
292292
raise AssertionError(f"Failed to check if {table_name} exists: {e}")
293-
assert table_exists_result, f"{table_name} table does not exist. The artifact was not created."
293+
assert (
294+
table_exists_result
295+
), f"{table_name} table does not exist. The artifact was not created."

integration_tests/tests/test_dbt_artifacts/test_groups.py

Lines changed: 110 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from dbt_project import DbtProject
21
import pytest
3-
from ruamel.yaml import YAML
2+
from dbt_project import DbtProject
43

54
GROUP_NAME = "test_group"
65
OWNER_NAME = "Data Spock"
@@ -25,7 +24,9 @@ def _write_group_config(dbt_project: DbtProject, group_config: dict, name: str):
2524
return dbt_project.write_yaml(group_config, name=name)
2625

2726

28-
def _get_group_from_table(dbt_project: DbtProject, group_name: str, table_name: str = "dbt_groups"):
27+
def _get_group_from_table(
28+
dbt_project: DbtProject, group_name: str, table_name: str = "dbt_groups"
29+
):
2930
"""Helper to read a group from the dbt_groups artifact table."""
3031
groups = dbt_project.read_table(table_name, raise_if_empty=True)
3132
return next((g for g in groups if g["name"] == group_name), None)
@@ -42,34 +43,43 @@ def _get_group_from_table(dbt_project: DbtProject, group_name: str, table_name:
4243
),
4344
# Single group with name only, no email
4445
(
45-
{"groups": [
46-
{"name": GROUP_NAME, "owner": {"name": OWNER_NAME}}
47-
]},
46+
{"groups": [{"name": GROUP_NAME, "owner": {"name": OWNER_NAME}}]},
4847
[(GROUP_NAME, OWNER_NAME, None)],
4948
"single_group_without_email",
5049
),
5150
# Single group with email only, no name
5251
(
53-
{"groups": [
54-
{"name": GROUP_NAME, "owner": {"email": OWNER_EMAIL}}
55-
]},
52+
{"groups": [{"name": GROUP_NAME, "owner": {"email": OWNER_EMAIL}}]},
5653
[(GROUP_NAME, None, OWNER_EMAIL)],
5754
"single_group_without_name",
5855
),
5956
# Single group with owner additional fields
6057
(
61-
{"groups": [
62-
{"name": GROUP_NAME, "owner": {"email": OWNER_EMAIL, "slack": "slack_channel"}}
63-
]},
58+
{
59+
"groups": [
60+
{
61+
"name": GROUP_NAME,
62+
"owner": {"email": OWNER_EMAIL, "slack": "slack_channel"},
63+
}
64+
]
65+
},
6466
[(GROUP_NAME, None, OWNER_EMAIL)],
6567
"single_group_with_additional_fields",
6668
),
6769
# Two groups, each with owner
6870
(
69-
{"groups": [
70-
{"name": "test_group_1", "owner": {"name": "Owner One", "email": "[email protected]"}},
71-
{"name": "test_group_2", "owner": {"name": "Owner Two", "email": "[email protected]"}},
72-
]},
71+
{
72+
"groups": [
73+
{
74+
"name": "test_group_1",
75+
"owner": {"name": "Owner One", "email": "[email protected]"},
76+
},
77+
{
78+
"name": "test_group_2",
79+
"owner": {"name": "Owner Two", "email": "[email protected]"},
80+
},
81+
]
82+
},
7383
[
7484
("test_group_1", "Owner One", "[email protected]"),
7585
("test_group_2", "Owner Two", "[email protected]"),
@@ -83,25 +93,35 @@ def _get_group_from_table(dbt_project: DbtProject, group_name: str, table_name:
8393
"single_group_without_name",
8494
"single_group_with_additional_fields",
8595
"two_groups",
86-
]
96+
],
8797
)
88-
def test_dbt_groups_artifact_parametrized(dbt_project: DbtProject, group_config, expected_groups, test_name):
98+
def test_dbt_groups_artifact_parametrized(
99+
dbt_project: DbtProject, group_config, expected_groups, test_name
100+
):
89101
"""
90102
Parametrized test for group artifact scenarios:
91103
- Single group with owner (name and email)
92104
- Single group with owner (name only, no email)
93105
- Two groups, each with owner
94106
Asserts that the group(s) and owner details are present and correct in the dbt_groups artifact table.
95107
"""
96-
with _write_group_config(dbt_project, group_config, name=f"groups_test_{test_name}.yml"):
108+
with _write_group_config(
109+
dbt_project, group_config, name=f"groups_test_{test_name}.yml"
110+
):
97111
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
98112
dbt_project.dbt_runner.run()
99113
dbt_project.assert_table_exists("dbt_groups")
100114
for group_name, owner_name, owner_email in expected_groups:
101115
group = _get_group_from_table(dbt_project, group_name)
102-
assert group is not None, f"Group {group_name} not found in dbt_groups artifact table."
103-
assert group.get("owner_name") == owner_name, f"Expected owner name {owner_name}, got {group.get('owner_name')}"
104-
assert group.get("owner_email") == owner_email, f"Expected owner email {owner_email}, got {group.get('owner_email')}"
116+
assert (
117+
group is not None
118+
), f"Group {group_name} not found in dbt_groups artifact table."
119+
assert (
120+
group.get("owner_name") == owner_name
121+
), f"Expected owner name {owner_name}, got {group.get('owner_name')}"
122+
assert (
123+
group.get("owner_email") == owner_email
124+
), f"Expected owner email {owner_email}, got {group.get('owner_email')}"
105125

106126

107127
def test_model_group_attribute(dbt_project: DbtProject):
@@ -121,21 +141,26 @@ def test_model_group_attribute(dbt_project: DbtProject):
121141
"group": GROUP_NAME,
122142
"description": "A model assigned to a group for testing",
123143
}
124-
]
144+
],
125145
}
126-
with _write_group_config(dbt_project, GROUP_CONFIG, name="groups_test_model_inherits.yml"), \
127-
dbt_project.write_yaml(schema_yaml, name="schema_model_with_group.yml"):
146+
with _write_group_config(
147+
dbt_project, GROUP_CONFIG, name="groups_test_model_inherits.yml"
148+
), dbt_project.write_yaml(schema_yaml, name="schema_model_with_group.yml"):
128149
model_path = dbt_project.models_dir_path / "tmp" / f"{model_name}.sql"
129150
model_path.parent.mkdir(parents=True, exist_ok=True)
130151
model_path.write_text(model_sql)
131152
try:
132153
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
133154
dbt_project.dbt_runner.run(select=model_name)
134155
dbt_project.assert_table_exists("dbt_models")
135-
models = dbt_project.read_table("dbt_models", where=f"name = '{model_name}'", raise_if_empty=True)
156+
models = dbt_project.read_table(
157+
"dbt_models", where=f"name = '{model_name}'", raise_if_empty=True
158+
)
136159
assert len(models) == 1, f"Expected 1 model, got {len(models)}"
137160
model_row = models[0]
138-
assert model_row["group_name"] == GROUP_NAME, f"Expected group_name {GROUP_NAME}, got {model_row['group_name']}"
161+
assert (
162+
model_row["group_name"] == GROUP_NAME
163+
), f"Expected group_name {GROUP_NAME}, got {model_row['group_name']}"
139164
finally:
140165
if model_path.exists():
141166
model_path.unlink()
@@ -154,31 +179,31 @@ def test_test_group_attribute(dbt_project: DbtProject):
154179
"name": model_name,
155180
"group": GROUP_NAME,
156181
"description": "A model assigned to a group for testing",
157-
"columns": [
158-
{
159-
"name": "col",
160-
"tests": ["unique"]
161-
}
162-
]
182+
"columns": [{"name": "col", "tests": ["unique"]}],
163183
}
164-
]
184+
],
165185
}
166186
model_sql = """
167187
select 1 as col
168188
"""
169-
with _write_group_config(dbt_project, GROUP_CONFIG, name="groups_test_model_inherits.yml"), \
170-
dbt_project.write_yaml(schema_yaml, name="schema_model_with_group.yml"):
189+
with _write_group_config(
190+
dbt_project, GROUP_CONFIG, name="groups_test_model_inherits.yml"
191+
), dbt_project.write_yaml(schema_yaml, name="schema_model_with_group.yml"):
171192
model_path = dbt_project.models_dir_path / "tmp" / f"{model_name}.sql"
172193
model_path.parent.mkdir(parents=True, exist_ok=True)
173194
model_path.write_text(model_sql)
174195
try:
175196
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
176197
dbt_project.dbt_runner.run(select=model_name)
177198
dbt_project.assert_table_exists("dbt_tests")
178-
tests = dbt_project.read_table("dbt_tests", where="name LIKE 'unique%'", raise_if_empty=True)
199+
tests = dbt_project.read_table(
200+
"dbt_tests", where="name LIKE 'unique%'", raise_if_empty=True
201+
)
179202
assert len(tests) == 1, f"Expected 1 test, got {len(tests)}"
180203
test_row = tests[0]
181-
assert test_row["group_name"] == GROUP_NAME, f"Expected group_name {GROUP_NAME}, got {test_row['group_name']}"
204+
assert (
205+
test_row["group_name"] == GROUP_NAME
206+
), f"Expected group_name {GROUP_NAME}, got {test_row['group_name']}"
182207
finally:
183208
if model_path.exists():
184209
model_path.unlink()
@@ -196,7 +221,10 @@ def test_test_override_group(dbt_project: DbtProject):
196221
group_config = {
197222
"groups": [
198223
{"name": test_group, "owner": {"name": OWNER_NAME, "email": OWNER_EMAIL}},
199-
{"name": override_group, "owner": {"name": "Override Owner", "email": "[email protected]"}},
224+
{
225+
"name": override_group,
226+
"owner": {"name": "Override Owner", "email": "[email protected]"},
227+
},
200228
]
201229
}
202230
schema_yaml = {
@@ -209,34 +237,33 @@ def test_test_override_group(dbt_project: DbtProject):
209237
"columns": [
210238
{
211239
"name": "col",
212-
"tests": [
213-
{
214-
"unique": {
215-
"config": {"group": override_group}
216-
}
217-
}
218-
]
240+
"tests": [{"unique": {"config": {"group": override_group}}}],
219241
}
220-
]
242+
],
221243
}
222-
]
244+
],
223245
}
224246
model_sql = """
225247
select 1 as col
226248
"""
227-
with _write_group_config(dbt_project, group_config, name="groups_test_override_group.yml"), \
228-
dbt_project.write_yaml(schema_yaml, name="schema_model_with_override_group.yml"):
249+
with _write_group_config(
250+
dbt_project, group_config, name="groups_test_override_group.yml"
251+
), dbt_project.write_yaml(schema_yaml, name="schema_model_with_override_group.yml"):
229252
model_path = dbt_project.models_dir_path / "tmp" / f"{model_name}.sql"
230253
model_path.parent.mkdir(parents=True, exist_ok=True)
231254
model_path.write_text(model_sql)
232255
try:
233256
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
234257
dbt_project.dbt_runner.run(select=model_name)
235258
dbt_project.assert_table_exists("dbt_tests")
236-
tests = dbt_project.read_table("dbt_tests", where="name LIKE 'unique%'", raise_if_empty=True)
259+
tests = dbt_project.read_table(
260+
"dbt_tests", where="name LIKE 'unique%'", raise_if_empty=True
261+
)
237262
assert len(tests) == 1, f"Expected 1 test, got {len(tests)}"
238263
test_row = tests[0]
239-
assert test_row["group_name"] == override_group, f"Expected group_name {override_group}, got {test_row['group_name']}"
264+
assert (
265+
test_row["group_name"] == override_group
266+
), f"Expected group_name {override_group}, got {test_row['group_name']}"
240267
finally:
241268
if model_path.exists():
242269
model_path.unlink()
@@ -258,25 +285,30 @@ def test_seed_group_attribute(dbt_project: DbtProject):
258285
"group": GROUP_NAME,
259286
"description": "A seed assigned to a group for testing",
260287
}
261-
]
288+
],
262289
}
263290

264291
seed_path = dbt_project.seeds_dir_path / f"{seed_name}.csv"
265292
try:
266-
with _write_group_config(dbt_project, GROUP_CONFIG, name="groups_test_seed_inherits.yml"), \
267-
dbt_project.write_yaml(schema_yaml, name="schema_seed_with_group.yml"):
293+
with _write_group_config(
294+
dbt_project, GROUP_CONFIG, name="groups_test_seed_inherits.yml"
295+
), dbt_project.write_yaml(schema_yaml, name="schema_seed_with_group.yml"):
268296
seed_path.parent.mkdir(parents=True, exist_ok=True)
269297
seed_path.write_text(seed_csv)
270298
# Run dbt seed
271299
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
272300
dbt_project.dbt_runner.seed(select=seed_name)
273301

274-
dbt_project.assert_table_exists('dbt_seeds')
302+
dbt_project.assert_table_exists("dbt_seeds")
275303

276-
seeds = dbt_project.read_table("dbt_seeds", where=f"name = '{seed_name}'", raise_if_empty=True)
304+
seeds = dbt_project.read_table(
305+
"dbt_seeds", where=f"name = '{seed_name}'", raise_if_empty=True
306+
)
277307
assert len(seeds) == 1, f"Expected 1 seed, got {len(seeds)}"
278308
seed_row = seeds[0]
279-
assert seed_row["group_name"] == GROUP_NAME, f"Expected group_name {GROUP_NAME}, got {seed_row['group_name']}"
309+
assert (
310+
seed_row["group_name"] == GROUP_NAME
311+
), f"Expected group_name {GROUP_NAME}, got {seed_row['group_name']}"
280312
finally:
281313
if seed_path.exists():
282314
seed_path.unlink()
@@ -306,29 +338,40 @@ def test_snapshot_group_attribute(dbt_project: DbtProject):
306338
"group": GROUP_NAME,
307339
"description": "A snapshot assigned to a group for testing",
308340
}
309-
]
341+
],
310342
}
311343
snapshots_dir = dbt_project.project_dir_path / "snapshots"
312344
snapshot_path = snapshots_dir / f"{snapshot_name}.sql"
313345
try:
314-
with _write_group_config(dbt_project, GROUP_CONFIG, name="groups_test_snapshot_inherits.yml"), \
315-
dbt_project.write_yaml(schema_yaml, name="schema_snapshot_with_group.yml"):
346+
with _write_group_config(
347+
dbt_project, GROUP_CONFIG, name="groups_test_snapshot_inherits.yml"
348+
), dbt_project.write_yaml(schema_yaml, name="schema_snapshot_with_group.yml"):
316349
snapshots_dir.mkdir(parents=True, exist_ok=True)
317350
snapshot_path.write_text(snapshot_sql)
318351
# Debug: print file existence and directory contents
319-
print(f"DEBUG: Snapshot file exists: {snapshot_path.exists()} at {snapshot_path}")
320-
print(f"DEBUG: Snapshots dir contents: {list(snapshots_dir.iterdir()) if snapshots_dir.exists() else 'DIR DOES NOT EXIST'}")
352+
print(
353+
f"DEBUG: Snapshot file exists: {snapshot_path.exists()} at {snapshot_path}"
354+
)
355+
print(
356+
f"DEBUG: Snapshots dir contents: {list(snapshots_dir.iterdir()) if snapshots_dir.exists() else 'DIR DOES NOT EXIST'}"
357+
)
321358
# Run dbt snapshot (runs all snapshots, as selecting is not supported by the runner)
322359
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
323360
dbt_project.dbt_runner.run()
324361

325-
dbt_project.assert_table_exists('dbt_snapshots')
362+
dbt_project.assert_table_exists("dbt_snapshots")
326363

327-
snapshots = dbt_project.read_table("dbt_snapshots", where=f"name = '{snapshot_name}'", raise_if_empty=False)
328-
assert snapshots, f"No rows found in dbt_snapshots for name = '{snapshot_name}'"
364+
snapshots = dbt_project.read_table(
365+
"dbt_snapshots", where=f"name = '{snapshot_name}'", raise_if_empty=False
366+
)
367+
assert (
368+
snapshots
369+
), f"No rows found in dbt_snapshots for name = '{snapshot_name}'"
329370
assert len(snapshots) == 1, f"Expected 1 snapshot, got {len(snapshots)}"
330371
snapshot_row = snapshots[0]
331-
assert snapshot_row["group_name"] == GROUP_NAME, f"Expected group_name {GROUP_NAME}, got {snapshot_row['group_name']}"
372+
assert (
373+
snapshot_row["group_name"] == GROUP_NAME
374+
), f"Expected group_name {GROUP_NAME}, got {snapshot_row['group_name']}"
332375
finally:
333376
if snapshot_path.exists():
334377
snapshot_path.unlink()

0 commit comments

Comments
 (0)