def test_no_skill_properties(self): goal = 'example-skill' skills = [self.skill_generator()] with self.assertRaises(KeyError): sf = SkillFactory(goal, skills) s = sf.goal_decoder(goal, skills)
def test_unknown_skill_properties(self): goal = 'example-skill;exampleSkillProperty0=exampleSkillValue0;exampleSkillProperty1=exampleSkillValue1;unknownSkillProperty=unknownSkillPropertyValue' skills = [self.skill_generator()] with self.assertRaises(KeyError): sf = SkillFactory(goal, skills) s = sf.goal_decoder(goal, skills)
def test_wrong_formatted_goal(self): goal = 'example-skill;wrongFormatted' skills = [self.skill_generator()] with self.assertRaises(ValueError): sf = SkillFactory(goal, skills) s = sf.goal_decoder(goal, skills)
def test_unknown_skill_name(self): goal = 'unknown-skill' skills = [self.skill_generator()] with self.assertRaises(ValueError): sf = SkillFactory(goal, skills) s = sf.goal_decoder(goal, skills)
def test_empty_goal_string(self): goal = '' skills = [self.skill_generator()] with self.assertRaises(ValueError): sf = SkillFactory(goal, skills) s = sf.goal_decoder(goal, skills)
def test_empty_goal_object(self): goal = None skills = [self.skill_generator()] with self.assertRaises(AttributeError): sf = SkillFactory(goal, skills) s = sf.goal_decoder(goal, skills)
def test_decode_goal_with_multiple_skill_properties(self): goal = 'example-skill;exampleSkillProperty0=exampleSkillValue0;exampleSkillProperty1=exampleSkillValue1;exampleSkillProperty2=exampleSkillValue2' skills = [ self.skill_generator(skillProperties=[ 'exampleSkillProperty0', 'exampleSkillProperty1', 'exampleSkillProperty2' ]) ] sf = SkillFactory(goal, skills) decodedGoal = sf.goal_decoder(goal, skills) self.assertEquals(decodedGoal['skillName'], 'example-skill') self.assertEquals(decodedGoal['skillType'], 'GenericSkill') self.assertEquals(decodedGoal['skillClass'], 'GenericSkill') self.assertEquals(decodedGoal['allowedSkillPropertiesKeys'], [ 'exampleSkillProperty0', 'exampleSkillProperty1', 'exampleSkillProperty2' ]) self.assertEquals( decodedGoal['skillProperties'], { 'exampleSkillProperty0': 'exampleSkillValue0', 'exampleSkillProperty1': 'exampleSkillValue1', 'exampleSkillProperty2': 'exampleSkillValue2' })
def test_decode_simple_goal_with_list_of_skills(self): goal = 'example-skill;exampleSkillProperty0=exampleSkillValue0' skills = [ self.skill_generator(skillProperties=['exampleSkillProperty0']), self.skill_generator(skillName='example-skill-2') ] sf = SkillFactory(goal, skills) decodedGoal = sf.goal_decoder(goal, skills) self.assertEquals(decodedGoal['skillName'], 'example-skill') self.assertEquals(decodedGoal['skillType'], 'GenericSkill') self.assertEquals(decodedGoal['skillClass'], 'GenericSkill') self.assertEquals(decodedGoal['allowedSkillPropertiesKeys'], ['exampleSkillProperty0']) self.assertEquals(decodedGoal['skillProperties'], {'exampleSkillProperty0': 'exampleSkillValue0'})
def test_decode_goal_with_list_property_values(self): goal = 'example-skill;exampleSkillProperty0=[1, 2, 3];exampleSkillProperty1=[4, 5, 6]' skills = [ self.skill_generator(skillProperties=[ 'exampleSkillProperty0', 'exampleSkillProperty1' ]) ] sf = SkillFactory(goal, skills) decodedGoal = sf.goal_decoder(goal, skills) self.assertEquals(decodedGoal['skillProperties'], { 'exampleSkillProperty0': [1, 2, 3], 'exampleSkillProperty1': [4, 5, 6] }) self.assertTrue( isinstance(decodedGoal['skillProperties']['exampleSkillProperty0'], list)) self.assertTrue( isinstance(decodedGoal['skillProperties']['exampleSkillProperty1'], list))
def test_decode_goal_with_float_property_values(self): goal = 'example-skill;exampleSkillProperty0=1.1;exampleSkillProperty1=10.1' skills = [ self.skill_generator(skillProperties=[ 'exampleSkillProperty0', 'exampleSkillProperty1' ]) ] sf = SkillFactory(goal, skills) decodedGoal = sf.goal_decoder(goal, skills) self.assertEquals(decodedGoal['skillProperties'], { 'exampleSkillProperty0': 1.1, 'exampleSkillProperty1': 10.1 }) self.assertTrue( isinstance(decodedGoal['skillProperties']['exampleSkillProperty0'], float)) self.assertTrue( isinstance(decodedGoal['skillProperties']['exampleSkillProperty1'], float))
def test_simple_wait_skill_factory(self): goal = 'example-skill;exampleSkillProperty0=exampleSkillValue0;exampleSkillProperty1=exampleSkillValue1' skills = [self.skill_generator()] sf = SkillFactory(goal, skills) self.assertTrue(isinstance(sf.skill, GenericSkill)) self.assertEquals(sf.skill.skillName, 'example-skill') self.assertEquals(sf.skill.skillType, 'GenericSkill') self.assertEquals(sf.skill.skillClass, 'GenericSkill') self.assertEquals(sf.skill.allowedSkillPropertiesKeys, ['exampleSkillProperty0', 'exampleSkillProperty1']) self.assertEquals( sf.skill.skillProperties, { 'exampleSkillProperty0': 'exampleSkillValue0', 'exampleSkillProperty1': 'exampleSkillValue1' })
def assign_mission_service_handler(self, missionId='defaultMissionId', robotId='defaultRobotId', goals=[], priority='NORMAL', executeMission=False): if robotId != self.robotId: rospy.logwarn('[TaskManager] [' + str(self.robotId) + '] Mission ' + str(missionId) + ' refused: Different robotId!') return MSGConstructor.ActionAcceptedRefusedConstructor( accepted='False', reasonOfRefusal='Different robotId!') if self.missionQueueSize > 0: if len(self.taskQueue) >= self.missionQueueSize: rospy.logwarn('[TaskManager] [' + str(self.robotId) + '] Mission ' + str(missionId) + ' refused: Mission queue is already fulfilled!') return MSGConstructor.ActionAcceptedRefusedConstructor( accepted='False', reasonOfRefusal='Mission queue is already fulfilled!') #this feature was comented by Ivo/Heber request. #TODO: it should be uncomented to refuse again in the future # for mission in self.missions: # if missionId == mission['missionId']: # rospy.logwarn('[TaskManager] [' + str(self.robotId) + '] Mission ' + str(missionId) + ' refused: Mission already stored!') # # return MSGConstructor.ActionAcceptedRefusedConstructor(accepted='False', reasonOfRefusal='Mission already stored!') if len(goals) == 0: rospy.logwarn('[TaskManager] [' + str(self.robotId) + '] Mission ' + str(missionId) + ' refused: Empty goals!') return MSGConstructor.ActionAcceptedRefusedConstructor( accepted='False', reasonOfRefusal='Empty goals!') if priority not in self.possiblePriorities: rospy.logwarn('[TaskManager] [' + str(self.robotId) + '] Mission ' + str(missionId) + ' refused: Priority is not well defined!') return MSGConstructor.ActionAcceptedRefusedConstructor( accepted='False', reasonOfRefusal='Priority is not well defined!') missionSkills = [] for goal in goals: try: sf = SkillFactory(goal, self.skills) missionSkills += [sf.skill] except Exception as e: rospy.logwarn('[TaskManager] [' + str(self.robotId) + '] Mission ' + str(missionId) + ' refused: Badly formatted goal (' + str(goal) + '): ' + str(e)) return MSGConstructor.ActionAcceptedRefusedConstructor( accepted='False', reasonOfRefusal='Badly formatted goal (' + str(goal) + '): ' + str(e)) self.missions.append({ 'missionId': missionId, 'taskId': '', 'statusCode': '', 'statusDescription': 'Mission Created' }) priorityNum = self.possiblePriorities[ priority] #Transforms priority description (LOW, NORMAL or HIGH in a number 0,1,2) mission = { 'missionId': missionId, 'missionSkills': missionSkills, 'priority': priorityNum, 'executeMission': executeMission } #this for loop apends missions in the queue deppendig on its priority for task in self.taskQueue: if task['priority'] < priorityNum: self.taskQueue.insert(self.taskQueue.index(task), mission) break else: self.taskQueue.append(mission) if self.robotState == 'busy': rospy.loginfo('[TaskManager] [' + str(self.robotId) + '] Mission ' + str(missionId) + ' Accepted! Waiting for execution.') rospy.loginfo('[TaskManager] [' + str(self.robotId) + '] Mission Queue' + str([task['missionId'] for task in self.taskQueue])) return MSGConstructor.ActionAcceptedRefusedConstructor( accepted='True', reasonOfRefusal='None') else: rospy.loginfo('[TaskManager] [' + str(self.robotId) + '] Mission ' + str(missionId) + ' Accepted! Starting Execution.') self.queue_execution_handler() return MSGConstructor.ActionAcceptedRefusedConstructor( accepted='True', reasonOfRefusal='None')