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 test_get_specific_task_from_task__task_is_find__returns_task_with_find(self): self.db_mock.get_task = Mock(return_value=(1, "find")) task = Task(name="find") task.objects_to_execute_on = [ObjectEntity()] returned = self.task_grounding.get_specific_task_from_task(task) self.assertEqual(TaskType.FIND, returned.task_info[0].task_type)
def test_add_entities_to_task__objects_in_entity_list__adds_object_to_task(self): entities = [ (EntityType.COLOUR, "blue"), (EntityType.OBJECT, "cover") ] self.ner_mock.get_entities = Mock(return_value=entities) task = Task("pick") task.task_type = TaskType.PICK self.cmd_builder.add_entities_to_task(task, "Dummy sentence") self.assertEqual("blue cover", task.objects_to_execute_on[0].name)
def handle_custom_task(self, sub_tasks): tasks = [] for i in range(len(sub_tasks[0])): # task idx task_id = sub_tasks[0][i] task_name = sub_tasks[1][i] db_task = sub_tasks[2][i] task = Task() if db_task is not None: task.name = task_name task.objects_to_execute_on = db_task.objects_to_execute_on task.child_tasks = db_task.child_tasks sub_task_tasks, error = self.task_switch(task_id, task_name, task) tasks.extend(sub_task_tasks) return tasks
def test_get_specific_task_from_task__task_has_no_object__returns_error_code_no_object(self): self.db_mock.get_task = Mock(return_value=(1, "pick up")) task = Task(name="pick up") returned = self.task_grounding.get_specific_task_from_task(task) self.assertFalse(returned.is_success) self.assertEqual(TaskErrorType.NO_OBJECT, returned.error.error_code)
def test_get_specific_task_from_task__task_is_unknown__returns_error_code_unknown(self): self.db_mock.get_task = Mock(return_value=(1, None)) task = Task(name="asdasd") returned = self.task_grounding.get_specific_task_from_task(task) self.assertFalse(returned.is_success) self.assertEqual(TaskErrorType.UNKNOWN, returned.error.error_code)
def test_teach_new_task__valid_input__returns_success(self): self.db_mock.add_task = Mock() self.db_mock.get_task = Mock() self.db_mock.get_task.side_effect = [(1, None), (2, None), (3, None)] self.db_mock.add_sub_task = Mock() returned = self.task_grounding.teach_new_task("nice task name", [Task("take"), Task("move"), Task("put")], "nice task keyword") self.assertTrue(returned.is_success)
def test_get_specific_task_from_tasks__task_is_custom_task_without_sub_tasks__returns_error_code_no_sub_tasks(self): self.db_mock.get_task = Mock(return_value=(1, "clear table")) self.db_mock.get_sub_tasks = Mock(return_value=None) task = Task("tidy") returned = self.task_grounding.get_specific_task_from_task(task) self.assertFalse(returned.is_success) self.assertEqual(TaskErrorType.NO_SUBTASKS, returned.error.error_code)
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_teach_new_task__contains_unknown_task__returns_unknown_error_code(self): self.db_mock.add_task = Mock() self.db_mock.get_task = Mock() self.db_mock.get_task.side_effect = [(None, None)] self.db_mock.add_sub_task = Mock() returned = self.task_grounding.teach_new_task("nice task name", [Task("take"), Task("move"), Task("put")], "nice task keyword") self.assertFalse(returned.is_success) self.assertEqual(TaskErrorType.UNKNOWN, returned.error.error_code)
def test_add_entities_to_task__sub_task_in_entity_list__adds_subtask_to_task(self): entities = [ (EntityType.TASK, "place"), (EntityType.COLOUR, "blue"), (EntityType.OBJECT, "cover"), (EntityType.LOCATION, "next"), (EntityType.COLOUR, "white"), (EntityType.OBJECT, "cover"), (EntityType.LOCATION, "top left corner"), (EntityType.OBJECT, "table") ] self.ner_mock.get_entities = Mock(return_value=entities) task = Task("pick") task.task_type = TaskType.PICK self.cmd_builder.add_entities_to_task(task, "Dummy sentence") self.assertEqual("place", task.child_tasks[0].name) self.assertEqual("white cover", task.child_tasks[0].objects_to_execute_on[0].spatial_descriptions[0].object_entity.name) self.assertEqual("top left corner", task.child_tasks[0].objects_to_execute_on[0].spatial_descriptions[1].object_entity.name)
def task_switch(self, task_id, task_name, task: Task): tasks = [] if task_name is None: return None, self.unknown_task_error(task.name) elif task_name == "pick up": # Check the default skills first. task.task_type = TaskType.PICK tasks.append(task) if len(task.objects_to_execute_on) == 0: error = self.missing_entities_error(task.name) return tasks, error elif task_name == "find": task.task_type = TaskType.FIND tasks.append(task) if len(task.objects_to_execute_on) == 0: error = self.missing_entities_error(task.name) return tasks, error elif task_name == "move": task.task_type = TaskType.MOVE tasks.append(task) if len(task.objects_to_execute_on) == 0: error = self.missing_entities_error(task.name) return tasks, error elif task_name == "place": task.task_type = TaskType.PLACE tasks.append(task) if len(task.objects_to_execute_on) == 0: error = self.missing_entities_error(task.name) return tasks, error else: sub_tasks = self.db.get_sub_tasks(task_id) if sub_tasks is None: error = TaskGroundingError() error.error_task_name = task_name error.error_code = TaskErrorType.NO_SUBTASKS return None, error tasks = self.handle_custom_task(sub_tasks) return tasks, None
def test_verify_command__no_teach_first_run__returns_wait_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")] task = Task(name="Dummy name") verify_command_state = dialog_flow.VerifyCommandState( self.state_dict, self.container) self.container.speak = Mock() self.container.ner.get_entities = Mock(return_value=entities) self.container.command_builder.get_task = Mock(return_value=task) verify_command_state.state_dict[ "last_received_sentence"] = "Dummy sentence" return_state = verify_command_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 test_get_specific_task_from_task__task_is_custom_task__returns_list_of_primary_skills(self): pick_up_task = Task("pick up") pick_up_task.task_type = TaskType.PICK pick_up_task.objects_to_execute_on = [ObjectEntity()] move_task = Task("pick up") move_task.task_type = TaskType.MOVE move_task.objects_to_execute_on = [ObjectEntity()] place_task = Task("pick up") place_task.task_type = TaskType.PICK place_task.objects_to_execute_on = [ObjectEntity()] sub_tasks = [[1, 2, 3], ["pick up", "move", "place"], [pick_up_task, move_task, place_task]] tasks = [TaskType.PICK, TaskType.MOVE, TaskType.PLACE] self.db_mock.get_task = Mock(return_value=(1, "clear table")) self.db_mock.get_sub_tasks = Mock(return_value=sub_tasks) task = Task("tidy") returned = self.task_grounding.get_specific_task_from_task(task) returned_tasks = [returned.task_info[0].task_type, returned.task_info[1].task_type, returned.task_info[2].task_type] self.assertEqual(tasks, returned_tasks)
def test_MoveBlue(self): tasks = [TaskType.PICK, TaskType.PLACE] returned = self.task_grounding.get_specific_task_from_task(Task("blue1")) returned_tasks = [returned.task_info[0].task_type, returned.task_info[1].task_type] self.assertEqual(tasks, returned_tasks)