当前位置: 首页>>代码示例>>Python>>正文


Python RoundEngine.attempt方法代码示例

本文整理汇总了Python中pants.engine.round_engine.RoundEngine.attempt方法的典型用法代码示例。如果您正苦于以下问题:Python RoundEngine.attempt方法的具体用法?Python RoundEngine.attempt怎么用?Python RoundEngine.attempt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pants.engine.round_engine.RoundEngine的用法示例。


在下文中一共展示了RoundEngine.attempt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RoundEngineTest

# 需要导入模块: from pants.engine.round_engine import RoundEngine [as 别名]
# 或者: from pants.engine.round_engine.RoundEngine import attempt [as 别名]
class RoundEngineTest(EngineTestBase, TestBase):
  def setUp(self):
    super(RoundEngineTest, self).setUp()

    self.set_options_for_scope('', explain=False)
    for outer in ['goal1', 'goal2', 'goal3', 'goal4', 'goal5']:
      for inner in ['task1', 'task2', 'task3', 'task4', 'task5']:
        self.set_options_for_scope('{}.{}'.format(outer, inner),
                                   level='info', colors=False)

    self.engine = RoundEngine()
    self.actions = []
    self._context = None

  def tearDown(self):
    if self._context is not None:
      self.assertTrue(not self._context or self._context.is_unlocked())
    super(RoundEngineTest, self).tearDown()

  def alternate_target_roots_action(self, tag):
    return 'alternate_target_roots', tag, self._context

  def prepare_action(self, tag):
    return 'prepare', tag, self._context

  def execute_action(self, tag):
    return 'execute', tag, self._context

  def construct_action(self, tag):
    return 'construct', tag, self._context

  def record(self, tag, product_types=None, required_data=None, optional_data=None,
             alternate_target_roots=None):

    class RecordingTask(Task):
      options_scope = tag

      @classmethod
      def product_types(cls):
        return product_types or []

      @classmethod
      def alternate_target_roots(cls, options, address_mapper, build_graph):
        self.actions.append(self.alternate_target_roots_action(tag))
        return alternate_target_roots

      @classmethod
      def prepare(cls, options, round_manager):
        for product in (required_data or ()):
          round_manager.require_data(product)
        for product in (optional_data or ()):
          round_manager.optional_data(product)
        self.actions.append(self.prepare_action(tag))

      def __init__(me, *args, **kwargs):
        super(RecordingTask, me).__init__(*args, **kwargs)
        self.actions.append(self.construct_action(tag))

      def execute(me):
        self.actions.append(self.execute_action(tag))

    return RecordingTask

  def install_task(self, name, product_types=None, goal=None, required_data=None,
                   optional_data=None, alternate_target_roots=None):
    """Install a task to goal and return all installed tasks of the goal.

    This is needed to initialize tasks' context.
    """
    task_type = self.record(name, product_types, required_data, optional_data,
                            alternate_target_roots)
    return super(RoundEngineTest,
                 self).install_task(name=name, action=task_type, goal=goal).task_types()

  def create_context(self, for_task_types=None, target_roots=None):
    self._context = self.context(for_task_types=for_task_types, target_roots=target_roots)
    self.assertTrue(self._context.is_unlocked())

  def assert_actions(self, *expected_execute_ordering):
    expected_pre_execute_actions = set()
    expected_execute_actions = []
    for action in expected_execute_ordering:
      expected_pre_execute_actions.add(self.alternate_target_roots_action(action))
      expected_pre_execute_actions.add(self.prepare_action(action))
      expected_execute_actions.append(self.construct_action(action))
      expected_execute_actions.append(self.execute_action(action))

    expeceted_execute_actions_length = len(expected_execute_ordering) * 2
    self.assertEqual(expected_pre_execute_actions,
                     set(self.actions[:-expeceted_execute_actions_length]))
    self.assertEqual(expected_execute_actions, self.actions[-expeceted_execute_actions_length:])

  def test_lifecycle_ordering(self):
    task1 = self.install_task('task1', goal='goal1', product_types=['1'])
    task2 = self.install_task('task2', goal='goal1', product_types=['2'], required_data=['1'])
    task3 = self.install_task('task3', goal='goal3', product_types=['3'], required_data=['2'])
    task4 = self.install_task('task4', goal='goal4', required_data=['1', '2', '3'])
    self.create_context(for_task_types=task1+task2+task3+task4)
    self.engine.attempt(self._context, self.as_goals('goal4'))
    self.assert_actions('task1', 'task2', 'task3', 'task4')
