Пример #1
0
    def test_service_discover_multiple_queue(self):
        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld")
        assert helloworld is None  # service not provided until node starts

        # Start two nodes queue process
        self.hwnodeextra.start()
        assert self.hwnodeextra.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5)  # we wait a bit to let it time to start
        assert not helloworld is None
        assert len(helloworld.providers) ==  1

        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5, 2)   # we wait until we get 2 providers ( or timeout )
        assert not helloworld is None
        assert len(helloworld.providers) ==  2

        self.hwnodeextra.shutdown()
        assert not self.hwnodeextra.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5)  # we wait a bit to let it time to start
        assert not helloworld is None
        assert len(helloworld.providers) ==  1

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #2
0
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()
Пример #3
0
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()
Пример #4
0
    def test_service_discover_timeout(self):
        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld")
        assert helloworld is None  # service not provided until node starts

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 1)  # check timeout actually times out
        assert helloworld is None

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 1, 2)
        assert helloworld is None
Пример #5
0
    def test_service_discover_timeout(self):
        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld")
        assert helloworld is None  # service not provided until node starts

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld",
                                    1)  # check timeout actually times out
        assert helloworld is None

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 1, 2)
        assert helloworld is None
Пример #6
0
    def test_rosnode_subscribers(
            self):  # Here we check that this node actually discovers topics

        # Starting underlying system before
        rospy.set_param('/string_sub/topic_name', '~test_str_topic'
                        )  # private topic name to not mess things up too much
        rospy.set_param('/string_sub/test_message', 'testing topic discovery')
        string_sub_node = roslaunch.core.Node('pyros_test',
                                              'string_sub_node.py',
                                              name='string_sub')
        string_sub_process = self.launch.launch(string_sub_node)
        try:
            # Starting PyrosROS with preconfigured subscribers,
            rosn = PyrosROS(
                kwargs={
                    'subscribers': ['/string_sub/test_str_topic'],
                    'enable_cache': self.enable_cache
                })  # careful assuming the topic fullname here
            try:
                nose.tools.assert_true(not rosn.is_alive())
                rosn.start()
                nose.tools.assert_true(rosn.is_alive())

                print("Discovering subscribers Service...")
                subscribers = pyzmp.discover(
                    "subscribers", 5)  # we wait a bit to let it time to start
                nose.tools.assert_true(subscribers is not None)
                print("subscribers providers : {svc}".format(
                    svc=subscribers.providers))
                nose.tools.assert_equal(len(subscribers.providers), 1)
                nose.tools.assert_true(
                    rosn.name in [p[0] for p in subscribers.providers])

                res = subscribers.call()
                # What we get here is non deterministic
                # however we can wait for topic to be detected to make sure we get it after some time

                with Timeout(15) as t:
                    while not t.timed_out and not '/string_sub/test_str_topic' in res.keys(
                    ):
                        rospy.rostime.wallsleep(1)
                        res = subscribers.call()

                nose.tools.assert_true(
                    '/string_sub/test_str_topic' in res.keys(
                    ))  # test_topic has been created, detected and exposed
            finally:
                # finishing PyrosROS process
                if rosn is not None and rosn.is_alive():
                    rosn.shutdown()

            nose.tools.assert_true(not rosn.is_alive())

        finally:
            # finishing string_pub_process
            if string_sub_process is not None and string_sub_process.is_alive(
            ):
                string_sub_process.stop()

            nose.tools.assert_true(not string_sub_process.is_alive())
Пример #7
0
    def test_service_comm_to_double_sub(self):
        print("\n" + inspect.currentframe().f_code.co_name)

        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        assert not self.hwnodeextra.is_alive()
        self.hwnodeextra.start()
        assert self.hwnodeextra.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5, 2)  # make sure we get both providers. we need them.
        assert helloworld is not None  # to make sure we get a service provided
        assert len(helloworld.providers) ==  2
        resp = helloworld.call(args=("Hello",))
        print("Hello -> {0}".format(resp))
        assert resp == "Hello! I am HNode" or resp == "Hello! I am HNodeExtra"
        resp = helloworld.call(args=("Hallo",))
        print("Hallo -> {0}".format(resp))
        assert resp == "..."

        resp = helloworld.call(args=("Hello",), node=self.hwnode.name)
        print("Hello -HNode-> {0}".format(resp))
        assert resp == "Hello! I am HNode"
        resp = helloworld.call(args=("Hello",), node=self.hwnodeextra.name)
        print("Hello -HNodeExtra-> {0}".format(resp))
        assert resp == "Hello! I am HNodeExtra"

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
        self.hwnodeextra.shutdown()
        assert not self.hwnodeextra.is_alive()
