Skip to content

Commit

Permalink
RFC: asset tutorial without AssetGroups (#7909)
Browse files Browse the repository at this point in the history
  • Loading branch information
sryza committed Jun 10, 2022
1 parent e2f3342 commit 2fbac77
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions docs/content/tutorial/assets/defining-an-asset.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ Success!
If you'd rather materialize your asset as a script, you can do that without spinning up Dagit. Just add a few lines to `cereal.py`. This executes a run within the Python process.

```python file=/guides/dagster/asset_tutorial/cereal.py startafter=start_materialize_marker endbefore=end_materialize_marker
from dagster import AssetGroup
from dagster import materialize

if __name__ == "__main__":
AssetGroup([cereals]).materialize()
materialize([cereals])
```

Now you can just run:
Expand Down
26 changes: 12 additions & 14 deletions docs/content/tutorial/assets/testing-assets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ def test_nabisco_cereals():
assert result == [{"name": "cereal1", "mfr": "N"}]
```

We'll also write a test for all the assets together. To do that, we need to combine them into an <PyObject object="AssetGroup" />. Then, we can invoke <PyObject object="AssetGroup" method="materialize_in_process" />, which returns an <PyObject module="dagster" object="ExecuteInProcessResult" />, whose methods let us investigate, in detail, the success or failure of execution, the values produced by the computation, and (as we'll see later) other events associated with execution.
We'll also write a test for all the assets together. To do that, we can put them in a list and then pass it to the <PyObject object="materialize" /> function. That returns an <PyObject object="ExecuteInProcessResult" />, whose methods let us investigate, in detail, the success or failure of execution, the values produced by the computation, and other events associated with execution.

```python file=/guides/dagster/asset_tutorial/complex_asset_graph_tests.py startafter=start_asset_group_test endbefore=end_asset_group_test
from dagster import AssetGroup
```python file=/guides/dagster/asset_tutorial/complex_asset_graph_tests.py startafter=start_all_assets_test endbefore=end_all_assets_test
from dagster import materialize


def test_cereal_asset_group():
group = AssetGroup(
[
nabisco_cereals,
cereals,
cereal_protein_fractions,
highest_protein_nabisco_cereal,
]
)
def test_cereal_assets():
assets = [
nabisco_cereals,
cereals,
cereal_protein_fractions,
highest_protein_nabisco_cereal,
]

result = group.materialize()
result = materialize(assets)
assert result.success
assert result.output_for_node("highest_protein_nabisco_cereal") == "100% Bran"
```
Expand All @@ -57,7 +55,7 @@ Dagster is written to make testing easy in a domain where it has historically be

## Conclusion

🎉 Congratulations! Having reached this far, you now have a working, tested group of software-defined assets.
🎉 Congratulations! Having reached this far, you now have a working, tested set of software-defined assets.

What if you want to do more?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def cereals():
# end_asset_marker

# start_materialize_marker
from dagster import AssetGroup
from dagster import materialize

if __name__ == "__main__":
AssetGroup([cereals]).materialize()
materialize([cereals])

# end_materialize_marker
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@ def test_nabisco_cereals():

# end_asset_test

# start_asset_group_test
from dagster import AssetGroup
# start_all_assets_test
from dagster import materialize


def test_cereal_asset_group():
group = AssetGroup(
[
nabisco_cereals,
cereals,
cereal_protein_fractions,
highest_protein_nabisco_cereal,
]
)
def test_cereal_assets():
assets = [
nabisco_cereals,
cereals,
cereal_protein_fractions,
highest_protein_nabisco_cereal,
]

result = group.materialize()
result = materialize(assets)
assert result.success
assert result.output_for_node("highest_protein_nabisco_cereal") == "100% Bran"


# end_asset_group_test
# end_all_assets_test
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from dagster import AssetGroup
from dagster import load_assets_from_modules, materialize
from docs_snippets.guides.dagster.asset_tutorial import complex_asset_graph
from docs_snippets.guides.dagster.asset_tutorial.complex_asset_graph_tests import ( # pylint: disable=unused-import
test_cereal_asset_group,
test_cereal_assets,
test_nabisco_cereals,
)
from docs_snippets.intro_tutorial.test_util import patch_cereal_requests


@patch_cereal_requests
def test_complex_asset_graph():
result = AssetGroup.from_modules([complex_asset_graph]).materialize()
result = materialize(load_assets_from_modules([complex_asset_graph]))
assert result.success

1 comment on commit 2fbac77

@vercel
Copy link

@vercel vercel bot commented on 2fbac77 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.