Esempio n. 1
0
    def test_trace_includes_rule_exception_traceback(self):
        rules = [RootRule(B), TaskRule(A, [Select(B)], nested_raise)]

        scheduler = create_native_scheduler(rules)
        request = scheduler._native.new_execution_request()
        subject = B()
        scheduler.add_root_selection(request, subject, A)
        scheduler.run_and_return_roots(request)

        trace = '\n'.join(scheduler.graph_trace(request))
        # NB removing location info to make trace repeatable
        trace = remove_locations_from_traceback(trace)

        assert_equal_with_printing(
            self,
            dedent('''
                     Computing Select(<pants_test.engine.test_scheduler.B object at 0xEEEEEEEEE>, =A)
                       Computing Task(nested_raise, <pants_test.engine.test_scheduler.B object at 0xEEEEEEEEE>, =A)
                         Throw(An exception for B)
                           Traceback (most recent call last):
                             File LOCATION-INFO, in call
                               val = func(*args)
                             File LOCATION-INFO, in nested_raise
                               fn_raises(x)
                             File LOCATION-INFO, in fn_raises
                               raise Exception('An exception for {}'.format(type(x).__name__))
                           Exception: An exception for B''').lstrip() +
            '\n\n',  # Traces include two empty lines after.
            trace)
Esempio n. 2
0
  def test_trace_includes_rule_exception_traceback(self):
    rules = [
      TaskRule(A, [Select(B)], nested_raise)
    ]

    scheduler = create_native_scheduler({B}, rules)
    subject = B()
    scheduler.add_root_selection(subject, Select(A))
    scheduler.run_and_return_stat()

    trace = '\n'.join(scheduler.graph_trace())
    # NB removing location info to make trace repeatable
    trace = remove_locations_from_traceback(trace)

    assert_equal_with_printing(self, dedent('''
                     Computing Select(<pants_test.engine.test_scheduler.B object at 0xEEEEEEEEE>, =A)
                       Computing Task(<function nested_raise at 0xEEEEEEEEE>, <pants_test.engine.test_scheduler.B object at 0xEEEEEEEEE>, =A)
                         Throw(An exception for B)
                           Traceback (most recent call last):
                             File LOCATION-INFO, in extern_invoke_runnable
                               val = runnable(*args)
                             File LOCATION-INFO, in nested_raise
                               fn_raises(x)
                             File LOCATION-INFO, in fn_raises
                               raise Exception('An exception for {}'.format(type(x).__name__))
                           Exception: An exception for B''').lstrip() + '\n\n', # Traces include two empty lines after.
                               trace)
Esempio n. 3
0
    def test_ruleset_with_missing_product_type(self):
        rules = _suba_root_rules + [TaskRule(A, [Select(B)], noop)]
        scheduler = create_native_scheduler(rules)

        with self.assertRaises(ValueError) as cm:
            scheduler.assert_ruleset_valid()

        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))
Esempio n. 4
0
  def test_ruleset_with_missing_product_type(self):
    rules = _suba_root_rules + [TaskRule(A, [Select(B)], noop)]
    scheduler = create_native_scheduler(rules)

    with self.assertRaises(ValueError) as cm:
      scheduler.assert_ruleset_valid()

    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))
Esempio n. 5
0
 def create_validator(self, goal_to_product, rules):
     return create_native_scheduler(rules)
Esempio n. 6
0
 def create_validator(self, goal_to_product, rules):
   return create_native_scheduler(rules)
Esempio n. 7
0
 def scheduler(self, root_subject_types, rules):
     return SimpleScheduler(
         create_native_scheduler(root_subject_types, rules))