#.........这里部分代码省略.........
开发者ID:baroquebobcat,项目名称:pants,代码行数:103,代码来源:test_round_engine.py

示例2: RoundEngineTest

# 需要导入模块: from pants.engine.round_engine import RoundEngine [as 别名]
# 或者: from pants.engine.round_engine.RoundEngine import attempt [as 别名]
class RoundEngineTest(EngineTestBase, BaseTest):
  def setUp(self):
    super(RoundEngineTest, self).setUp()

    self.set_new_options_for_scope('', explain=False)
    self._context = self.context()
    self.assertTrue(self._context.is_unlocked())

    self.engine = RoundEngine()
    self.actions = []

  def tearDown(self):
    self.assertTrue(self._context.is_unlocked())
    super(RoundEngineTest, self).tearDown()

  def construct_action(self, tag):
    return 'construct', tag, self._context

  def prepare_action(self, tag):
    return 'prepare', tag, self._context

  def execute_action(self, tag):
    return 'execute', tag, self._context

  def record(self, tag, product_types=None, required_data=None):
    class RecordingTask(Task):
      def __init__(me, *args, **kwargs):
        super(RecordingTask, me).__init__(*args, **kwargs)
        self.actions.append(self.construct_action(tag))

      @classmethod
      def product_types(cls):
        return product_types or []

      def prepare(me, round_manager):
        for requirement in (required_data or ()):
          round_manager.require_data(requirement)
        self.actions.append(self.prepare_action(tag))

      def execute(me):
        self.actions.append(self.execute_action(tag))

    return RecordingTask

  def install_task(self, name, product_types=None, goal=None, required_data=None):
    task = self.record(name, product_types, required_data)
    return super(RoundEngineTest, self).install_task(name=name, action=task, goal=goal)

  def assert_actions(self, *expected_execute_ordering):
    expected_pre_execute_actions = set()
    expected_execute_actions = []
    for action in expected_execute_ordering:
      expected_pre_execute_actions.add(self.construct_action(action))
      expected_pre_execute_actions.add(self.prepare_action(action))
      expected_execute_actions.append(self.execute_action(action))

    self.assertEqual(expected_pre_execute_actions,
                     set(self.actions[:-len(expected_execute_ordering)]))
    self.assertEqual(expected_execute_actions, self.actions[-len(expected_execute_ordering):])

  def test_lifecycle_ordering(self):
    self.install_task('task1', goal='goal1', product_types=['1'])
    self.install_task('task2', goal='goal1', product_types=['2'], required_data=['1'])
    self.install_task('task3', goal='goal3', product_types=['3'], required_data=['2'])
    self.install_task('task4', goal='goal4', required_data=['1', '2', '3'])

    self.engine.attempt(self._context, self.as_goals('goal4'))

    self.assert_actions('task1', 'task2', 'task3', 'task4')

  def test_lifecycle_ordering_install_order_invariant(self):
    # Here we swap the order of goal3 and goal4 task installation from the order in
    # `test_lifecycle_ordering` above.  We can't swap task1 and task2 since they purposefully
    # do have an implicit order dependence with a dep inside the same goal.
    self.install_task('task1', goal='goal1', product_types=['1'])
    self.install_task('task2', goal='goal1', product_types=['2'], required_data=['1'])
    self.install_task('task4', goal='goal4', required_data=['1', '2', '3'])
    self.install_task('task3', goal='goal3', product_types=['3'], required_data=['2'])

    self.engine.attempt(self._context, self.as_goals('goal4'))

    self.assert_actions('task1', 'task2', 'task3', 'task4')

  def test_inter_goal_dep(self):
    self.install_task('task1', goal='goal1', product_types=['1'])
    self.install_task('task2', goal='goal1', required_data=['1'])

    self.engine.attempt(self._context, self.as_goals('goal1'))

    self.assert_actions('task1', 'task2')

  def test_inter_goal_dep_self_cycle(self):
    self.install_task('task1', goal='goal1', product_types=['1'], required_data=['1'])

    with self.assertRaises(self.engine.TaskOrderError):
      self.engine.attempt(self._context, self.as_goals('goal1'))

  def test_inter_goal_dep_downstream(self):
    self.install_task('task1', goal='goal1', required_data=['1'])
    self.install_task('task2', goal='goal1', product_types=['1'])
#.........这里部分代码省略.........
开发者ID:digideskio,项目名称:pants,代码行数:103,代码来源:test_round_engine.py


注:本文中的pants.engine.round_engine.RoundEngine.attempt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。