Skip to content

Commit 539119b

Browse files
authored
Merge pull request #359 from elementary-data/ele-900-fix-integration-tests-for-dbt-150
integration test: fix for dbt 1.5.0
2 parents d3b2eb3 + afc2aa4 commit 539119b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

integration_tests/integration_tests/dbt_project.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
from pathlib import Path
3+
14
import dbt.adapters.factory
25

36
dbt.adapters.factory.get_adapter = lambda config: config.adapter
@@ -27,6 +30,24 @@
2730
disable_tracking()
2831

2932

33+
def default_project_dir() -> Path:
34+
if "DBT_PROJECT_DIR" in os.environ:
35+
return Path(os.environ["DBT_PROJECT_DIR"]).resolve()
36+
paths = list(Path.cwd().parents)
37+
paths.insert(0, Path.cwd())
38+
return next((x for x in paths if (x / "dbt_project.yml").exists()), Path.cwd())
39+
40+
41+
def default_profiles_dir() -> Path:
42+
if "DBT_PROFILES_DIR" in os.environ:
43+
return Path(os.environ["DBT_PROFILES_DIR"]).resolve()
44+
return Path.cwd() if (Path.cwd() / "profiles.yml").exists() else Path.home() / ".dbt"
45+
46+
47+
DEFAULT_PROFILES_DIR = str(default_profiles_dir())
48+
DEFAULT_PROJECT_DIR = str(default_project_dir())
49+
50+
3051
class DbtProject:
3152
def __init__(self, project_dir, target=None):
3253
args = Args(project_dir=project_dir, target=target)
@@ -133,7 +154,8 @@ class Args(BaseModel):
133154
Minimal mock to dbt config arguments
134155
"""
135156

136-
project_dir: str
157+
project_dir: str = DEFAULT_PROJECT_DIR
158+
profiles_dir: str = DEFAULT_PROFILES_DIR
137159
profile: str = None
138160
target: Optional[str] = None
139161
threads: Optional[int] = 1

0 commit comments

Comments
 (0)