def extra_prepare_after_activation(self, configuration, args_dict): """Called after the configuration.converters are activated""" def task_maker(name, description=None, action=None, label="Project", **options): if not action: action = name self.task_overrides[name] = Task(action=action, description=description, options=options, label=label) return self.task_overrides[name] # Post register our addons extra_args = {"harpoon.crosshairs": {"task_maker": task_maker}} self.register.post_register(extra_args) # Make the task finder task_finder = TaskFinder(self) self.configuration["task_runner"] = task_finder.task_runner task_finder.find_tasks(getattr(self, "task_overrides", {}))
def extra_prepare_after_activation(self, configuration, args_dict): """ Called after the configuration.converters are activated Here we create our ``task_maker`` helper that we pass into ``post_register`` for our ``option_merge_addon_hook`` functions. We also create a ``task_finder`` for doing task finding related duties. """ def task_maker(name, description=None, action=None, label="Project", **options): if not action: action = name self.task_overrides[name] = Task(action=action, description=description, options=options, label=label) return self.task_overrides[name] # Post register our addons extra_args = {"harpoon.crosshairs": {"task_maker": task_maker}} self.register.post_register(extra_args) # Make the task finder task_finder = TaskFinder(self) configuration["task_runner"] = task_finder.task_runner task_finder.find_tasks(self.task_overrides)
describe "Finding tasks": it "returns default tasks with overrides added": configuration = {"images": {}} collector = mock.Mock(name="collector", configuration=configuration) task_finder = TaskFinder(collector) tasks = {"one": Task(action="one", description="one"), "two": Task(action="two", description="two")} overrides = {"three": Task(action="three", description="three")} default_tasks = mock.Mock(name="default_tasks", return_value=tasks) all_tasks = {} all_tasks.update(tasks) all_tasks.update(overrides) with mock.patch.object(task_finder, "default_tasks", default_tasks): self.assertEqual(task_finder.find_tasks(overrides), all_tasks) self.assertEqual(task_finder.tasks, all_tasks) it "finds tasks attached to images": configuration = { "images": { "blah": { "commands": "FROM ubuntu:14.04" , "tasks": {"one": {}} } , "stuff": { "commands": "FROM ubuntu:14.04" , "tasks": {"two": {"description": "not much"}} } , "other": { "commands": "FROM ubuntu:14.04"
def extra_prepare_after_activation(self, configuration, cli_args): """Called after the configuration.converters are activated""" task_finder = TaskFinder(self) self.configuration["task_runner"] = task_finder.task_runner task_finder.find_tasks({})