Differential D4697 Diff 23458 python_modules/dagster/dagster_tests/core_tests/resource_tests/test_required_resources.py
Changeset View
Changeset View
Standalone View
Standalone View
python_modules/dagster/dagster_tests/core_tests/resource_tests/test_required_resources.py
Show First 20 Lines • Show All 463 Lines • ▼ Show 20 Lines | def define_materialization_pipeline(should_require_resources=True, resources_initted=None): | ||||
if resources_initted is None: | if resources_initted is None: | ||||
resources_initted = {} | resources_initted = {} | ||||
@resource | @resource | ||||
def resource_a(_): | def resource_a(_): | ||||
resources_initted["a"] = True | resources_initted["a"] = True | ||||
yield "A" | yield "A" | ||||
@dagster_type_loader( | |||||
String, required_resource_keys={"a"} if should_require_resources else set() | |||||
) | |||||
def load(context, hello): | |||||
assert context.resources.a == "A" | |||||
return hello | |||||
@dagster_type_materializer( | @dagster_type_materializer( | ||||
String, required_resource_keys={"a"} if should_require_resources else set() | String, required_resource_keys={"a"} if should_require_resources else set() | ||||
) | ) | ||||
def materialize(context, *_args, **_kwargs): | def materialize(context, *_args, **_kwargs): | ||||
assert context.resources.a == "A" | assert context.resources.a == "A" | ||||
return AssetMaterialization("hello") | return AssetMaterialization("hello") | ||||
CustomDagsterType = create_any_type(name="CustomType", materializer=materialize) | CustomDagsterType = create_any_type(name="CustomType", materializer=materialize, loader=load) | ||||
@solid(output_defs=[OutputDefinition(CustomDagsterType)]) | @solid(output_defs=[OutputDefinition(CustomDagsterType)]) | ||||
def output_solid(_context): | def output_solid(_context): | ||||
return "hello" | return "hello" | ||||
@pipeline(mode_defs=[ModeDefinition(resource_defs={"a": resource_a})]) | @pipeline(mode_defs=[ModeDefinition(resource_defs={"a": resource_a})]) | ||||
def output_pipeline(): | def output_pipeline(): | ||||
output_solid() | output_solid() | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |