def test_advice_builder_error_handling(self): builder = AdviceBuilder() builder.add_error_handler(Target.raise_exception, handle_exception) builder.apply() target = Target() target.raise_exception() self.assertEqual( target.exceptions_handled, 1) # No error should be raised, we just increment when we handle.
def test_advice_builder_multiple_error_handlers(self): builder = AdviceBuilder() builder.add_error_handler(Target.raise_exception, handle_exception) builder.add_error_handler(Target.raise_exception, handle_exception) builder.apply() target = Target() target.raise_exception() self.assertEqual( target.exceptions_handled, 2) # We increment twice if we run the exception handler twice.
def test_model_fuzzing(self): def example_fuzzer(steps, context): steps[0].targets = [] return steps set_fuzzer('a_submitted', example_fuzzer) exceptions_raised = [] def handleExpectedErr(attribute, context, exception): exceptions_raised.append(exception) catch_expected_err = AdviceBuilder() catch_expected_err.add_error_handler( CustomerServiceWorkflow.A_submitted, handleExpectedErr) catch_expected_err.apply() self.company.recieve_message('start') self.clock.tick(2) self.assertTrue(len(exceptions_raised) is not 0)