def test_handler_stop_exception(self): """Test the handler exception.""" with pytest.raises(_StopRuntime): with mock.patch.object(self.handler, "handle", side_effect=_StopRuntime()): self.handler.handle_wrapper("msg")
def exception_handler(self, exception: Exception, function: Callable) -> bool: """ Handle exception raised during agent main loop execution. :param exception: exception raised :param function: a callable exception raised in. :return: bool, propagate exception if True otherwise skip it. """ # docstyle: ignore # noqa: E800 def log_exception(e, fn, is_debug: bool = False): if is_debug: self.logger.debug(f"<{e}> raised during `{fn}`") else: self.logger.exception(f"<{e}> raised during `{fn}`") if self._skills_exception_policy == ExceptionPolicyEnum.propagate: log_exception(exception, function, is_debug=True) return True if self._skills_exception_policy == ExceptionPolicyEnum.stop_and_exit: log_exception(exception, function) raise _StopRuntime( AEAException( f"AEA was terminated cause exception `{exception}` in skills {function}! Please check logs." )) if self._skills_exception_policy == ExceptionPolicyEnum.just_log: log_exception(exception, function) return False raise AEAException( f"Unsupported exception policy: {self._skills_exception_policy}")
def test_act_wrapper_negative_stop_runtime(self): """Test for act_wrapper negative result.""" obj = self.TestCyclicBehaviour(skill_context="skill_context", name="name") obj.act = mock.Mock() with pytest.raises(_StopRuntime): with mock.patch.object(obj, "act", side_effect=_StopRuntime()): assert obj.number_of_executions == 0 obj.act_wrapper() obj.act.assert_called_once() assert obj.number_of_executions == 1
def test_stop_with_stopped_exception(self): """Test runtime stopped by stopruntime exception.""" behaviour = self.agent.resources.get_behaviour(DUMMY_SKILL_PUBLIC_ID, "dummy") with patch.object( behaviour, "act", side_effect=_StopRuntime(reraise=ValueError("expected"))): self.runtime.start() wait_for_condition(lambda: self.runtime.is_running, timeout=20) # started and should be stopped after the first act called wait_for_condition(lambda: self.runtime.is_stopped, timeout=20) with pytest.raises(ValueError, match="expected"): self.runtime.wait_completed(timeout=20, sync=True)
def test_stop_runtime(): """Test thes stop runtime exception.""" test = "test string" e = _StopRuntime(test) assert e.reraise == test