예제 #1
0
  def test_list_goals_graph(self):
    Phase.clear()

    Goal(name=self._LIST_GOALS_NAME, action=ListGoals)\
      .install().with_description(self._LIST_GOALS_DESC)
    Goal(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\
      .install().with_description(self._LLAMA_DESC)
    Goal(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'],
    )
예제 #2
0
  def test_list_goals(self):
    Phase.clear()
    self.assert_console_output(self._INSTALLED_HEADER)

    Goal(name=self._LIST_GOALS_NAME, action=ListGoals)\
      .install().with_description(self._LIST_GOALS_DESC)
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
    )

    Goal(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\
      .install().with_description(self._LLAMA_DESC)
    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),
    )

    Goal(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),
    )
예제 #3
0
  def installed_goal(cls, name, action=None, group=None, dependencies=None, phase=None):
    """Creates and installs a goal with the given name.

    :param string name: The goal name.
    :param action: The goal's action.
    :param group: The goal's group if it belongs to one.
    :param list dependencies: The list of phase names the goal depends on, if any.
    :param string phase: The name of the phase to install the goal in if different from the goal
      name.
    :returns The installed ``Goal`` object.
    """
    goal = Goal(cls._namespace(name),
                action=action or (lambda: None),
                group=group,
                dependencies=map(cls._namespace, dependencies or []))
    goal.install(cls._namespace(phase) if phase is not None else None)
    return goal
예제 #4
0
    def test_from_goal_valid(self):
        def predicate(tgt):
            return tgt == 42

        goal = Goal('fred',
                    action=lambda: None,
                    group=Group('heathers', predicate))
        self.assertEqual(GroupMember('heathers', 'fred', predicate),
                         GroupMember.from_goal(goal))
예제 #5
0
    def installed_goal(cls,
                       name,
                       action=None,
                       group=None,
                       dependencies=None,
                       phase=None):
        """Creates and installs a goal with the given name.

    :param string name: The goal name.
    :param action: The goal's action.
    :param group: The goal's group if it belongs to one.
    :param list dependencies: The list of phase names the goal depends on, if any.
    :param string phase: The name of the phase to install the goal in if different from the goal
      name.
    :returns The installed ``Goal`` object.
    """
        goal = Goal(cls._namespace(name),
                    action=action or (lambda: None),
                    group=group,
                    dependencies=map(cls._namespace, dependencies or []))
        goal.install(cls._namespace(phase) if phase is not None else None)
        return goal
예제 #6
0
 def test_from_goal_invalid(self):
     with pytest.raises(ValueError):
         GroupMember.from_goal(Goal('fred', action=lambda: None))