def test_ask_rephrase(self, trained_policy, default_domain): events = [ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ActionExecuted(ACTION_DEFAULT_ASK_AFFIRMATION_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered('deny', 1)] next_action = self._get_next_action(trained_policy, events, default_domain) assert next_action == ACTION_DEFAULT_ASK_REPHRASE_NAME
def test_unknown_instead_affirmation(self, trained_policy, default_domain): events = [ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ActionExecuted(ACTION_DEFAULT_ASK_AFFIRMATION_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ] next_action = self._get_next_action(trained_policy, events, default_domain) assert next_action == ACTION_DEFAULT_FALLBACK_NAME
def test_ask_affirmation(self, trained_policy, default_domain): events = [ActionExecuted(ACTION_LISTEN_NAME), user_uttered("Hi", 0.2)] next_action = self._get_next_action(trained_policy, events, default_domain) assert next_action == ACTION_DEFAULT_ASK_AFFIRMATION_NAME
def test_affirm_rephrased_intent(self, trained_policy, default_domain): events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ActionExecuted(ACTION_DEFAULT_ASK_AFFIRMATION_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered(USER_INTENT_DENY, 1), ActionExecuted(ACTION_DEFAULT_ASK_REPHRASE_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ] next_action = self._get_next_action(trained_policy, events, default_domain) assert next_action == ACTION_DEFAULT_ASK_AFFIRMATION_NAME
def test_successful_rephrasing(self, trained_policy, default_dispatcher_collecting, default_domain): events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ActionExecuted(ACTION_DEFAULT_ASK_AFFIRMATION_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered('deny', 1), ActionExecuted(ACTION_DEFAULT_ASK_REPHRASE_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered("bye", 1), ] tracker = self._get_tracker_after_reverts( events, default_dispatcher_collecting, default_domain) assert 'bye' == tracker.latest_message.parse_data['intent']['name'] assert tracker.export_stories() == "## sender\n* bye\n"
def test_last_executed_has_not_name(): events = [ ActionExecuted('one'), user_uttered('two', 1), ActionExecuted(ACTION_LISTEN_NAME) ] tracker = get_tracker(events) assert tracker.last_executed_action_has('another') is False
def test_affirmation(self, default_dispatcher_collecting, default_domain): events = [ActionExecuted(ACTION_LISTEN_NAME), user_uttered('greet', 1), ActionExecuted('utter_hello'), ActionExecuted(ACTION_LISTEN_NAME), user_uttered('greet', 0.2), ActionExecuted(ACTION_DEFAULT_ASK_AFFIRMATION_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered('greet', 1)] tracker = self._get_tracker_after_reverts(events, default_dispatcher_collecting, default_domain) assert 'greet' == tracker.latest_message.parse_data['intent']['name'] assert tracker.export_stories() == ("## sender\n" "* greet\n" " - utter_hello\n" "* greet\n")
def test_get_last_event_for_with_skip(): events = [ ActionExecuted('one'), user_uttered('two', 1), ActionExecuted('three') ] tracker = get_tracker(events) assert (tracker.get_last_event_for(ActionExecuted, skip=1).action_name == 'one')
def test_get_last_event_for_with_exclude(): events = [ ActionExecuted('one'), user_uttered('two', 1), ActionExecuted('three') ] tracker = get_tracker(events) assert (tracker.get_last_event_for( ActionExecuted, action_names_to_exclude=['three']).action_name == 'one')
def test_rephrasing_instead_affirmation(self, trained_policy, default_dispatcher_collecting, default_domain): events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 1), ActionExecuted("utter_hello"), ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ActionExecuted(ACTION_DEFAULT_ASK_AFFIRMATION_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered("bye", 1), ] tracker = self._get_tracker_after_reverts( events, default_dispatcher_collecting, default_domain) assert 'bye' == tracker.latest_message.parse_data['intent']['name'] assert tracker.export_stories() == ("## sender\n" "* greet\n" " - utter_hello\n" "* bye\n")
def test_get_last_event_with_reverted(): events = [ActionExecuted('one'), ActionReverted(), user_uttered('two', 1)] tracker = get_tracker(events) assert tracker.get_last_event_for(ActionExecuted) is None
def test_get_last_event_for(): events = [ActionExecuted('one'), user_uttered('two', 1)] tracker = get_tracker(events) assert tracker.get_last_event_for(ActionExecuted).action_name == 'one'