-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Direct invocation of assets for unit testing (#6761)
- Loading branch information
jamiedemaria
committed
Feb 25, 2022
1 parent
ee07c9c
commit ef3ad62
Showing
5 changed files
with
209 additions
and
2 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
63 changes: 63 additions & 0 deletions
63
examples/docs_snippets/docs_snippets/concepts/assets/asset_testing.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,63 @@ | ||
# pylint: disable=redefined-outer-name | ||
from dagster import asset, build_op_context | ||
|
||
# start_simple_asset | ||
|
||
|
||
@asset | ||
def my_simple_asset(): | ||
return [1, 2, 3] | ||
|
||
|
||
# end_simple_asset | ||
|
||
# start_test_simple_asset | ||
|
||
|
||
def test_my_simple_asset(): | ||
result = my_simple_asset() | ||
assert result == [1, 2, 3] | ||
|
||
|
||
# end_test_simple_asset | ||
|
||
# start_more_complex_asset | ||
|
||
|
||
@asset | ||
def more_complex_asset(my_simple_asset): | ||
return my_simple_asset + [4, 5, 6] | ||
|
||
|
||
# end_more_complex_asset | ||
|
||
# start_test_more_complex_asset | ||
|
||
|
||
def test_more_complex_asset(): | ||
result = more_complex_asset([0]) | ||
assert result == [0, 4, 5, 6] | ||
|
||
|
||
# end_test_more_complex_asset | ||
|
||
# start_with_context_asset | ||
|
||
|
||
@asset | ||
def uses_context(context): | ||
return context.resources.foo | ||
|
||
|
||
# end_with_context_asset | ||
|
||
# start_test_with_context_asset | ||
|
||
|
||
def test_uses_context(): | ||
context = build_op_context(resources={"foo": "bar"}) | ||
result = uses_context(context) | ||
assert result == "bar" | ||
|
||
|
||
# end_test_with_context_asset |
12 changes: 12 additions & 0 deletions
12
examples/docs_snippets/docs_snippets/concepts/assets/asset_w_context.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,12 @@ | ||
from dagster import asset | ||
|
||
# start_w_context | ||
|
||
|
||
@asset(required_resource_keys={"api"}) | ||
def my_asset(context): | ||
# fetches contents of an asset | ||
return context.resources.api.fetch_table("my_asset") | ||
|
||
|
||
# end_w_context |
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
ef3ad62
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dagster – ./docs/next
docs.dagster.io
dagster.vercel.app
dagster-elementl.vercel.app
new-docs.dagster.io
dagster-git-master-elementl.vercel.app