def test_extract_task__success__returns_perform_task_state(self):
     task_return = TaskGroundingReturn()
     task_return.is_success = True
     extract_task_State = dialog_flow.ExtractTaskState(
         self.state_dict, self.container)
     self.container.speak = Mock()
     self.container.task_grounding.get_specific_task_from_task = Mock(
         return_value=task_return)
     extract_task_State.state_dict[
         "last_received_sentence"] = "Dummy sentence"
     return_state = extract_task_State.execute()
     self.assertTrue(isinstance(return_state, dialog_flow.PerformTaskState))
 def test_validate_task__any_error__returns_ask_for_clarification_state(
         self):
     task_grounding_return = TaskGroundingReturn()
     error = TaskGroundingError()
     error.error_code = TaskErrorType.UNKNOWN
     error.error_task_name = "Dummy Task"
     task_grounding_return.error = error
     validate_task_state = dialog_flow.ValidateTaskState(
         self.state_dict, self.container)
     validate_task_state.state_dict[
         'task_grounding_return'] = task_grounding_return
     self.container.speak = Mock()
     return_state = validate_task_state.execute()
     self.assertTrue(
         isinstance(return_state, dialog_flow.AskForClarificationState))
 def test_clarify_objects__no_proper_answer__returns_wait_for_response_state(
         self):
     entities = [(EntityType.LOCATION, "blue"),
                 (EntityType.LOCATION, "cover"),
                 (EntityType.OBJECT, "next"),
                 (EntityType.LOCATION, "black"),
                 (EntityType.OBJECT, "bottom cover"),
                 (EntityType.LOCATION, "above"),
                 (EntityType.OBJECT, "bottom cover")]
     grounding_return = GroundingReturn()
     grounding_return.is_success = True
     base_task = Task(name="Dummy name")
     base_task.task_type = TaskType.PICK
     task_grounding_return = TaskGroundingReturn()
     task_grounding_return.task_info.append(base_task)
     self.container.ner.get_entities = Mock(return_value=entities)
     self.container.grounding.find_object = Mock(
         return_value=grounding_return)
     clarify_objects_state = dialog_flow.ClarifyObjects(
         self.state_dict, self.container)
     clarify_objects_state.state_dict["base_task"] = base_task
     clarify_objects_state.state_dict[
         "task_grounding_return"] = task_grounding_return
     clarify_objects_state.is_first_run = False
     self.container.speak = Mock()
     return_state = clarify_objects_state.execute()
     self.assertTrue(
         isinstance(return_state, dialog_flow.WaitForResponseState))
 def test_clarify_objects__cant_find_no_restart_request_grounding_fail_new_error__returns_clarify_state(
         self):
     entities = [(EntityType.LOCATION, "blue"),
                 (EntityType.LOCATION, "cover"),
                 (EntityType.OBJECT, "next"),
                 (EntityType.LOCATION, "black"),
                 (EntityType.OBJECT, "bottom cover"),
                 (EntityType.LOCATION, "above"),
                 (EntityType.OBJECT, "bottom cover")]
     grounding_return = GroundingReturn()
     grounding_return.is_success = False
     grounding_return.error_code = GroundingErrorType.ALREADY_KNOWN
     self.container.ner.get_entities = Mock(return_value=entities)
     self.container.grounding.find_object = Mock(
         return_value=grounding_return)
     clarify_objects_state = dialog_flow.ClarifyObjects(
         self.state_dict, self.container)
     base_task = Task(name="Dummy name")
     dummy_object = ObjectEntity(name="dummy")
     base_task.objects_to_execute_on.append(dummy_object)
     base_task.task_type = TaskType.PICK
     task_grounding_return = TaskGroundingReturn()
     task_grounding_return.task_info.append(base_task)
     clarify_objects_state.state_dict["base_task"] = base_task
     clarify_objects_state.state_dict[
         "task_grounding_return"] = task_grounding_return
     clarify_objects_state.error = GroundingErrorType.CANT_FIND
     clarify_objects_state.is_first_run = False
     self.container.speak = Mock()
     return_state = clarify_objects_state.execute()
     self.assertTrue(isinstance(return_state, dialog_flow.ClarifyObjects))
 def test_perform_task__succeeds_to_perform_task__returns_perform_task_state(
         self):
     grounding_return = GroundingReturn()
     grounding_return.is_success = True
     grounding_return.object_infos.append("dummy")
     self.container.speak = Mock()
     self.container.robot.move_out_of_view = Mock()
     self.container.camera.get_image = Mock()
     self.container.camera.get_depth = Mock()
     self.container.grounding.find_object = Mock(
         return_value=grounding_return)
     self.container.robot.pick_up = Mock(return_value=True)
     perform_task_state = dialog_flow.PerformTaskState(
         self.state_dict, self.container)
     base_task = Task(name="Dummy name")
     dummy_object = ObjectEntity(name="dummy")
     base_task.objects_to_execute_on.append(dummy_object)
     base_task.task_type = TaskType.PICK
     task_grounding_return = TaskGroundingReturn()
     task_grounding_return.task_info.append(base_task)
     perform_task_state.state_dict["base_task"] = base_task
     perform_task_state.state_dict[
         "task_grounding_return"] = task_grounding_return
     return_state = perform_task_state.execute()
     self.assertTrue(isinstance(return_state, dialog_flow.PerformTaskState))
 def setUp(self):
     self.task_grounding = TaskGrounding(DatabaseHandler("test_grounding.db"))
     self.returned = TaskGroundingReturn()
     self.entities = [
         (EntityType.COLOUR, "blue"),
         (EntityType.OBJECT, "cover"),
         (EntityType.LOCATION, "next"),
         (EntityType.COLOUR, "black"),
         (EntityType.OBJECT, "bottom cover"),
         (EntityType.LOCATION, "above"),
         (EntityType.OBJECT, "bottom cover")
     ]
 def setUp(self):
     self.state_dict = {
         "last_received_sentence": None,
         "last_received_sentence_timestamp": None,
         "websocket_is_connected": False,
         "task_grounding_return": TaskGroundingReturn(),
         "base_task": Task,
         "wait_response_called_from": None,
         "tasks_to_perform": None,
         "carrying_object": False,
         "grounding_error": None,
     }
     self.container = Mock()
 def test_clarify_objects__first_run_cant_find_object__returns_wait_response_state(
         self):
     clarify_objects_state = dialog_flow.ClarifyObjects(
         self.state_dict, self.container)
     clarify_objects_state.error = GroundingErrorType.CANT_FIND
     self.container.speak = Mock()
     base_task = Task(name="Dummy name")
     dummy_object = ObjectEntity(name="dummy")
     base_task.objects_to_execute_on.append(dummy_object)
     base_task.task_type = TaskType.PICK
     task_grounding_return = TaskGroundingReturn()
     task_grounding_return.task_info.append(base_task)
     clarify_objects_state.state_dict["base_task"] = base_task
     clarify_objects_state.state_dict[
         "task_grounding_return"] = task_grounding_return
     return_state = clarify_objects_state.execute()
     self.assertTrue(
         isinstance(return_state, dialog_flow.WaitForResponseState))
 def test_perform_task__grounding_fails__returns_clarify_objects_state(
         self):
     grounding_return = GroundingReturn()
     grounding_return.is_success = False
     self.container.speak = Mock()
     self.container.robot.move_out_of_view = Mock()
     self.container.camera.get_image = Mock()
     self.container.camera.get_depth = Mock()
     self.container.grounding.find_object = Mock(
         return_value=grounding_return)
     perform_task_state = dialog_flow.PerformTaskState(
         self.state_dict, self.container)
     base_task = Task(name="Dummy name")
     base_task.objects_to_execute_on.append("dummy")
     task_grounding_return = TaskGroundingReturn()
     task_grounding_return.task_info.append(base_task)
     perform_task_state.state_dict["base_task"] = base_task
     perform_task_state.state_dict[
         "task_grounding_return"] = task_grounding_return
     return_state = perform_task_state.execute()
     self.assertTrue(isinstance(return_state, dialog_flow.ClarifyObjects))
 def setUp(self):
     self.db = DatabaseHandler("test_grounding.db")
     self.task_grounding = TaskGrounding(self.db)
     self.returned = TaskGroundingReturn()
 def __init__(self):
     self.grounding = TaskGrounding()
     self.returned = TaskGroundingReturn()