def __init__( self, name="", host=None, serializer=None, transport=None, attributes=None, backend=Backend.OSBRAIN, mesa_model=None, ): self.backend = self.validate_backend(backend) if self.backend == Backend.OSBRAIN: self._remove_methods(MesaAgent) osBrainAgent.__init__( self, name=name, host=host, serializer=serializer, transport=transport, attributes=attributes, ) elif self.backend == Backend.MESA: MesaAgent.__init__(self, name, mesa_model) self._remove_methods(osBrainAgent) self.init_mesa(name) self.unique_id = name self.name = name self.mesa_model = mesa_model
def test_agent_error_permission(nsaddr): """ Agent start() should raise an error if it has not sufficient permissions. """ agent = Agent('a0', nsaddr, '127.0.0.1:22') try: agent.start() agent.shutdown() assert 0 except RuntimeError: pass except: raise
def test_agent_error_os(nsaddr): """ Agent start() should raise an error if address is already in use. """ agent = Agent('a0', nsaddr, nsaddr) try: agent.start() agent.shutdown() assert 0 except RuntimeError: pass except: raise
def test_agent_uuid(): """ All agent identifiers should be unique strings. """ N = 100 bunch = set(Agent()._uuid for i in range(N)) assert len(bunch) == N assert all(isinstance(identifier, bytes) for identifier in bunch)
def shutdown(self): if self.backend == Backend.OSBRAIN: osBrainAgent.shutdown(self) else: # self.backend == Backend.MESA: self.mesa_model.schedule.remove(self) del self