def test_with_context_should_inject_dependencies_properly(tmpdir): data_inputs = np.array([0, 1, 2, 3]) context = ExecutionContext(root=tmpdir) service = SomeService() context.set_service_locator({BaseService: service}) p = Pipeline([SomeStep().assert_has_services(BaseService) ]).with_context(context=context) p.transform(data_inputs=data_inputs) assert np.array_equal(service.data, data_inputs)
def test_step_with_context_should_only_save_wrapped_step(tmpdir): context = ExecutionContext(root=tmpdir) service = SomeService() context.set_service_locator({BaseService: service}) p = Pipeline([SomeStep().assert_has_services(BaseService) ]).with_context(context=context) p.save(context, full_dump=True) p: Pipeline = ExecutionContext(root=tmpdir).load( os.path.join('StepWithContext', 'Pipeline')) assert isinstance(p, Pipeline)
def test_step_with_context_saver(tmpdir): context = ExecutionContext(root=tmpdir) service = SomeService() pipeline_name = 'testname' context.set_service_locator({SomeBaseService: service}) p = Pipeline([ SomeStep().assert_has_services(SomeBaseService) ]).with_context(context=context) p.set_name(pipeline_name) p.save(context, full_dump=True) p: StepWithContext = ExecutionContext(root=tmpdir).load(pipeline_name) assert isinstance(p, StepWithContext) p: Pipeline = ExecutionContext(root=tmpdir).load(os.path.join(pipeline_name, 'Pipeline')) assert isinstance(p, Pipeline)
def test_auto_ml_should_inject_dependencies_properly(tmpdir): data_inputs = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) expected_outputs = data_inputs * 2 p = Pipeline([ SomeStep().assert_has_services(SomeBaseService), SomeStep().assert_has_services_at_execution(SomeBaseService) ]) context = ExecutionContext(root=tmpdir) service = SomeService() context.set_service_locator({SomeBaseService: service}) auto_ml: AutoML = _make_autoML_loop(tmpdir, p) auto_ml: StepWithContext = auto_ml.with_context(context=context) assert isinstance(auto_ml, StepWithContext) auto_ml.fit(data_inputs, expected_outputs) assert np.array_equal(service.data, data_inputs)