def test_select_context(): context_defs = { 'int_context': PipelineContextDefinition( config_field=Field(Int), context_fn=lambda *args: ExecutionContext() ), 'string_context': PipelineContextDefinition( config_field=Field(String), context_fn=lambda *args: ExecutionContext() ), } context_config_type = define_context_context_cls('something', context_defs).inst() assert construct_context_config( throwing_evaluate_config_value(context_config_type, {'int_context': {'config': 1}}) ) == ContextConfig(name='int_context', config=1) assert construct_context_config( throwing_evaluate_config_value(context_config_type, {'string_context': {'config': 'bar'}}) ) == ContextConfig(name='string_context', config='bar') # mismatched field type mismatch with pytest.raises(DagsterEvaluateConfigValueError): assert throwing_evaluate_config_value( context_config_type, {'int_context': {'config': 'bar'}} ) # mismatched field type mismatch with pytest.raises(DagsterEvaluateConfigValueError): assert throwing_evaluate_config_value( context_config_type, {'string_context': {'config': 1}} )
def construct_context_config(config_value): context_name, context_value = single_item(config_value) return ContextConfig( name=context_name, config=context_value.get('config'), resources=context_value['resources'], persistence=context_value['persistence'], )
def test_whole_environment(): pipeline_def = PipelineDefinition( name='some_pipeline', context_definitions={ 'test': PipelineContextDefinition( config_field=Field(Any), context_fn=lambda *args: ExecutionContext()) }, solids=[ SolidDefinition( name='int_config_solid', config_field=Field(Int), inputs=[], outputs=[], transform_fn=lambda *args: None, ), SolidDefinition(name='no_config_solid', inputs=[], outputs=[], transform_fn=lambda *args: None), ], ) environment_type = pipeline_def.environment_type assert environment_type.fields[ 'context'].config_type.name == 'SomePipeline.ContextConfig' solids_type = environment_type.fields['solids'].config_type assert solids_type.name == 'SomePipeline.SolidsConfigDictionary' assert (solids_type.fields['int_config_solid'].config_type.name == 'SomePipeline.SolidConfig.IntConfigSolid') assert (environment_type.fields['expectations'].config_type.name == 'SomePipeline.ExpectationsConfig') env = construct_environment_config( throwing_evaluate_config_value( pipeline_def.environment_type, { 'context': { 'test': { 'config': 1 } }, 'solids': { 'int_config_solid': { 'config': 123 } } }, )) assert isinstance(env, EnvironmentConfig) assert env.context == ContextConfig('test', 1, persistence={'file': {}}) assert env.solids == {'int_config_solid': SolidConfig(123)} assert env.expectations == ExpectationsConfig(evaluate=True)