-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from tecnalia-advancedmanufacturing-robotics/f…
…ix_service_call Fix service call
- Loading branch information
Showing
5 changed files
with
29 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[![license - apache 2.0](https://img.shields.io/:license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
|
||
# node_test | ||
|
||
[![license - apache 2.0](https://img.shields.io/:license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
|
||
The package `node_test` extends `rostest` to add more testing functionalities at node level. | ||
|
||
**Author & Maintainer**: [Anthony Remazeilles](https://github.com/aremazeilles), [email protected] | ||
**Author & Maintainer**: [Anthony Remazeilles](https://github.com/aremazeilles), <mailto:[email protected]> | ||
|
||
**Affiliation** : Tecnalia Research and Innovation, Spain | ||
|
||
|
@@ -17,6 +17,7 @@ See [LICENSE.md](LICENSE.md) for more details. | |
|
||
We assume [`ROS`][ros] is installed on the machine. | ||
Code developed and tested so far under `ROS kinetic`. | ||
Currently working under `ROS noetic` | ||
|
||
[ros]: http://www.ros.org/ | ||
|
||
|
@@ -93,7 +94,6 @@ rostest node_test example_srv.test | |
|
||
### test_filter | ||
|
||
|
||
`test_filter` enables testing a filter-like node, that is supposed to publish a message after having processed a received message. | ||
|
||
An example is provided in [msg_filter.test](node_test/test/msg_filter.test): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
<rosparam> | ||
filters: | ||
- topic_in: topic to which the filter node is subscribed to | ||
topic_out: topic to which the filter node will pubish filter output | ||
topic_out: topic to which the filter node will publish filter output | ||
msg_in: message to publish on topic_in, in python dictionary format | ||
msg_out: message to be received on topic_out, in python dictionary format | ||
timeout: limit time [s] for receiving the filter output | ||
|
@@ -25,16 +25,14 @@ | |
__author__ = "Anthony Remazeilles" | ||
__email__ = "[email protected]" | ||
__copyright__ = "Copyright (C) 2020 Tecnalia Research and Innovation" | ||
__licence__ = "Apache 2.0" | ||
__license__ = "Apache 2.0" | ||
|
||
import sys | ||
import time | ||
import unittest | ||
import rospy | ||
import rostopic | ||
import rosmsg | ||
import rostest | ||
import genpy | ||
from rospy_message_converter import message_converter | ||
|
||
CLASSNAME = 'filterTest' | ||
|
@@ -73,8 +71,8 @@ def test_filter(self): | |
keys = ['topic_in', 'topic_out', 'msg_in', 'msg_out', 'timeout'] | ||
|
||
for item in keys: | ||
if item not in keys: | ||
self.fail("{} field required, but not specified in {}".format(item, call)) | ||
if item not in one_filter: | ||
self.fail("{} field required, but not specified in {}".format(item, one_filter)) | ||
|
||
if one_filter['topic_in'] == 'None': | ||
rospy.logwarn('None input converted to empty input') | ||
|
@@ -123,10 +121,10 @@ def _test_filter(self, topic_in, topic_out, msg_in, msg_out, timeout): | |
ros_msg_in = message_converter.convert_dictionary_to_ros_message(msg_in_type, msg_in) | ||
rospy.loginfo("Generated message: [%s]" % (ros_msg_in)) | ||
except ValueError as err: | ||
msg_err = "Prb in message in contruction \n" | ||
msg_err = "Prb in message in construction \n" | ||
msg_err += "Expected type: [%s]\n" % (msg_in_type) | ||
msg_err += "dictionary: [%s]\n" % (msg_in) | ||
msg_err += "Erorr: [%s]\n" % (str(err)) | ||
msg_err += "Error: [%s]\n" % (str(err)) | ||
self.fail(msg_err) | ||
|
||
# getting message to receive | ||
|
@@ -139,10 +137,10 @@ def _test_filter(self, topic_in, topic_out, msg_in, msg_out, timeout): | |
ros_msg_out = message_converter.convert_dictionary_to_ros_message(msg_out_type, msg_out) | ||
rospy.loginfo("Generated message: [%s]" % (ros_msg_out)) | ||
except ValueError as err: | ||
msg_err = "Prb in message in contruction \n" | ||
msg_err = "Prb in message construction \n" | ||
msg_err += "Expected type: [%s]\n" % (msg_out_type) | ||
msg_err += "dictionary: [%s]\n" % (msg_out) | ||
msg_err += "Erorr: [%s]\n" % (str(err)) | ||
msg_err += "Errorr: [%s]\n" % (str(err)) | ||
self.fail(msg_err) | ||
|
||
# subscription | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
__author__ = "Anthony Remazeilles" | ||
__email__ = "[email protected]" | ||
__copyright__ = "Copyright (C) 2020 Tecnalia Research and Innovation" | ||
__licence__ = "Apache 2.0" | ||
__license__ = "Apache 2.0" | ||
|
||
import sys | ||
import time | ||
|
@@ -92,7 +92,7 @@ def setUp(self): | |
def test_advertise_service(self): | ||
"""Test services are advertised""" | ||
t_start = self.t_start | ||
s_name_set = set([ item['name'] for item in self.calls]) | ||
s_name_set = set([item['name'] for item in self.calls]) | ||
t_timeout_max = 10.0 | ||
|
||
while not rospy.is_shutdown(): | ||
|
@@ -133,11 +133,16 @@ def _test_service(self, srv_name, srv_input, srv_output): | |
srv_proxy = rospy.ServiceProxy(srv_name, srv_class) | ||
except KeyError as err: | ||
msg_err = "Service proxy could not be created" | ||
msg_err += "Error: [%s]\n" % (str(err)) | ||
self.fail(msg_err) | ||
|
||
try: | ||
if srv_input: | ||
srv_resp = srv_proxy(**srv_input) | ||
srv_type = rosservice.get_service_type(srv_name) | ||
rospy.loginfo(f"Service type: {srv_type}") | ||
|
||
req = message_converter.convert_dictionary_to_ros_message(srv_type, srv_input, kind='request') | ||
srv_resp = srv_proxy(req) | ||
else: | ||
srv_resp = srv_proxy() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters