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 test_context_config_any(): context_defs = { 'test': PipelineContextDefinition( config_field=Field(Any), context_fn=lambda *args: ExecutionContext() ) } context_config_type = define_context_context_cls('something', context_defs).inst() assert context_config_type.type_attributes.is_system_config output = construct_context_config( throwing_evaluate_config_value(context_config_type, {'test': {'config': 1}}) ) assert output.name == 'test' assert output.config == 1
def test_context_config(): context_defs = { 'test': PipelineContextDefinition( config_field=Field(dagster_type=Dict({'some_str': Field(String)})), context_fn=lambda *args: ExecutionContext(), ) } context_config_type = define_context_context_cls('something', context_defs).inst() output = construct_context_config( throwing_evaluate_config_value( context_config_type, {'test': {'config': {'some_str': 'something'}}} ) ) assert isinstance(output, ContextConfig) assert output.name == 'test' assert output.config == {'some_str': 'something'}
def test_errors(): context_defs = { 'test': PipelineContextDefinition( config_field=Field(Dict({'required_int': Field(Int)})), context_fn=lambda *args: ExecutionContext(), ) } context_config_type = define_context_context_cls('something', context_defs).inst() assert not evaluate_config_value(context_config_type, 1).success assert not evaluate_config_value(context_config_type, {}).success invalid_value = {'context_one': 1, 'context_two': 2} result = evaluate_config_value(context_config_type, invalid_value) assert not result.success assert len(result.errors) == 1
def test_default_context_config(): pipeline_def = PipelineDefinition(solids=[ SolidDefinition(name='some_solid', inputs=[], outputs=[], transform_fn=lambda *args: None) ]) context_config_type = define_context_context_cls( pipeline_def.name, pipeline_def.context_definitions).inst() assert 'default' in context_config_type.fields assert context_config_type.fields['default'].is_optional default_context_config_type = context_config_type.fields[ 'default'].config_type assert 'config' in default_context_config_type.fields context_dict = throwing_evaluate_config_value(context_config_type, {}) assert 'default' in context_dict