def test_create_instance_from_plugin_with_kwargs(self, tmpdir, params): workflow = flexmock(data=flexmock()) workflow.data.image_id = 'image-id' workflow.source = flexmock() workflow.source.dockerfile_path = 'dockerfile-path' workflow.source.path = 'path' workflow.user_params = {} class MyPlugin(BuildPlugin): key = 'my_plugin' def __init__(self, workflow, spam=None, **kwargs): self.spam = spam for key, value in kwargs.items(): setattr(self, key, value) def run(self): pass bpr = BuildPluginsRunner(workflow, 'PreBuildPlugin', {}) plugin = bpr.create_instance_from_plugin(MyPlugin, params) for key, value in params.items(): assert getattr(plugin, key) == value
def test_create_instance_from_plugin(self, tmpdir, params): workflow = flexmock(data=flexmock()) workflow.data.image_id = 'image-id' workflow.source = flexmock() workflow.source.dockerfile_path = 'dockerfile-path' workflow.source.path = 'path' workflow.user_params = {'shrubbery': 'yrebburhs'} class MyPlugin(BuildPlugin): key = 'my_plugin' @staticmethod def args_from_user_params(user_params): return {'shrubbery': user_params['shrubbery']} def __init__(self, workflow, spam=None, shrubbery=None): self.spam = spam self.shrubbery = shrubbery def run(self): pass bpr = BuildPluginsRunner(workflow, 'PreBuildPlugin', {}) plugin = bpr.create_instance_from_plugin(MyPlugin, params) assert plugin.spam == params['spam'] assert plugin.shrubbery == 'yrebburhs'
def test_create_instance_from_plugin(self, tmpdir, params): workflow = flexmock() workflow.builder = flexmock() workflow.builder.image_id = 'image-id' workflow.builder.source = flexmock() workflow.builder.source.dockerfile_path = 'dockerfile-path' workflow.builder.source.path = 'path' workflow.builder.base_image = flexmock() workflow.builder.base_image.to_str = lambda: 'base-image' tasker = flexmock() class MyPlugin(object): def __init__(self, tasker, workflow, spam=None): self.spam = spam bpr = BuildPluginsRunner(tasker, workflow, 'PreBuildPlugin', {}) plugin = bpr.create_instance_from_plugin(MyPlugin, params) assert plugin.spam == params['spam']
def test_create_instance_from_plugin_with_kwargs(self, tmpdir, params): workflow = flexmock() workflow.builder = flexmock() workflow.builder.image_id = 'image-id' workflow.builder.source = flexmock() workflow.builder.source.dockerfile_path = 'dockerfile-path' workflow.builder.source.path = 'path' workflow.builder.base_image = flexmock() workflow.builder.base_image.to_str = lambda: 'base-image' tasker = flexmock() class MyPlugin(object): def __init__(self, tasker, workflow, spam=None, **kwargs): self.spam = spam for key, value in kwargs.items(): setattr(self, key, value) bpr = BuildPluginsRunner(tasker, workflow, 'PreBuildPlugin', {}) plugin = bpr.create_instance_from_plugin(MyPlugin, params) for key, value in params.items(): assert getattr(plugin, key) == value