def create_test_context():
    return ExecutionContext()
Exemple #2
0
def silencing_default_context():
    return {
        'default':
        PipelineContextDefinition(context_fn=lambda *_args: ExecutionContext())
    }
Exemple #3
0
 def construct_context(info):
     called['yes'] = True
     assert uuid.UUID(info.run_id)
     return ExecutionContext()
 def _create_context(_info):
     return ExecutionContext(tags={'foo': 'baaz'})
Exemple #5
0
def test_invalid_context():
    @lambda_solid
    def never_transform():
        raise Exception('should never execute')

    default_context_pipeline = PipelineDefinition(
        name='default_context_pipeline', solids=[never_transform])

    environment_context_not_found = {'context': {'not_found': {}}}

    with pytest.raises(
            PipelineConfigEvaluationError,
            match='Undefined field "not_found" at path root:context'):
        execute_pipeline(default_context_pipeline,
                         environment=environment_context_not_found,
                         throw_on_error=True)

    environment_field_name_mismatch = {
        'context': {
            'default': {
                'config': {
                    'unexpected': 'value'
                }
            }
        }
    }

    with pytest.raises(PipelineConfigEvaluationError,
                       match='Undefined field "unexpected"'):
        execute_pipeline(
            default_context_pipeline,
            environment=environment_field_name_mismatch,
            throw_on_error=True,
        )

    with_argful_context_pipeline = PipelineDefinition(
        solids=[never_transform],
        context_definitions={
            'default':
            PipelineContextDefinition(
                config_field=Field(Dict({'string_field': Field(String)})),
                context_fn=lambda info: ExecutionContext(resources=info.config
                                                         ),
            )
        },
    )

    environment_no_config_error = {'context': {'default': {'config': {}}}}

    with pytest.raises(
            PipelineConfigEvaluationError,
            match=
        ('Error 1: Missing required field  "string_field" at path '
         'root:context:default:config Expected: "{ string_field: String }"'),
    ):
        execute_pipeline(
            with_argful_context_pipeline,
            environment=environment_no_config_error,
            throw_on_error=True,
        )

    environment_type_mismatch_error = {
        'context': {
            'default': {
                'config': {
                    'string_field': 1
                }
            }
        }
    }

    with pytest.raises(
            PipelineConfigEvaluationError,
            match=
        ('Error 1: Type failure at path "root:context:default:config:string_field" '
         'on type "String". Got "1". Value "1" at path '
         'root:context:default:config:string_field is not valid. Expected "String".'
         ),
    ):
        execute_pipeline(
            with_argful_context_pipeline,
            environment=environment_type_mismatch_error,
            throw_on_error=True,
        )
Exemple #6
0
 def _yield_context(info):
     events.append('before')
     tags = {'foo': 'bar'}
     context = ExecutionContext(resources=info.config, tags=tags)
     yield context
     events.append('after')
 def _create_context(_context):
     return ExecutionContext(tags={'quux': 'baaz'})
Exemple #8
0
def create_lambda_context():
    return PipelineContextDefinition(
        context_fn=lambda info: ExecutionContext.console_logging(
            log_level=logging.DEBUG),
        resources={'dagma': define_dagma_resource()},
    )
def test_invalid_context():
    @lambda_solid
    def never_transform():
        raise Exception('should never execute')

    default_context_pipeline = PipelineDefinition(
        name='default_context_pipeline', solids=[never_transform])

    environment_context_not_found = {'context': {'not_found': {}}}

    with pytest.raises(
            PipelineConfigEvaluationError,
            match='Undefined field "not_found" at path root:context'):
        execute_pipeline(default_context_pipeline,
                         environment_dict=environment_context_not_found)

    environment_field_name_mismatch = {
        'context': {
            'default': {
                'config': {
                    'unexpected': 'value'
                }
            }
        }
    }

    with pytest.raises(PipelineConfigEvaluationError,
                       match='Undefined field "unexpected"'):
        execute_pipeline(default_context_pipeline,
                         environment_dict=environment_field_name_mismatch)

    with_argful_context_pipeline = PipelineDefinition(
        solids=[never_transform],
        context_definitions={
            'default':
            PipelineContextDefinition(
                config_field=Field(Dict({'string_field': Field(String)})),
                context_fn=lambda init_context: ExecutionContext(
                    resources=init_context.context_config),
            )
        },
    )

    environment_no_config_error = {'context': {'default': {'config': {}}}}

    with pytest.raises(
            PipelineConfigEvaluationError,
            # match=(
            #     'Error 1: Missing required field  "string_field" at path '
            #     'root:context:default:config Expected: "{ string_field: String }"'
            # ),
    ) as pe_info_one:
        execute_pipeline(with_argful_context_pipeline,
                         environment_dict=environment_no_config_error)

    assert len(pe_info_one.value.errors) == 1

    assert pe_info_one.value.errors[0].message == (
        '''Missing required field "string_field" at path root:context:default:config '''
        '''Available Fields: "['string_field']".''')

    environment_type_mismatch_error = {
        'context': {
            'default': {
                'config': {
                    'string_field': 1
                }
            }
        }
    }

    with pytest.raises(
            PipelineConfigEvaluationError,
            match=
        ('Error 1: Type failure at path "root:context:default:config:string_field" '
         'on type "String". Value at path '
         'root:context:default:config:string_field is not valid. Expected "String".'
         ),
    ):
        execute_pipeline(with_argful_context_pipeline,
                         environment_dict=environment_type_mismatch_error)