Пример #1
0
  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()
Пример #2
0
    def test_ruleset_with_explicit_type_constraint(self):
        rules = [(Exactly(A), (Select(B), ), noop), (B, (Select(A), ), noop)]
        validator = RulesetValidator(NodeBuilder.create(rules),
                                     goal_to_product=dict(),
                                     root_subject_types=tuple())

        validator.validate()
Пример #3
0
    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()
Пример #4
0
  def test_ruleset_with_selector_only_provided_as_root_subject(self):
    rules = [(A, (Select(B),), noop)]
    validator = RulesetValidator(RuleIndex.create(rules, tuple()),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (B,)})

    validator.validate()
Пример #5
0
    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()
Пример #6
0
    def test_ruleset_with_explicit_type_constraint(self):
        rules = [(Exactly(A), (Select(B), ), noop), (B, (Select(A), ), noop)]
        validator = RulesetValidator(
            RuleIndex.create(rules, tuple()),
            goal_to_product={},
            root_subject_fns={k: lambda p: Select(p)
                              for k in (SubA, )})

        validator.validate()
Пример #7
0
  def test_ruleset_with_explicit_type_constraint(self):
    rules = [
      (Exactly(A), (Select(B),), noop),
      (B, (Select(A),), noop)
    ]
    validator = RulesetValidator(RuleIndex.create(rules, tuple()),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (SubA,)})

    validator.validate()
Пример #8
0
    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))
Пример #9
0
    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),
        )
Пример #10
0
  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))
Пример #11
0
  def test_ruleset_with_missing_product_type(self):
    rules = [(A, (Select(B),), noop)]
    validator = RulesetValidator(RuleIndex.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))
Пример #12
0
    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))
Пример #13
0
  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))
Пример #14
0
  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(RuleIndex.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))
Пример #15
0
    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),
        )
Пример #16
0
  def test_initial_select_projection_failure(self):
    rules = [
      (Exactly(A), (SelectProjection(B, D, ('some',), C),), noop),
    ]
    validator = RulesetValidator(RuleIndex.create(rules, tuple()),
      goal_to_product={},
      root_subject_fns=_suba_root_subject_fns)

    with self.assertRaises(ValueError) as cm:
      validator.validate()

    self.assert_equal_with_printing(dedent("""
                      Rules with errors: 1
                        (Exactly(A), (SelectProjection(B, D, (u'some',), C),), noop):
                          no matches for Select(C) when resolving SelectProjection(B, D, (u'some',), C) with subject types: SubA
                      """).strip(),
                                    str(cm.exception))
Пример #17
0
    def test_secondary_select_projection_failure(self):
        rules = [(Exactly(A), (SelectProjection(B, D, ('some', ), C), ), noop),
                 (C, tuple(), noop)]

        validator = RulesetValidator(RuleIndex.create(rules, tuple()),
                                     goal_to_product={},
                                     root_subject_fns=_suba_root_subject_fns)

        with self.assertRaises(ValueError) as cm:
            validator.validate()

        self.assert_equal_with_printing(
            dedent("""
                      Rules with errors: 1
                        (Exactly(A), (SelectProjection(B, D, (u'some',), C),), noop):
                          no matches for Select(B) when resolving SelectProjection(B, D, (u'some',), C) with subject types: D
                      """).strip(), str(cm.exception))
Пример #18
0
    def test_ruleset_with_superclass_of_selected_type_produced_fails(self):
        rules = [(A, (Select(B), ), noop), (B, (Select(SubA), ), noop)]
        validator = RulesetValidator(
            RuleIndex.create(rules, tuple()),
            goal_to_product={},
            root_subject_fns={k: lambda p: Select(p)
                              for k in (C, )})

        with self.assertRaises(ValueError) as cm:
            validator.validate()
        self.assert_equal_with_printing(
            dedent("""
                                      Rules with errors: 2
                                        (A, (Select(B),), noop):
                                          depends on unfulfillable (B, (Select(SubA),), noop) of C with subject types: C
                                        (B, (Select(SubA),), noop):
                                          no matches for Select(SubA) with subject types: C
                                      """).strip(), str(cm.exception))
Пример #19
0
  def test_ruleset_with_superclass_of_selected_type_produced_fails(self):
    rules = [
      (A, (Select(B),), noop),
      (B, (Select(SubA),), noop)
    ]
    validator = RulesetValidator(RuleIndex.create(rules, tuple()),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (C,)})

    with self.assertRaises(ValueError) as cm:
      validator.validate()
    self.assert_equal_with_printing(dedent("""
                                      Rules with errors: 2
                                        (A, (Select(B),), noop):
                                          depends on unfulfillable (B, (Select(SubA),), noop) of C with subject types: C
                                        (B, (Select(SubA),), noop):
                                          no matches for Select(SubA) with subject types: C
                                      """).strip(),
                                    str(cm.exception))