Пример #8
0
    def test_service_double_comm_to_sub(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5)
        assert helloworld is not None  # to make sure we get a service provided

        def callit():
            hw = pyzmp.discover("helloworld", 5)
            return hw.call(args=("Hello",))

        c = multiprocessing.Process(name="Client", target=callit)
        assert not c.is_alive()
        c.start()
        assert c.is_alive()

        resp = helloworld.call(args=("Hello",))
        print("Hallo -> {0}".format(resp))
        assert resp == "Hello! I am HNode"
        resp = helloworld.call(args=("Hallo",))
        print("Hallo -> {0}".format(resp))
        assert resp == "..."
        resp = helloworld.call(args=("Hello",), node=self.hwnode.name)
        print("Hello -HNode-> {0}".format(resp))
        assert resp == "Hello! I am HNode"

        c.join()
        assert not c.is_alive()

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #9
0
    def test_service_double_comm_to_sub_self(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.magic_number = 42
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering getlucky Service...")
        getlucky = pyzmp.discover("getlucky", 5)
        assert getlucky is not None  # to make sure we get a service provided

        def callit():
            getlucky = pyzmp.discover("getlucky", 5)
            return getlucky.call()

        c = multiprocessing.Process(name="Client", target=callit)
        assert not c.is_alive()
        c.start()
        assert c.is_alive()

        resp = getlucky.call()
        print("42 ? -> {0}".format(resp))
        assert resp == 42
        resp = getlucky.call(node=self.hwnode.name)
        print("42 ? -HNode-> {0}".format(resp))
        assert resp == 42

        c.join()
        assert not c.is_alive()

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #10
0
    def test_service_comm_to_double_sub_self(self):
        print("\n" + inspect.currentframe().f_code.co_name)

        assert not self.hwnode.is_alive()
        self.hwnode.magic_number = 42
        self.hwnode.start()
        assert self.hwnode.is_alive()

        assert not self.hwnodeextra.is_alive()
        self.hwnodeextra.magic_number = 79
        self.hwnodeextra.start()
        assert self.hwnodeextra.is_alive()

        print("Discovering getlucky Service...")
        getlucky = pyzmp.discover(
            "getlucky", 5, 2)  # make sure we get both providers. we need them.
        assert getlucky is not None  # to make sure we get a service provided
        assert len(getlucky.providers) == 2
        resp = getlucky.call()
        print("42 || 79 ? -> {0}".format(resp))
        assert resp == 42 or resp == 79

        resp = getlucky.call(node=self.hwnode.name)
        print("42 ? -HNode-> {0}".format(resp))
        assert resp == 42
        resp = getlucky.call(node=self.hwnodeextra.name)
        print("79 ? -HNodeExtra-> {0}".format(resp))
        assert resp == 79

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
        self.hwnodeextra.shutdown()
        assert not self.hwnodeextra.is_alive()
Пример #11
0
    def test_service_comm_to_double_sub_self(self):
        print("\n" + inspect.currentframe().f_code.co_name)

        assert not self.hwnode.is_alive()
        self.hwnode.magic_number = 42
        self.hwnode.start()
        assert self.hwnode.is_alive()

        assert not self.hwnodeextra.is_alive()
        self.hwnodeextra.magic_number = 79
        self.hwnodeextra.start()
        assert self.hwnodeextra.is_alive()

        print("Discovering getlucky Service...")
        getlucky = pyzmp.discover("getlucky", 5, 2)  # make sure we get both providers. we need them.
        assert getlucky is not None  # to make sure we get a service provided
        assert len(getlucky.providers) ==  2
        resp = getlucky.call()
        print("42 || 79 ? -> {0}".format(resp))
        assert resp == 42 or resp == 79

        resp = getlucky.call(node=self.hwnode.name)
        print("42 ? -HNode-> {0}".format(resp))
        assert resp == 42
        resp = getlucky.call(node=self.hwnodeextra.name)
        print("79 ? -HNodeExtra-> {0}".format(resp))
        assert resp == 79

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
        self.hwnodeextra.shutdown()
        assert not self.hwnodeextra.is_alive()
Пример #12
0
    def test_service_double_comm_to_sub_self(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.magic_number = 42
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering getlucky Service...")
        getlucky = pyzmp.discover("getlucky", 5)
        assert getlucky is not None  # to make sure we get a service provided

        def callit():
            getlucky = pyzmp.discover("getlucky", 5)
            return getlucky.call()

        c = multiprocessing.Process(name="Client", target=callit)
        assert not c.is_alive()
        c.start()
        assert c.is_alive()

        resp = getlucky.call()
        print("42 ? -> {0}".format(resp))
        assert resp == 42
        resp = getlucky.call(node=self.hwnode.name)
        print("42 ? -HNode-> {0}".format(resp))
        assert resp == 42

        c.join()
        assert not c.is_alive()

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #13
0
    def test_service_double_comm_to_sub(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5)
        assert helloworld is not None  # to make sure we get a service provided

        def callit():
            hw = pyzmp.discover("helloworld", 5)
            return hw.call(args=("Hello", ))

        c = multiprocessing.Process(name="Client", target=callit)
        assert not c.is_alive()
        c.start()
        assert c.is_alive()

        resp = helloworld.call(args=("Hello", ))
        print("Hallo -> {0}".format(resp))
        assert resp == "Hello! I am HNode"
        resp = helloworld.call(args=("Hallo", ))
        print("Hallo -> {0}".format(resp))
        assert resp == "..."
        resp = helloworld.call(args=("Hello", ), node=self.hwnode.name)
        print("Hello -HNode-> {0}".format(resp))
        assert resp == "Hello! I am HNode"

        c.join()
        assert not c.is_alive()

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #14
0
    def test_service_comm_to_double_sub(self):
        print("\n" + inspect.currentframe().f_code.co_name)

        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        assert not self.hwnodeextra.is_alive()
        self.hwnodeextra.start()
        assert self.hwnodeextra.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover(
            "helloworld", 5,
            2)  # make sure we get both providers. we need them.
        assert helloworld is not None  # to make sure we get a service provided
        assert len(helloworld.providers) == 2
        resp = helloworld.call(args=("Hello", ))
        print("Hello -> {0}".format(resp))
        assert resp == "Hello! I am HNode" or resp == "Hello! I am HNodeExtra"
        resp = helloworld.call(args=("Hallo", ))
        print("Hallo -> {0}".format(resp))
        assert resp == "..."

        resp = helloworld.call(args=("Hello", ), node=self.hwnode.name)
        print("Hello -HNode-> {0}".format(resp))
        assert resp == "Hello! I am HNode"
        resp = helloworld.call(args=("Hello", ), node=self.hwnodeextra.name)
        print("Hello -HNodeExtra-> {0}".format(resp))
        assert resp == "Hello! I am HNodeExtra"

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
        self.hwnodeextra.shutdown()
        assert not self.hwnodeextra.is_alive()
Пример #15
0
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()
Пример #16
0
    def test_service_discover_multiple_queue(self):
        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld")
        assert helloworld is None  # service not provided until node starts

        # Start two nodes queue process
        self.hwnodeextra.start()
        assert self.hwnodeextra.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld",
                                    5)  # we wait a bit to let it time to start
        assert not helloworld is None
        assert len(helloworld.providers) == 1

        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover(
            "helloworld", 5,
            2)  # we wait until we get 2 providers ( or timeout )
        assert not helloworld is None
        assert len(helloworld.providers) == 2

        self.hwnodeextra.shutdown()
        assert not self.hwnodeextra.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld",
                                    5)  # we wait a bit to let it time to start
        assert not helloworld is None
        assert len(helloworld.providers) == 1

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #17
0
    def test_service_discover(self):
        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld")
        assert helloworld is None  # service not provided until node starts

        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5)  # we wait a bit to let it time to start
        assert not helloworld is None
        assert len(helloworld.providers) ==  1

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld")
        assert helloworld is None
