Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions tests/dbt/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@
SAMPLE_DBT_LS_OUTPUT = Path(__file__).parent.parent / "sample/sample_dbt_ls.txt"
SOURCE_RENDERING_BEHAVIOR = SourceRenderingBehavior(os.getenv("SOURCE_RENDERING_BEHAVIOR", "none"))

# File and directory names to skip when copying dbt project trees in tests (keeps fixture output deterministic).
_DBT_PROJECT_COPY_IGNORED_FILE_AND_DIR_NAMES = (".user.yml", ".DS_Store", "logs", "target")

if AIRFLOW_VERSION.major >= _AIRFLOW3_MAJOR_VERSION:
object_storage_path = "airflow.sdk.ObjectStoragePath"
else:
object_storage_path = "airflow.io.path.ObjectStoragePath"


def _ignore_when_copying_dbt_project(directory: str, names: list[str]) -> list[str]:
"""Names to skip in copytree so the fixture tree is deterministic."""
return [name for name in names if name in _DBT_PROJECT_COPY_IGNORED_FILE_AND_DIR_NAMES]


@pytest.fixture
def tmp_dbt_project_dir():
"""
Expand All @@ -66,9 +74,7 @@ def tmp_dbt_project_dir():

tmp_dir = Path(tempfile.mkdtemp())
target_proj_dir = tmp_dir / DBT_PROJECT_NAME
shutil.copytree(source_proj_dir, target_proj_dir)
shutil.rmtree(target_proj_dir / "logs", ignore_errors=True)
shutil.rmtree(target_proj_dir / "target", ignore_errors=True)
shutil.copytree(source_proj_dir, target_proj_dir, ignore=_ignore_when_copying_dbt_project)
yield tmp_dir

shutil.rmtree(tmp_dir, ignore_errors=True) # delete directory
Expand All @@ -83,9 +89,7 @@ def tmp_altered_dbt_project_dir():

tmp_dir = Path(tempfile.mkdtemp())
target_proj_dir = tmp_dir / ALTERED_DBT_PROJECT_NAME
shutil.copytree(source_proj_dir, target_proj_dir)
shutil.rmtree(target_proj_dir / "logs", ignore_errors=True)
shutil.rmtree(target_proj_dir / "target", ignore_errors=True)
shutil.copytree(source_proj_dir, target_proj_dir, ignore=_ignore_when_copying_dbt_project)
yield tmp_dir

shutil.rmtree(tmp_dir, ignore_errors=True) # delete directory
Expand Down