Пример #20
0
  def test_ruleset_unreachable_due_to_product_of_select_dependencies(self):
    rules = [
      (A, (SelectDependencies(B, SubA, field_types=(D,)),), noop),
    ]
    intrinsics = [
      (B, C, noop),
    ]
    validator = RulesetValidator(RuleIndex.create(rules, intrinsics),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (A,)})

    with self.assertRaises(ValueError) as cm:
      validator.validate()

    self.assert_equal_with_printing(dedent("""
                             Rules with errors: 1
                               (A, (SelectDependencies(B, SubA, field_types=(D,)),), noop):
                                 Unreachable with subject types: Any
                             """).strip(),
                                    str(cm.exception))
Пример #21
0
  def test_ruleset_with_failure_due_to_incompatible_subject_for_intrinsic(self):
    rules = [
      (D, (Select(C),), noop)
    ]
    intrinsics = [
      (B, C, noop),
    ]
    validator = RulesetValidator(NodeBuilder.create(rules, intrinsics),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (A,)})

    with self.assertRaises(ValueError) as cm:
      validator.validate()

    self.assert_equal_with_printing(dedent("""
                                      Rules with errors: 1
                                        (D, (Select(C),), noop):
                                          no matches for Select(C) with subject types: A
                                      """).strip(),
                                    str(cm.exception))
Пример #22
0
  def test_ruleset_unreachable_due_to_product_of_select_dependencies(self):
    rules = [
      (A, (SelectDependencies(B, SubA, field_types=(D,)),), noop),
    ]
    intrinsics = [
      (B, C, noop),
    ]
    validator = RulesetValidator(NodeBuilder.create(rules, intrinsics),
      goal_to_product={},
      root_subject_fns={k: lambda p: Select(p) for k in (A,)})

    with self.assertRaises(ValueError) as cm:
      validator.validate()

    self.assert_equal_with_printing(dedent("""
                             Rules with errors: 1
                               (A, (SelectDependencies(B, SubA, u'dependencies', field_types=(D,)),), noop):
                                 Unreachable with subject types: Any
                             """).strip(),
                                    str(cm.exception))
Пример #23
0
  def test_not_fulfillable_duplicated_dependency(self):
    # If a rule depends on another rule+subject in two ways, and one of them is unfulfillable
    # Only the unfulfillable one should be in the errors.
    rules = [
      (B, (Select(D),), noop),
      (D, (Select(A), SelectDependencies(A, SubA, field_types=(C,))), noop),
      (A, (Select(SubA),), noop)
    ]
    validator = RulesetValidator(RuleIndex.create(rules, tuple()),
      goal_to_product={},
      root_subject_fns=_suba_root_subject_fns)

    with self.assertRaises(ValueError) as cm:
      validator.validate()

    self.assert_equal_with_printing(dedent("""
                      Rules with errors: 2
                        (B, (Select(D),), noop):
                          depends on unfulfillable (D, (Select(A), SelectDependencies(A, SubA, field_types=(C,))), noop) of SubA with subject types: SubA
                        (D, (Select(A), SelectDependencies(A, SubA, field_types=(C,))), noop):
                          depends on unfulfillable (A, (Select(SubA),), noop) of C with subject types: SubA""").strip(),
        str(cm.exception))
Пример #24
0
    def test_not_fulfillable_duplicated_dependency(self):
        # If a rule depends on another rule+subject in two ways, and one of them is unfulfillable
        # Only the unfulfillable one should be in the errors.
        rules = [(B, (Select(D), ), noop),
                 (D, (Select(A), SelectDependencies(A, SubA,
                                                    field_types=(C, ))), noop),
                 (A, (Select(SubA), ), noop)]
        validator = RulesetValidator(RuleIndex.create(rules, tuple()),
                                     goal_to_product={},
                                     root_subject_fns=_suba_root_subject_fns)

        with self.assertRaises(ValueError) as cm:
            validator.validate()

        self.assert_equal_with_printing(
            dedent("""
                      Rules with errors: 2
                        (B, (Select(D),), noop):
                          depends on unfulfillable (D, (Select(A), SelectDependencies(A, SubA, field_types=(C,))), noop) of SubA with subject types: SubA
                        (D, (Select(A), SelectDependencies(A, SubA, field_types=(C,))), noop):
                          depends on unfulfillable (A, (Select(SubA),), noop) of C with subject types: SubA"""
                   ).strip(), str(cm.exception))
Пример #25
0
    def test_ruleset_with_explicit_type_constraint(self):
        rules = [(Exactly(A), (Select(B),), noop), (B, (Select(A),), noop)]
        validator = RulesetValidator(NodeBuilder.create(rules), goal_to_product=dict(), root_subject_types=tuple())

        validator.validate()