Пример #18
0
    def test_service_discover(self):
        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld")
        assert helloworld is None  # service not provided until node starts

        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld",
                                    5)  # we wait a bit to let it time to start
        assert not helloworld is None
        assert len(helloworld.providers) == 1

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld")
        assert helloworld is None
Пример #19
0
    def test_service_except_from_sub(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering breakworld Service...")
        breakworld = pyzmp.discover("breakworld", 5)
        assert breakworld is not None  # to make sure we get a service provided
        with pytest.raises(Exception) as cm:
            resp = breakworld.call(args=("Hello",))

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #20
0
    def test_service_except_from_sub(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering breakworld Service...")
        breakworld = pyzmp.discover("breakworld", 5)
        assert breakworld is not None  # to make sure we get a service provided
        with pytest.raises(Exception) as cm:
            resp = breakworld.call(args=("Hello", ))

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #21
0
    def test_service_params_comm_to_sub(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering add Service...")
        add = pyzmp.discover("add", 5)
        assert add is not None  # to make sure we get a service provided

        resp = add.call(args=(17, 25))
        print(" 17 + 25 -> {0}".format(resp))
        assert resp == 17 + 25

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #22
0
    def test_service_params_comm_to_sub(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering add Service...")
        add = pyzmp.discover("add", 5)
        assert add is not None  # to make sure we get a service provided

        resp = add.call(args=(17, 25))
        print(" 17 + 25 -> {0}".format(resp))
        assert resp == 17+25

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #23
0
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()
Пример #24
0
    def test_service_comm_to_sub_self(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.magic_number = 42
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering getlucky Service...")
        getlucky = pyzmp.discover("getlucky", 5)
        assert getlucky is not None  # to make sure we get a service provided
        resp = getlucky.call()
        print("42 ? -> {0}".format(resp))
        assert resp == 42

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #25
0
    def test_service_comm_to_sub_self(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.magic_number = 42
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering getlucky Service...")
        getlucky = pyzmp.discover("getlucky", 5)
        assert getlucky is not None  # to make sure we get a service provided
        resp = getlucky.call()
        print("42 ? -> {0}".format(resp))
        assert resp == 42

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #26
0
    def test_service_except_from_node_no_service(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering breakworld Service...")
        breakworld = pyzmp.discover("breakworld", 5)
        assert breakworld is not None  # to make sure we get a service provided

        # messing around even if we should not
        breakworld.name = "NOT_EXISTING"

        with pytest.raises(pyzmp.UnknownServiceException) as cm:
            resp = breakworld.call(args=("Hello",))

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #27
0
    def test_service_comm_to_sub(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5)
        assert helloworld is not None  # to make sure we get a service provided
        resp = helloworld.call(args=("Hello", ))
        print("Hello -> {0}".format(resp))
        assert resp == "Hello! I am HNode"
        resp = helloworld.call(args=("Hallo", ))
        print("Hallo -> {0}".format(resp))
        assert resp == "..."

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #28
0
    def test_service_except_from_node_no_service(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering breakworld Service...")
        breakworld = pyzmp.discover("breakworld", 5)
        assert breakworld is not None  # to make sure we get a service provided

        # messing around even if we should not
        breakworld.name = "NOT_EXISTING"

        with pytest.raises(pyzmp.UnknownServiceException) as cm:
            resp = breakworld.call(args=("Hello", ))

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #29
0
    def test_service_comm_to_sub(self):

        print("\n" + inspect.currentframe().f_code.co_name)
        assert not self.hwnode.is_alive()
        self.hwnode.start()
        assert self.hwnode.is_alive()

        print("Discovering helloworld Service...")
        helloworld = pyzmp.discover("helloworld", 5)
        assert helloworld is not None  # to make sure we get a service provided
        resp = helloworld.call(args=("Hello",))
        print("Hello -> {0}".format(resp))
        assert resp == "Hello! I am HNode"
        resp = helloworld.call(args=("Hallo",))
        print("Hallo -> {0}".format(resp))
        assert resp == "..."

        self.hwnode.shutdown()
        assert not self.hwnode.is_alive()
Пример #30
0
 def callit():
     getlucky = pyzmp.discover("getlucky", 5)
     return getlucky.call()
Пример #31
0
 def callit():
     getlucky = pyzmp.discover("getlucky", 5)
     return getlucky.call()
Пример #32
0
 def callit():
     hw = pyzmp.discover("helloworld", 5)
     return hw.call(args=("Hello", ))
Пример #33
0
    def test_rosnode_services(
            self):  # Here we check that this node actually discovers services

        # Starting underlying system before
        rospy.set_param(
            '/string_echo/topic_name',
            '~topic')  # private names to not mess things up too much
        rospy.set_param('/string_echo/echo_topic_name', '~echo_topic')
        rospy.set_param('/string_echo/echo_service_name', '~echo_service')

        string_echo_node = roslaunch.core.Node('pyros_test',
                                               'echo.py',
                                               name='string_echo')
        try:
            string_echo_process = self.launch.launch(string_echo_node)
        except roslaunch.RLException as rlexc:
            logging.error(
                "pyros_test is needed to run this test. Please verify that it is installed in your ROS environment"
            )
            raise
        try:
            # Starting PyrosROS with preconfigured services to expose
            rosn = PyrosROS(
                kwargs={
                    'services': ['/string_echo/echo_service'],
                    'enable_cache': self.enable_cache
                })  # careful assuming the service fullname here
            try:
                nose.tools.assert_true(not rosn.is_alive())
                rosn.start()
                nose.tools.assert_true(rosn.is_alive())

                print("Discovering services Service...")
                services = pyzmp.discover(
                    "services", 5)  # we wait a bit to let it time to start
                nose.tools.assert_true(services is not None)
                print("services providers : {svc}".format(
                    svc=services.providers))
                nose.tools.assert_equal(len(services.providers), 1)
                nose.tools.assert_true(
                    rosn.name in [p[0] for p in services.providers])

                res = services.call()
                # What we get here is non deterministic
                # however we can wait for service to be detected to make sure we get it after some time

                with Timeout(5) as t:
                    while not t.timed_out and not '/string_echo/echo_service' in res.keys(
                    ):
                        rospy.rostime.wallsleep(1)
                        res = services.call()

                nose.tools.assert_true('/string_echo/echo_service' in res.keys(
                ))  # echo_service has been created, detected and exposed
            finally:
                # finishing PyrosROS process
                if rosn is not None and rosn.is_alive():
                    rosn.shutdown()

            nose.tools.assert_true(not rosn.is_alive())

        finally:
            # finishing string_pub_process
            if string_echo_process is not None and string_echo_process.is_alive(
            ):
                string_echo_process.stop()

        nose.tools.assert_true(not string_echo_process.is_alive())
Пример #34
0
    def test_rosnode_services_setup(
        self
    ):  # Here we check that this node actually provides all the services
        rosn = PyrosROS()
        try:
            nose.tools.assert_true(not rosn.is_alive())
            rosn.start()
            nose.tools.assert_true(rosn.is_alive())

            print("Discovering services Service...")
            services = pyzmp.discover(
                "services", 5)  # we wait a bit to let it time to start
            nose.tools.assert_true(services is not None)
            print("services providers : {svc}".format(svc=services.providers))
            nose.tools.assert_equal(len(services.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in services.providers])

            res = services.call()
            nose.tools.assert_true('echo_service' not in res.keys(
            ))  # test_topic has not been created, detected or exposed

            print("Discovering setup Service...")
            setup = pyzmp.discover("setup",
                                   5)  # we wait a bit to let it time to start
            nose.tools.assert_true(setup is not None)
            print("setup providers : {svc}".format(svc=setup.providers))
            nose.tools.assert_equal(len(setup.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in setup.providers])

            rospy.set_param(
                '/string_echo/topic_name',
                '~topic')  # private names to not mess things up too much
            rospy.set_param('/string_echo/echo_topic_name', '~echo_topic')
            rospy.set_param('/string_echo/echo_service_name', '~echo_service')

            string_echo_node = roslaunch.core.Node('pyros_test',
                                                   'echo.py',
                                                   name='string_echo')
            string_echo_process = self.launch.launch(string_echo_node)
            try:

                new_config = setup.call(
                    kwargs={
                        'services': ['/string_echo/echo_service'],
                        'topics': [],
                        'params': [],
                        'enable_cache': self.enable_cache,
                    })
                # What we get here is non deterministic
                # however we can wait for topic to be detected to make sure we get it after some time

                res = services.call()

                with Timeout(5) as t:
                    while not t.timed_out and not '/string_echo/echo_service' in res.keys(
                    ):
                        rospy.rostime.wallsleep(1)
                        res = services.call()

                nose.tools.assert_true('/string_echo/echo_service' in res.keys(
                ))  # test_topic has been created, detected and exposed

            finally:
                # finishing all processes
                if string_echo_process is not None and string_echo_process.is_alive(
                ):
                    string_echo_process.stop()

            nose.tools.assert_true(not string_echo_process.is_alive())

        finally:
            # finishing PyrosROS process
            if rosn is not None and rosn.is_alive():
                rosn.shutdown()

        nose.tools.assert_true(not rosn.is_alive())
Пример #35
0
    def test_rosnode_provide_services(
        self
    ):  # Here we check that this node actually provides all the services
        rosn = PyrosROS()
        nose.tools.assert_true(not rosn.is_alive())
        try:
            rosn.start()
            nose.tools.assert_true(rosn.is_alive())

            print("Discovering msg_build Service...")
            msg_build = pyzmp.discover(
                "msg_build", 5)  # we wait a bit to let it time to start
            nose.tools.assert_true(msg_build is not None)
            print(
                "msg_build providers : {svc}".format(svc=msg_build.providers))
            nose.tools.assert_equal(len(msg_build.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in msg_build.providers])

            print("Discovering topic Service...")
            topic = pyzmp.discover("topic",
                                   5)  # we wait a bit to let it time to start
            nose.tools.assert_true(topic is not None)
            print("topic providers : {svc}".format(svc=topic.providers))
            nose.tools.assert_equal(len(topic.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in topic.providers])

            print("Discovering topics Service...")
            topics = pyzmp.discover("topics",
                                    5)  # we wait a bit to let it time to start
            nose.tools.assert_true(topics is not None)
            print("topics providers : {svc}".format(svc=topics.providers))
            nose.tools.assert_equal(len(topics.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in topics.providers])

            print("Discovering service Service...")
            service = pyzmp.discover(
                "service", 5)  # we wait a bit to let it time to start
            nose.tools.assert_true(service is not None)
            print("service providers : {svc}".format(svc=service.providers))
            nose.tools.assert_equal(len(service.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in service.providers])

            print("Discovering services Service...")
            services = pyzmp.discover(
                "services", 5)  # we wait a bit to let it time to start
            nose.tools.assert_true(services is not None)
            print("services providers : {svc}".format(svc=services.providers))
            nose.tools.assert_equal(len(services.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in services.providers])

            print("Discovering param Service...")
            param = pyzmp.discover("param",
                                   5)  # we wait a bit to let it time to start
            nose.tools.assert_true(param is not None)
            print("param providers : {svc}".format(svc=param.providers))
            nose.tools.assert_equal(len(param.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in param.providers])

            print("Discovering params Service...")
            params = pyzmp.discover("params",
                                    5)  # we wait a bit to let it time to start
            nose.tools.assert_true(params is not None)
            print("params providers : {svc}".format(svc=params.providers))
            nose.tools.assert_equal(len(params.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in params.providers])

            print("Discovering setup Service...")
            setup = pyzmp.discover("setup",
                                   5)  # we wait a bit to let it time to start
            nose.tools.assert_true(setup is not None)
            print("setup providers : {svc}".format(svc=setup.providers))
            nose.tools.assert_equal(len(setup.providers), 1)
            nose.tools.assert_true(
                rosn.name in [p[0] for p in setup.providers])
        finally:
            # finishing PyrosROS process
            if rosn is not None and rosn.is_alive():
                rosn.shutdown()

        nose.tools.assert_true(not rosn.is_alive())
Пример #36
0
 def callit():
     hw = pyzmp.discover("helloworld", 5)
     return hw.call(args=("Hello",))