-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
242 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
python_modules/dagster/dagster_tests/definitions_tests/test_asset_check_selection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
from dagster import ( | ||
AssetCheckResult, | ||
AssetSelection, | ||
Definitions, | ||
ExecuteInProcessResult, | ||
asset, | ||
asset_check, | ||
define_asset_job, | ||
) | ||
from dagster._core.definitions.asset_check_spec import AssetCheckHandle | ||
from dagster._core.definitions.unresolved_asset_job_definition import UnresolvedAssetJobDefinition | ||
|
||
|
||
@asset | ||
def asset1(): | ||
... | ||
|
||
|
||
@asset | ||
def asset2(): | ||
... | ||
|
||
|
||
@asset_check(asset=asset1) | ||
def asset1_check1(): | ||
return AssetCheckResult(success=True) | ||
|
||
|
||
@asset_check(asset=asset1) | ||
def asset1_check2(): | ||
return AssetCheckResult(success=True) | ||
|
||
|
||
@asset_check(asset=asset2) | ||
def asset2_check1(): | ||
return AssetCheckResult(success=True) | ||
|
||
|
||
def execute_asset_job_in_process(asset_job: UnresolvedAssetJobDefinition) -> ExecuteInProcessResult: | ||
assets = [asset1, asset2] | ||
asset_checks = [asset1_check1, asset1_check2, asset2_check1] | ||
defs = Definitions(assets=assets, jobs=[asset_job], asset_checks=asset_checks) | ||
job_def = defs.get_job_def(asset_job.name) | ||
return job_def.execute_in_process() | ||
|
||
|
||
def test_job_with_all_checks_no_materializations(): | ||
job_def = define_asset_job("job1", selection=AssetSelection.all_asset_checks()) | ||
result = execute_asset_job_in_process(job_def) | ||
assert result.success | ||
|
||
assert len(result.get_asset_materialization_events()) == 0 | ||
check_evals = result.get_asset_check_evaluations() | ||
assert {check_eval.asset_check_handle for check_eval in check_evals} == { | ||
AssetCheckHandle(asset1.key, "asset1_check1"), | ||
AssetCheckHandle(asset1.key, "asset1_check2"), | ||
AssetCheckHandle(asset2.key, "asset2_check1"), | ||
} | ||
|
||
|
||
def test_job_with_all_checks_for_asset(): | ||
job_def = define_asset_job("job1", selection=AssetSelection.checks_for_asset(asset1)) | ||
result = execute_asset_job_in_process(job_def) | ||
assert result.success | ||
|
||
assert len(result.get_asset_materialization_events()) == 0 | ||
check_evals = result.get_asset_check_evaluations() | ||
assert {check_eval.handle for check_eval in check_evals} == { | ||
AssetCheckHandle(asset1.key, "asset1_check1"), | ||
AssetCheckHandle(asset1.key, "asset1_check2"), | ||
} | ||
|
||
|
||
# def test_job_with_asset_and_all_its_checks(): | ||
# job_def = define_asset_job("job1", selection=AssetSelection.assets(asset1)) | ||
# result = execute_asset_job_in_process(job_def) | ||
# assert result.success | ||
|
||
# assert len(result.get_asset_materialization_events()) == 1 | ||
# check_evals = result.get_asset_check_evaluations() | ||
# assert {check_eval.handle for check_eval in check_evals} == { | ||
# AssetCheckHandle(asset1.key, "asset1_check1"), | ||
# AssetCheckHandle(asset1.key, "asset1_check2"), | ||
# } | ||
|
||
|
||
# def test_job_with_single_check(): | ||
# job_def = define_asset_job("job1", selection=AssetSelection.asset_checks(asset1_check1)) | ||
# result = execute_asset_job_in_process(job_def) | ||
# assert result.success | ||
|
||
# assert len(result.get_asset_materialization_events()) == 0 | ||
# check_evals = result.get_asset_check_evaluations() | ||
# assert {check_eval.handle for check_eval in check_evals} == { | ||
# AssetCheckHandle(asset1.key, "asset1_check1"), | ||
# } | ||
|
||
|
||
# def test_job_with_all_assets_but_no_checks(): | ||
# job_def = define_asset_job( | ||
# "job1", selection=AssetSelection.all_assets() - AssetSelection.all_asset_checks(asset1_check1) | ||
# ) | ||
# result = execute_asset_job_in_process(job_def) | ||
# assert result.success | ||
|
||
# assert len(result.get_asset_materialization_events()) == 2 | ||
# check_evals = result.get_asset_check_evaluations() | ||
# assert len(check_evals) == 0 | ||
|
||
|
||
# def test_job_with_asset_without_its_checks(): | ||
# job_def = define_asset_job( | ||
# "job1", selection=AssetSelection.assets(asset1) - AssetSelection.all_asset_checks() | ||
# ) | ||
# result = execute_asset_job_in_process(job_def) | ||
# assert result.success | ||
|
||
# assert len(result.get_asset_materialization_events()) == 1 | ||
# check_evals = result.get_asset_check_evaluations() | ||
# assert len(check_evals) == 0 | ||
|
||
|
||
# def test_job_with_all_assets_and_all_checks(): | ||
# job_def = define_asset_job("job1", selection=AssetSelection.all_assets()) | ||
# result = execute_asset_job_in_process(job_def) | ||
# assert result.success | ||
|
||
# assert len(result.get_asset_materialization_events()) == 2 | ||
# check_evals = result.get_asset_check_evaluations() | ||
# assert len(check_evals) == 3 | ||
|
||
|
||
# def test_job_with_all_assets_and_all_but_one_check(): | ||
# job_def = define_asset_job( | ||
# "job1", selection=AssetSelection.all_assets() - AssetSelection.asset_checks(asset1_check1) | ||
# ) | ||
# result = execute_asset_job_in_process(job_def) | ||
# assert result.success | ||
|
||
# assert len(result.get_asset_materialization_events()) == 2 | ||
# check_evals = result.get_asset_check_evaluations() | ||
# assert {check_eval.handle for check_eval in check_evals} == { | ||
# AssetCheckHandle(asset1.key, "asset1_check2"), | ||
# AssetCheckHandle(asset2.key, "asset2_check1"), | ||
# } | ||
|
||
|
||
# def test_include_asset_after_excluding_checks(): | ||
# job_def = define_asset_job( | ||
# "job1", | ||
# selection=(AssetSelection.all_assets() - AssetSelection.all_asset_checks()) | ||
# & AssetSelection.assets(asset1), | ||
# ) | ||
# result = execute_asset_job_in_process(job_def) | ||
# assert result.success | ||
|
||
# assert len(result.get_asset_materialization_events()) == 2 | ||
# check_evals = result.get_asset_check_evaluations() | ||
# assert {check_eval.handle for check_eval in check_evals} == { | ||
# AssetCheckHandle(asset1.key, "asset1_check1"), | ||
# AssetCheckHandle(asset1.key, "asset1_check2"), | ||
# } |