Package teamwork :: Package test :: Package agent :: Module testSupport
[hide private]
[frames] | no frames]

Source Code for Module teamwork.test.agent.testSupport

 1  from teamwork.agent.Entities import * 
 2  from teamwork.multiagent.sequential import * 
 3  from teamwork.multiagent.GenericSociety import * 
 4  from teamwork.agent.DefaultBased import createEntity 
 5  from teamwork.examples.InfoShare.PortClasses import * 
 6  from teamwork.math.ProbabilityTree import * 
 7   
 8  import unittest 
 9   
10 -class TestRecursiveAgent(unittest.TestCase):
11 - def setUp(self):
12 """Creates the instantiated scenario used for testing""" 13 society = GenericSociety() 14 society.importDict(classHierarchy) 15 entities = [] 16 self.instances = {'World':1,'FederalAuthority':1, 17 'FirstResponder':1,'Shipper':1} 18 for cls,num in self.instances.items(): 19 for index in range(num): 20 if num > 1: 21 name = '%s%d' % (cls,index) 22 else: 23 name = cls 24 entities.append(createEntity(cls,name,society,PsychEntity)) 25 self.entities = SequentialAgents(entities) 26 self.entities.applyDefaults() 27 # Set up the spec of the desired test action 28 entity = self.entities['FirstResponder'] 29 options = entity.actions.getOptions() 30 self.inspect = None 31 self.pass_ = None 32 for act in options: 33 if act[0]['type'] == 'inspect': 34 self.inspect = act 35 elif act[0]['type'] == 'pass': 36 self.pass_ = act 37 self.assert_(self.inspect) 38 self.assert_(self.pass_)
39
40 - def testDynamics(self):
41 parent = self.entities['FederalAuthority'] 42 entity = parent.getEntity('FirstResponder') 43 state = parent.entities.getState() 44 actions = {entity.name:self.pass_} 45 dynamics = parent.entities.getDynamics(actions)['state'].getTree() 46 goals = parent.getGoalTree() 47 print goals*dynamics
48 49 if __name__ == '__main__': 50 unittest.main() 51