def test_agent_shutdown(nsproxy): """ An agent must unregister itself before shutting down. """ agent = AgentProcess('a0', nsproxy.addr()) agent.start() a0 = Proxy('a0', nsproxy.addr()) a0.run() a0.wait_for_running() assert 'a0' in nsproxy.list() a0.shutdown() agent.join() assert 'a0' not in nsproxy.list()
def test_agent_inheritance(nsproxy): """ Test agent inheritance; agents can be based on a custom class. """ class NewAgent(Agent): def the_answer_to_life(self): return 42 # Test an Agent based on the new class AgentProcess('new', nsaddr=nsproxy.addr(), base=NewAgent).start() new = Proxy('new', nsproxy.addr()) new.run() new.wait_for_running() assert new.the_answer_to_life() == 42 # Test the quick `run_agent` function a0 = run_agent('a0', nsproxy.addr(), base=NewAgent) assert a0.the_answer_to_life() == 42