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


Python rules.NodeBuilder类代码示例

本文整理汇总了Python中pants.engine.rules.NodeBuilder的典型用法代码示例。如果您正苦于以下问题:Python NodeBuilder类的具体用法?Python NodeBuilder怎么用?Python NodeBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_creation_fails_with_bad_declaration_type

 def test_creation_fails_with_bad_declaration_type(self):
     with self.assertRaises(TypeError) as cm:
         NodeBuilder.create([A()])
     self.assertEquals(
         "Unexpected rule type: <class 'pants_test.engine.test_rules.A'>."
         " Rules either extend Rule, or are 3 elem tuples.",
         str(cm.exception),
     )
开发者ID:UnrememberMe,项目名称:pants,代码行数:8,代码来源:test_rules.py

示例2: test_ruleset_with_with_selector_only_provided_as_root_subject

    def test_ruleset_with_with_selector_only_provided_as_root_subject(self):

        validator = RulesetValidator(
            NodeBuilder.create([(A, (Select(B),), noop)]), goal_to_product=dict(), root_subject_types=(B,)
        )

        validator.validate()
开发者ID:UnrememberMe,项目名称:pants,代码行数:7,代码来源:test_rules.py

示例3: test_ruleset_with_selector_only_provided_as_root_subject

  def test_ruleset_with_selector_only_provided_as_root_subject(self):
    rules = [(A, (Select(B),), noop)]
    validator = RulesetValidator(NodeBuilder.create(rules, tuple()),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (B,)})

    validator.validate()
开发者ID:ericzundel,项目名称:pants,代码行数:7,代码来源:test_rules.py

示例4: test_select_dependencies_recurse_with_different_type

  def test_select_dependencies_recurse_with_different_type(self):
    rules = [
      (Exactly(A), (SelectDependencies(B, SubA, field_types=(C, D,)),), noop),
      (B, (Select(A),), noop),
      (C, (Select(SubA),), noop),
      (SubA, tuple(), noop)
    ]

    graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
      root_subject_fns=_suba_root_subject_fns)
    subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)

    self.assert_equal_with_printing(dedent("""
                                      {
                                        root_subject_types: (SubA,)
                                        root_rules: (Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(C, D,)),), noop) of SubA
                                        (B, (Select(A),), noop) of C => ((Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(C, D,)),), noop) of C,)
                                        (B, (Select(A),), noop) of D => ((Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(C, D,)),), noop) of D,)
                                        (Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(C, D,)),), noop) of C => ((SubA, (), noop) of C, (B, (Select(A),), noop) of C, (B, (Select(A),), noop) of D,)
                                        (Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(C, D,)),), noop) of D => ((SubA, (), noop) of D, (B, (Select(A),), noop) of C, (B, (Select(A),), noop) of D,)
                                        (Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(C, D,)),), noop) of SubA => (SubjectIsProduct(SubA), (B, (Select(A),), noop) of C, (B, (Select(A),), noop) of D,)
                                        (SubA, (), noop) of C => (,)
                                        (SubA, (), noop) of D => (,)
                                      }""").strip(),
                                    subgraph)
开发者ID:ericzundel,项目名称:pants,代码行数:25,代码来源:test_rules.py

示例5: test_full_graph_for_planner_example

  def test_full_graph_for_planner_example(self):
    symbol_table_cls = TargetTable
    address_mapper = AddressMapper(symbol_table_cls, JsonParser, '*.BUILD.json')
    tasks = create_graph_tasks(address_mapper, symbol_table_cls) + create_fs_tasks()
    intrinsics = create_fs_intrinsics('Let us pretend that this is a ProjectTree!')

    rule_index = NodeBuilder.create(tasks, intrinsics)
    graphmaker = GraphMaker(rule_index,
      root_subject_fns={k: lambda p: Select(p) for k in (Address, # TODO, use the actual fns.
                          PathGlobs,
                          SingleAddress,
                          SiblingAddresses,
                          DescendantAddresses,
                          AscendantAddresses
      )})
    fullgraph = graphmaker.full_graph()
    print('---diagnostic------')
    print(fullgraph.error_message())
    print('/---diagnostic------')
    print(fullgraph)


    # Assert that all of the rules specified the various task fns are present
    declared_rules = rule_index.all_rules()
    rules_remaining_in_graph_strs = set(str(r.rule) for r in fullgraph.rule_dependencies.keys())

    declared_rule_strings = set(str(r) for r in declared_rules)
    self.assertEquals(declared_rule_strings,
      rules_remaining_in_graph_strs
    )
开发者ID:ericzundel,项目名称:pants,代码行数:30,代码来源:test_rules.py

示例6: test_ruleset_with_explicit_type_constraint

  def test_ruleset_with_explicit_type_constraint(self):
    rules = [
      (Exactly(A), (Select(B),), noop),
      (B, (Select(A),), noop)
    ]
    validator = RulesetValidator(NodeBuilder.create(rules, tuple()),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (SubA,)})

    validator.validate()
开发者ID:ericzundel,项目名称:pants,代码行数:10,代码来源:test_rules.py

示例7: test_fails_if_root_subject_types_empty

 def test_fails_if_root_subject_types_empty(self):
   rules = [
     (A, (Select(B),), noop),
   ]
   with self.assertRaises(ValueError) as cm:
     RulesetValidator(NodeBuilder.create(rules, tuple()),
     goal_to_product={},
     root_subject_fns={})
   self.assertEquals(dedent("""
                               root_subject_fns must not be empty
                            """).strip(), str(cm.exception))
开发者ID:ericzundel,项目名称:pants,代码行数:11,代码来源:test_rules.py

示例8: test_ruleset_with_goal_not_produced

    def test_ruleset_with_goal_not_produced(self):
        rules = [(B, (Select(SubA),), noop)]

        validator = RulesetValidator(
            NodeBuilder.create(rules), goal_to_product={"goal-name": AGoal}, root_subject_types=tuple()
        )
        with self.assertRaises(ValueError) as cm:
            validator.validate()

        self.assertEquals(
            "no task for product used by goal \"goal-name\": <class 'pants_test.engine.test_rules.AGoal'>",
            str(cm.exception),
        )
开发者ID:UnrememberMe,项目名称:pants,代码行数:13,代码来源:test_rules.py

示例9: test_ruleset_with_missing_product_type

  def test_ruleset_with_missing_product_type(self):
    rules = [(A, (Select(B),), noop)]
    validator = RulesetValidator(NodeBuilder.create(rules, tuple()),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (SubA,)})
    with self.assertRaises(ValueError) as cm:
      validator.validate()

    self.assert_equal_with_printing(dedent("""
                     Rules with errors: 1
                       (A, (Select(B),), noop):
                         no matches for Select(B) with subject types: SubA
                     """).strip(),
                                    str(cm.exception))
开发者ID:ericzundel,项目名称:pants,代码行数:14,代码来源:test_rules.py

示例10: test_ruleset_with_goal_not_produced

  def test_ruleset_with_goal_not_produced(self):
    # The graph is complete, but the goal 'goal-name' requests A,
    # which is not produced by any rule.
    rules = [
      (B, (Select(SubA),), noop)
    ]

    validator = RulesetValidator(NodeBuilder.create(rules, tuple()),
      goal_to_product={'goal-name': AGoal},
      root_subject_fns={k: lambda p: Select(p) for k in (SubA,)})
    with self.assertRaises(ValueError) as cm:
      validator.validate()

    self.assert_equal_with_printing("no task for product used by goal \"goal-name\": AGoal",
                                    str(cm.exception))
开发者ID:ericzundel,项目名称:pants,代码行数:15,代码来源:test_rules.py

示例11: test_single_rule_depending_on_subject_selection

  def test_single_rule_depending_on_subject_selection(self):
    rules = [
      (Exactly(A), (Select(SubA),), noop)
    ]

    graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
      root_subject_fns=_suba_root_subject_fns)
    subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)

    self.assert_equal_with_printing(dedent("""
                               {
                                 root_subject_types: (SubA,)
                                 root_rules: (Exactly(A), (Select(SubA),), noop) of SubA
                                 (Exactly(A), (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
                               }""").strip(), subgraph)
开发者ID:ericzundel,项目名称:pants,代码行数:15,代码来源:test_rules.py

示例12: test_smallest_full_test

  def test_smallest_full_test(self):
    rules = [
      (Exactly(A), (Select(SubA),), noop)
    ]

    graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
      root_subject_fns={k: lambda p: Select(p) for k in (SubA,)})
    fullgraph = graphmaker.full_graph()

    self.assert_equal_with_printing(dedent("""
                               {
                                 root_subject_types: (SubA,)
                                 root_rules: (Exactly(A), (Select(SubA),), noop) of SubA
                                 (Exactly(A), (Select(SubA),), noop) of SubA => (SubjectIsProduct(SubA),)
                               }""").strip(), fullgraph)
开发者ID:ericzundel,项目名称:pants,代码行数:15,代码来源:test_rules.py

示例13: test_select_literal

  def test_select_literal(self):
    literally_a = A()
    rules = [
      (B, (SelectLiteral(literally_a, A),), noop)
    ]

    graphmaker = GraphMaker(NodeBuilder.create(rules, tuple()),
      root_subject_fns=_suba_root_subject_fns)
    subgraph = graphmaker.generate_subgraph(SubA(), requested_product=B)

    self.assert_equal_with_printing(dedent("""
                               {
                                 root_subject_types: (SubA,)
                                 root_rules: (B, (SelectLiteral(A(), A),), noop) of SubA
                                 (B, (SelectLiteral(A(), A),), noop) of SubA => (Literal(A(), A),)
                               }""").strip(), subgraph)
开发者ID:ericzundel,项目名称:pants,代码行数:16,代码来源:test_rules.py

示例14: test_ruleset_with_missing_product_type

    def test_ruleset_with_missing_product_type(self):
        rules = [(A, (Select(B),), noop)]
        validator = RulesetValidator(NodeBuilder.create(rules), goal_to_product=dict(), root_subject_types=tuple())
        with self.assertRaises(ValueError) as cm:
            validator.validate()

        self.assertEquals(
            dedent(
                """
                                Found 1 rules with errors:
                                  (A, (Select(B),), noop)
                                    There is no producer of Select(B)
                             """
            ).strip(),
            str(cm.exception),
        )
开发者ID:UnrememberMe,项目名称:pants,代码行数:16,代码来源:test_rules.py

示例15: test_select_dependencies_non_matching_subselector_because_of_intrinsic

  def test_select_dependencies_non_matching_subselector_because_of_intrinsic(self):
    rules = [
      (Exactly(A), (SelectDependencies(B, SubA, field_types=(D,)),), noop),
    ]
    intrinsics = [
      (C, B, noop),
    ]
    graphmaker = GraphMaker(NodeBuilder.create(rules, intrinsics),
                            root_subject_fns=_suba_root_subject_fns)
    subgraph = graphmaker.generate_subgraph(SubA(), requested_product=A)

    self.assert_equal_with_printing('{empty graph}', subgraph)
    self.assert_equal_with_printing(dedent("""
                         Rules with errors: 1
                           (Exactly(A), (SelectDependencies(B, SubA, u'dependencies', field_types=(D,)),), noop):
                             no matches for Select(B) when resolving SelectDependencies(B, SubA, u'dependencies', field_types=(D,)) with subject types: D""").strip(),
                                    subgraph.error_message())
开发者ID:ericzundel,项目名称:pants,代码行数:17,代码来源:test_rules.py


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