feat: expand testing

This commit is contained in:
Stijnvandenbroek
2026-03-04 22:18:30 +00:00
parent 0d2706a93e
commit 0b9b408714
22 changed files with 1266 additions and 54 deletions

View File

@@ -0,0 +1,11 @@
from data_platform.ops.check_source_freshness import (
SourceFreshnessConfig,
check_source_freshness,
)
from data_platform.ops.elementary import elementary_generate_report
__all__ = [
"check_source_freshness",
"SourceFreshnessConfig",
"elementary_generate_report",
]

View File

@@ -0,0 +1,25 @@
"""dbt source freshness op."""
from dagster import Config, OpExecutionContext, op
from dagster_dbt import DbtCliResource
class SourceFreshnessConfig(Config):
"""Config for the source freshness op."""
source_name: str
@op
def check_source_freshness(
context: OpExecutionContext,
config: SourceFreshnessConfig,
dbt: DbtCliResource,
) -> None:
"""Run dbt source freshness for the configured source."""
list(
dbt.cli(
["source", "freshness", "--select", f"source:{config.source_name}"],
context=context,
).stream()
)

View File

@@ -0,0 +1,31 @@
"""Elementary report generation op."""
import subprocess
from pathlib import Path
from dagster import OpExecutionContext, op
_DBT_DIR = Path(__file__).parents[2] / "dbt"
@op
def elementary_generate_report(context: OpExecutionContext) -> None:
"""Run edr report to regenerate the Elementary HTML report."""
cmd = [
"edr",
"report",
"--profiles-dir",
str(_DBT_DIR),
"--project-dir",
str(_DBT_DIR),
"--disable-open-browser",
]
context.log.info(f"Running: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.stdout:
context.log.info(result.stdout)
if result.stderr:
context.log.warning(result.stderr)
if result.returncode != 0:
raise Exception(f"edr report failed with exit code {result.returncode}")
context.log.info("Elementary report generated successfully.")