def test_echo_service(): msg = 'testing' mock = PyrosMock() print("msg sent is {0}".format(msg)) recv_msg = mock.service('random_service', msg) print("msg received is {0}".format(recv_msg)) assert msg == recv_msg
def test_mocknode_subscribers_detect_setup(): # Here we check that this node actually detects a topic upon setup mockn = PyrosMock() assert not mockn.is_alive() assert hasattr(mockn, 'topics') mockn.start() try: assert mockn.is_alive() with mock_subscriber_remote('test_topic', statusecho_topic): print("Discovering topics Service...") topics = pyzmp.discover("topics", 3) # we wait a bit to let it time to start assert topics is not None assert len(topics.providers) == 1 res = topics.call() assert not 'test_topic' in res # topic not detected since not in list of exposed topics print("Discovering setup Service...") setup = pyzmp.discover("setup", 3) # we wait a bit to let it time to start assert setup is not None assert len(setup.providers) == 1 setup.call(kwargs={'services': [], 'topics': ['test_topic'], 'params': []}) time.sleep(mockn.update_interval + 1) # waiting for update to kick in res = topics.call() assert 'test_topic' in res finally: mockn.shutdown() assert not mockn.is_alive()
def test_mocknode_provide_services(): # Here we check that this node actually provides all the services mockn = PyrosMock() assert not mockn.is_alive() assert hasattr(mockn, 'msg_build') assert hasattr(mockn, 'topic') assert hasattr(mockn, 'topics') assert hasattr(mockn, 'service') assert hasattr(mockn, 'services') assert hasattr(mockn, 'param') assert hasattr(mockn, 'params') assert hasattr(mockn, 'setup') mockn.start() try: assert mockn.is_alive() print("Discovering msg_build Service...") msg_build = pyzmp.discover("msg_build", 5) # we wait a bit to let it time to start assert msg_build is not None assert len(msg_build.providers) == 1 print("Discovering topic Service...") topic = pyzmp.discover("topic", 5) # we wait a bit to let it time to start assert topic is not None assert len(topic.providers) == 1 print("Discovering topics Service...") topic_list = pyzmp.discover("topics", 5) # we wait a bit to let it time to start assert topic_list is not None assert len(topic_list.providers) == 1 print("Discovering service Service...") service = pyzmp.discover("service", 5) # we wait a bit to let it time to start assert service is not None assert len(service.providers) == 1 print("Discovering services Service...") service_list = pyzmp.discover("services", 5) # we wait a bit to let it time to start assert service_list is not None assert len(service_list.providers) == 1 print("Discovering param Service...") param = pyzmp.discover("param", 5) # we wait a bit to let it time to start assert param is not None assert len(param.providers) == 1 print("Discovering params Service...") param_list = pyzmp.discover("params", 5) # we wait a bit to let it time to start assert param_list is not None assert len(param_list.providers) == 1 print("Discovering setup Service...") param_list = pyzmp.discover("setup", 5) # we wait a bit to let it time to start assert param_list is not None assert len(param_list.providers) == 1 finally: mockn.shutdown() assert not mockn.is_alive()
def test_other_topic(): msg = 'testing' mock = PyrosMock() mock.topic('random_topic', msg) print("msg sent is {0}".format(msg)) recv_msg = mock.topic('random_topic_2') print("msg received is {0}".format(recv_msg)) assert recv_msg is None
def test_echo_same_topic(): msg = 'testing' mock = PyrosMock() mock.topic('random_topic', msg) print("msg sent is {0}".format(msg)) recv_msg = mock.topic('random_topic') print("msg received is {0}".format(recv_msg)) assert msg == recv_msg
def test_mocknode_creation_termination(): mockn = PyrosMock() assert not mockn.is_alive() mockn.start() try: assert mockn.is_alive() finally: mockn.shutdown() assert not mockn.is_alive()
def test_mocknode_subscribers_configure_detect(): # Here we check that this node actually detects a topic mockn = PyrosMock() mockn.configure({ 'SERVICES': [], 'PUBLISHERS': [], 'SUBSCRIBERS': ['test_topic'], 'PARAMS': [] }) assert not mockn.is_alive() assert hasattr(mockn, 'topics') # starting the node mockn.start() # checking interface is still None here ( instantiated in child only ) assert mockn.interface is None # Services are initialized in run() method of pyzmp.Node, after interface has been initialized try: assert mockn.is_alive() with mock_subscriber_remote('test_topic', statusecho_topic): # asserting the mock system has done its job from our point of view at least assert 'test_topic' in topics_available_remote assert topics_available_type_remote['test_topic'] == statusecho_topic # Getting topics list from child process print("Discovering topics Service...") topics = pyzmp.discover("topics", 3) # we wait a bit to let it time to start assert topics is not None assert len(topics.providers) == 1 time.sleep(mockn.update_interval + 1) # make sure we let update time to kick in res = topics.call(recv_timeout=6000000) # the mock system should have done its job from the other process perspective too # via multiprocess manager list assert 'test_topic' in res # topic detected since in list of exposed topics finally: mockn.shutdown() assert not mockn.is_alive()
def test_mocknode_subscribers_detect_throttled(): """ Testing that the mocknode detection of topics is throttled properly :return: """ mockn = PyrosMock() assert not mockn.is_alive() assert hasattr(mockn, 'topics') mockn.update_interval = 5 # we wait 5 seconds between each update_throttled call mockn.start() # one update will be triggered, and then nothing for the next 10 seconds try: assert mockn.is_alive() print("Discovering setup Service...") setup = pyzmp.discover("setup", 3) # we wait a bit to let it time to start assert setup is not None assert len(setup.providers) == 1 setup.call(kwargs={'services': [], 'topics': ['test_topic'], 'params': []}) with mock_subscriber_remote('test_topic', statusecho_topic): print("Discovering topics Service...") topics = pyzmp.discover("topics", 3) # we wait a bit to let it time to start assert topics is not None assert len(topics.providers) == 1 # topic is very likely not detected yet ( we didn't wait after creating and exposing it ) res = topics.call() assert not 'test_topic' in res time.sleep(mockn.update_interval + 1) # make sure we let update time to kick in # topic has to be detected now res = topics.call() assert 'test_topic' in res finally: # to make sure we clean up on failure mockn.shutdown() assert not mockn.is_alive()
def setup_class(cls): cls.mockInstance = PyrosMock() assert cls.mockInstance.start()
def test_echo_service_default(): msg = 'testing' mock = PyrosMock() assert mock.service('random_service') is None
def test_echo_topic_default(): mock = PyrosMock() recv_msg = mock.topic('random_topic') assert recv_msg is None
def test_msg_build(): msg = PyrosMock().msg_build('fake_connec_name') print("msg is of type {0}".format(type(msg))) assert isinstance(msg, str)
def setUp(self): self.mockInstance = PyrosMock() # setting up mockinterface instance cmd_conn = self.mockInstance.start() self.client = PyrosClient(cmd_conn)