def test_list_goals(self): Goal.clear() self.assert_console_output(self._INSTALLED_HEADER) TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), ) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), )
def test_list_goals_graph(self): Goal.clear() TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( 'digraph G {\n rankdir=LR;\n graph [compound=true];', ' subgraph cluster_goals {\n node [style=filled];\n color = blue;\n label = "goals";', ' goals_goals [label="goals"];', ' }', ' subgraph cluster_llama {\n node [style=filled];\n color = blue;\n label = "llama";', ' llama_llama [label="llama"];', ' }', ' subgraph cluster_alpaca {\n node [style=filled];\n color = blue;\n label = "alpaca";', ' alpaca_alpaca [label="alpaca"];', ' }', ' alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];', '}', args=['--test-graph'], )
def test_gen_tasks_goals_reference_data(self): # can we run our reflection-y goal code without crashing? would be nice Goal.by_name('jack').install(TaskRegistrar('jill', lambda: 42)) gref_data = builddictionary.gen_tasks_goals_reference_data() self.assertTrue( len(gref_data) > 0, 'Tried to generate data for goals reference, got emptiness')
def test_register_duplicate_task_name_is_not_error_when_replacing(self): Goal.clear() class NoopTask(Task): def execute(self): pass class OtherNoopTask(Task): def execute(self): pass goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) task_name = 'foo' goal.install(TaskRegistrar(task_name, NoopTask)) goal.install(TaskRegistrar(task_name, OtherNoopTask), replace=True) self.assertTrue(issubclass(goal.task_type_by_name(task_name), OtherNoopTask))
def test_list_goals_all(self): Goal.clear() TaskRegistrar(name=self._LIST_GOALS_NAME, action=ListGoals)\ .install().with_description(self._LIST_GOALS_DESC) TaskRegistrar(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\ .install().with_description(self._LLAMA_DESC) TaskRegistrar(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\ .install() self.assert_console_output( self._INSTALLED_HEADER, ' %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC), '', self._UNDOCUMENTED_HEADER, ' %s' % self._ALPACA_NAME, args=['--test-all'], )
def test_register_duplicate_task_name_is_error(self): Goal.clear() class NoopTask(Task): def execute(self): pass class OtherNoopTask(Task): def execute(self): pass goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) task_name = 'foo' goal.install(TaskRegistrar(task_name, NoopTask)) with self.assertRaises(GoalError) as ctx: goal.install(TaskRegistrar(task_name, OtherNoopTask)) self.assertIn('foo', ctx.exception.message) self.assertIn(self._LIST_GOALS_NAME, ctx.exception.message)
def install_task(cls, name, action=None, dependencies=None, goal=None): """Creates and installs a task with the given name. :param string name: The task name. :param action: The task's action. :param list dependencies: The list of goal names the task depends on, if any. :param string goal: The name of the goal to install the task in, if different from the task name. :returns The ``Goal`` object with task installed. """ return TaskRegistrar(name, action=action or (lambda: None), dependencies=dependencies or []).install(goal if goal is not None else None)
class ListGoalsTest(ConsoleTaskTestBase): class NoopTask(Task): def execute(self): pass _INSTALLED_HEADER = 'Installed goals:' _UNDOCUMENTED_HEADER = 'Undocumented goals:' _LIST_GOALS_NAME = 'goals' _LIST_GOALS_DESC = 'List available goals.' _LIST_GOALS_TASK = TaskRegistrar('list-goals', NoopTask) _LLAMA_NAME = 'llama' _LLAMA_DESC = 'With such handsome fiber, no wonder everyone loves Llamas.' _LLAMA_TASK = TaskRegistrar('winamp', NoopTask) _ALPACA_NAME = 'alpaca' _ALPACA_TASK = TaskRegistrar('alpaca', NoopTask) @classmethod def task_type(cls): return ListGoals def test_list_goals(self): Goal.clear() self.assert_console_output(self._INSTALLED_HEADER) # Goals with no tasks should always be elided. list_goals_goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) self.assert_console_output(self._INSTALLED_HEADER) list_goals_goal.install(self._LIST_GOALS_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC).install(self._LLAMA_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), ) Goal.register(self._ALPACA_NAME, description='').install(self._ALPACA_TASK) self.assert_console_output( self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), ' {0}: {1}'.format(self._LLAMA_NAME, self._LLAMA_DESC), ) def test_list_goals_all(self): Goal.clear() Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC).install(self._LIST_GOALS_TASK) # Goals with no tasks should always be elided. Goal.register(self._LLAMA_NAME, self._LLAMA_DESC) Goal.register(self._ALPACA_NAME, description='').install(self._ALPACA_TASK) self.assert_console_output(self._INSTALLED_HEADER, ' {0}: {1}'.format(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC), '', self._UNDOCUMENTED_HEADER, ' {0}'.format(self._ALPACA_NAME), options={'all': True}) def test_register_duplicate_task_name_is_error(self): Goal.clear() class NoopTask(Task): def execute(self): pass class OtherNoopTask(Task): def execute(self): pass goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) task_name = 'foo' goal.install(TaskRegistrar(task_name, NoopTask)) with self.assertRaises(GoalError) as ctx: goal.install(TaskRegistrar(task_name, OtherNoopTask)) self.assertIn('foo', ctx.exception.message) self.assertIn(self._LIST_GOALS_NAME, ctx.exception.message) def test_register_duplicate_task_name_is_not_error_when_replacing(self): Goal.clear() class NoopTask(Task): def execute(self): pass class OtherNoopTask(Task): def execute(self): pass goal = Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC) task_name = 'foo' goal.install(TaskRegistrar(task_name, NoopTask)) goal.install(TaskRegistrar(task_name, OtherNoopTask), replace=True) self.assertTrue( issubclass(goal.task_type_by_name(task_name), OtherNoopTask)) # TODO(John Sirois): Re-enable when fixing up ListGoals `--graph` in # https://github.com/pantsbuild/pants/issues/918 @expectedFailure def test_list_goals_graph(self): Goal.clear() Goal.register(self._LIST_GOALS_NAME, self._LIST_GOALS_DESC).install(self._LIST_GOALS_TASK) Goal.register(self._LLAMA_NAME, self._LLAMA_DESC).install(self._LLAMA_TASK) Goal.register(self._ALPACA_NAME, description='') self.assert_console_output( 'digraph G {\n rankdir=LR;\n graph [compound=true];', ' subgraph cluster_goals {\n node [style=filled];\n color = blue;\n label = "goals";', ' goals_goals [label="goals"];', ' }', ' subgraph cluster_llama {\n node [style=filled];\n color = blue;\n label = "llama";', ' llama_llama [label="llama"];', ' }', ' subgraph cluster_alpaca {\n node [style=filled];\n color = blue;\n label = "alpaca";', ' alpaca_alpaca [label="alpaca"];', ' }', ' alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];', '}', options={'graph': True})
def reg_goal(): Goal.by_name('plugindemo').install(TaskRegistrar('foo', DummyTask))
def register_goals(): Goal.by_name('jack').install(TaskRegistrar('jill', DummyTask))
def register_goals(): Goal.by_name('jack').install(TaskRegistrar('jill', lambda: 42))
def reg_goal(): Goal.by_name('plugindemo').install(TaskRegistrar('foo', lambda: 1))
def register_goals(): TaskRegistrar(name='stack-build', action=StackBuild).install('compile')
def reg_goal(): Goal.by_name("plugindemo").install(TaskRegistrar("foo", DummyTask))
def register_goals(): Goal.by_name("jack").install(TaskRegistrar("jill", DummyTask))