This commit is contained in:
Ivan
2022-04-05 11:42:28 +03:00
commit 6dc0eb0fcf
5565 changed files with 1200500 additions and 0 deletions

View File

@@ -0,0 +1,187 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package rostopic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.12.14 (2018-08-23)
--------------------
1.12.13 (2018-02-21)
--------------------
1.12.12 (2017-11-16)
--------------------
1.12.11 (2017-11-07)
--------------------
1.12.10 (2017-11-06)
--------------------
1.12.9 (2017-11-06)
-------------------
1.12.8 (2017-11-06)
-------------------
* fix rostopic hz and bw in Python 3 (`#1126 <https://github.com/ros/ros_comm/issues/1126>`_)
* update tests to match stringify changes (`#1125 <https://github.com/ros/ros_comm/issues/1125>`_)
* fix rostopic prining long integers (`#1110 <https://github.com/ros/ros_comm/pull/1110>`_)
1.12.7 (2017-02-17)
-------------------
1.12.6 (2016-10-26)
-------------------
* fix typo of arg for _str_plot function (`#915 <https://github.com/ros/ros_comm/issues/915>`_)
1.12.5 (2016-09-30)
-------------------
* fix regression with rostopic echo for primitive fields from 1.12.3 (`#909 <https://github.com/ros/ros_comm/issues/909>`_)
1.12.4 (2016-09-19)
-------------------
1.12.3 (2016-09-17)
-------------------
* show topic field type with rostopic type (`#860 <https://github.com/ros/ros_comm/issues/860>`_)
* show stat for rostopic echo --noarr/nostr (`#724 <https://github.com/ros/ros_comm/pull/724>`_, `#872 <https://github.com/ros/ros_comm/pull/872>`_)
* add support for multiple topics in rostopic hz (`#712 <https://github.com/ros/ros_comm/pull/712>`_, `#886 <https://github.com/ros/ros_comm/pull/886>`_, `#888 <https://github.com/ros/ros_comm/pull/888>`_)
* more detailed help string for rostopic echo -p (`#816 <https://github.com/ros/ros_comm/issues/816>`_)
1.12.2 (2016-06-03)
-------------------
1.12.1 (2016-04-18)
-------------------
1.12.0 (2016-03-18)
-------------------
1.11.18 (2016-03-17)
--------------------
1.11.17 (2016-03-11)
--------------------
* add "rostopic delay" to measure message delay compared to the input from real world (`#719 <https://github.com/ros/ros_comm/pull/719>`_)
* add option to perform keyword substitution for messages published with "rostopic pub" (`#702 <https://github.com/ros/ros_comm/pull/702>`_)
* add wall-time option for rostopic hz (`#674 <https://github.com/ros/ros_comm/pull/674>`_)
1.11.16 (2015-11-09)
--------------------
1.11.15 (2015-10-13)
--------------------
* add warning to rostopic hz about simulated time (`#672 <https://github.com/ros/ros_comm/pull/672>`_)
1.11.14 (2015-09-19)
--------------------
* support specifying multiple array indices (`#606 <https://github.com/ros/ros_comm/pull/606>`_)
* fix string type check if variable is unicode
1.11.13 (2015-04-28)
--------------------
1.11.12 (2015-04-27)
--------------------
* fix command parsing for rosservice and rostopic to not accept arbitrary substrings of 'list' (`#609 <https://github.com/ros/ros_comm/issues/609>`_)
1.11.11 (2015-04-16)
--------------------
1.11.10 (2014-12-22)
--------------------
* add support for fixed-width floating-point and integer array values (`#400 <https://github.com/ros/ros_comm/issues/400>`_)
1.11.9 (2014-08-18)
-------------------
1.11.8 (2014-08-04)
-------------------
* fix handling of array index when being part of the topic (`#480 <https://github.com/ros/ros_comm/issues/480>`_)
* support splice arguments in 'rostopic echo' (`#480 <https://github.com/ros/ros_comm/issues/480>`_)
1.11.7 (2014-07-18)
-------------------
1.11.6 (2014-07-10)
-------------------
1.11.5 (2014-06-24)
-------------------
1.11.4 (2014-06-16)
-------------------
* Python 3 compatibility (`#426 <https://github.com/ros/ros_comm/issues/426>`_, `#427 <https://github.com/ros/ros_comm/issues/427>`_)
1.11.3 (2014-05-21)
-------------------
* add publisher queue_size to rostopic
1.11.2 (2014-05-08)
-------------------
1.11.1 (2014-05-07)
-------------------
* add check for message fields when determining message type (`#376 <https://github.com/ros/ros_comm/issues/376>`_)
1.11.0 (2014-03-04)
-------------------
* make rostest in CMakeLists optional (`ros/rosdistro#3010 <https://github.com/ros/rosdistro/issues/3010>`_)
* use catkin_install_python() to install Python scripts (`#361 <https://github.com/ros/ros_comm/issues/361>`_)
1.10.0 (2014-02-11)
-------------------
1.9.54 (2014-01-27)
-------------------
* fix wrong time in csv export when using 'rostopic echo -p -b' (`#330 <https://github.com/ros/ros_comm/issues/330>`_)
1.9.53 (2014-01-14)
-------------------
1.9.52 (2014-01-08)
-------------------
1.9.51 (2014-01-07)
-------------------
1.9.50 (2013-10-04)
-------------------
1.9.49 (2013-09-16)
-------------------
1.9.48 (2013-08-21)
-------------------
* fix access to array fields by index (regression of `#242 <https://github.com/ros/ros_comm/issues/242>`_ in 1.9.47)
1.9.47 (2013-07-03)
-------------------
* fix 'rostopic echo' for submessages of type uint8[] (`#242 <https://github.com/ros/ros_comm/issues/242>`_)
* check for CATKIN_ENABLE_TESTING to enable configure without tests
1.9.46 (2013-06-18)
-------------------
1.9.45 (2013-06-06)
-------------------
1.9.44 (2013-03-21)
-------------------
1.9.43 (2013-03-13)
-------------------
1.9.42 (2013-03-08)
-------------------
* fix missing run_depend on rosbag (`#179 <https://github.com/ros/ros_comm/issues/179>`_)
1.9.41 (2013-01-24)
-------------------
1.9.40 (2013-01-13)
-------------------
* add support for boolean in 'rostopic -p' (`#3948 <https://code.ros.org/trac/ros/ticket/3948>`_)
1.9.39 (2012-12-29)
-------------------
* first public release for Groovy

View File

@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 2.8.3)
project(rostopic)
find_package(catkin REQUIRED)
catkin_package()
catkin_python_setup()
catkin_install_python(PROGRAMS scripts/rostopic
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
if(CATKIN_ENABLE_TESTING)
find_package(rostest)
add_rostest(test/rostopic.test)
#add_rostest(test/rostopic2.test)
catkin_add_nosetests(test/test_rostopic_command_line_offline.py)
endif()

View File

@@ -0,0 +1,7 @@
[epydoc]
name: rostopic
modules: rostopic
inheritance: included
url: http://ros.org/wiki/rostopic
frames: no
private: no

View File

@@ -0,0 +1,33 @@
<package>
<name>rostopic</name>
<version>1.12.14</version>
<description>
rostopic contains the rostopic command-line tool for displaying
debug information about
ROS <a href="http://www.ros.org/wiki/Topics">Topics</a>, including
publishers, subscribers, publishing rate,
and ROS <a href="http://www.ros.org/wiki/Messages">Messages</a>. It also
contains an experimental Python library for getting information about
and interacting with topics dynamically. This library is for
internal-use only as the code API may change, though it does provide
examples of how to implement dynamic subscription and publication
behaviors in ROS.
</description>
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
<license>BSD</license>
<url>http://ros.org/wiki/rostopic</url>
<author>Ken Conley</author>
<buildtool_depend version_gte="0.5.78">catkin</buildtool_depend>
<build_depend>rostest</build_depend>
<run_depend version_gte="0.5.4">genpy</run_depend>
<run_depend>rosbag</run_depend>
<run_depend>rospy</run_depend>
<export>
<rosdoc config="rosdoc.yaml"/>
</export>
</package>

View File

@@ -0,0 +1,2 @@
- builder: epydoc
config: epydoc.config

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import rostopic
rostopic.rostopicmain()

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup(
packages=['rostopic'],
package_dir={'': 'src'},
scripts=['scripts/rostopic'],
requires=['genmsg', 'genpy', 'roslib', 'rospkg']
)
setup(**d)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,178 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2009, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import signal
import sys
import time
import unittest
import rospy
import rostest
import std_msgs.msg
from subprocess import Popen, PIPE, check_call, call
def run_for(cmd, secs):
popen = Popen(cmd, stdout=PIPE, stderr=PIPE, close_fds=True)
timeout_t = time.time() + secs
while time.time() < timeout_t:
time.sleep(0.1)
os.kill(popen.pid, signal.SIGKILL)
class TestRostopicOnline(unittest.TestCase):
def setUp(self):
self.vals = set()
self.msgs = {}
def callback(self, msg, val):
self.vals.add(val)
self.msgs[val] = msg
def test_rostopic(self):
topics = ['/chatter', '/foo/chatter', '/bar/chatter']
# wait for network to initialize
rospy.init_node('test')
for i, t in enumerate(topics):
rospy.Subscriber(t, std_msgs.msg.String, self.callback, i)
all = set(range(0, len(topics)))
timeout_t = time.time() + 10.
while time.time() < timeout_t and self.vals != all:
time.sleep(0.1)
# network is initialized
cmd = 'rostopic'
names = ['/chatter', 'foo/chatter']
# list
# - we aren't matching against the core services as those can make the test suites brittle
output = Popen([cmd, 'list'], stdout=PIPE).communicate()[0]
output = output.decode()
l = set(output.split())
for t in topics:
self.assert_(t in l)
for name in names:
# type
output = Popen([cmd, 'type', name], stdout=PIPE).communicate()[0]
output = output.decode()
self.assertEquals('std_msgs/String', output.strip())
# check type of topic field
output = Popen([cmd, 'type', name + '/data'], stdout=PIPE).communicate()[0]
output = output.decode()
self.assertEquals('std_msgs/String data string', output.strip())
# find
output = Popen([cmd, 'find', 'std_msgs/String'], stdout=PIPE).communicate()[0]
output = output.decode()
values = [n.strip() for n in output.split('\n') if n.strip()]
self.assertEquals(set(values), set(topics))
#echo
# test with -c option to get command to terminate
count = 3
output = Popen([cmd, 'echo', name, '-n', str(count)], stdout=PIPE).communicate()[0]
output = output.decode()
values = [n.strip() for n in output.split('\n') if n.strip()]
values = [n for n in values if n != '---']
self.assertEquals(count, len(values), "wrong number of echos in output:\n"+str(values))
for n in values:
self.assert_('data: "hello world ' in n, n)
if 0:
#bw
stdout, stderr = run_for([cmd, 'bw', name], 3.)
self.assert_('average:' in stdout, "OUTPUT: %s\n%s"%(stdout,stderr))
# hz
stdout, stderr = run_for([cmd, 'hz', name], 2.)
self.assert_('average rate:' in stdout)
# delay
stdout, stderr = run_for([cmd, 'delay', name], 2.)
self.assert_('average rate:' in stdout)
# pub
# - pub wait until ctrl-C, so we have to wait then kill it
if 1:
s = 'hello'
t = '/pub/chatter'
key = len(topics)
rospy.Subscriber(t, std_msgs.msg.String, self.callback, key)
#TODO: correct popen call
args = [cmd, 'pub', t, 'std_msgs/String', s]
popen = Popen(args, stdout=PIPE, stderr=PIPE, close_fds=True)
# - give rostopic pub 5 seconds to send us a message
all = set(range(0, key+1))
timeout_t = time.time() + 5.
while time.time() < timeout_t and self.vals != all:
time.sleep(0.1)
# - check published value
msg = self.msgs[key]
self.assertEquals(s, msg.data)
os.kill(popen.pid, signal.SIGKILL)
# test with dictionary
t = '/pub2/chatter'
key = len(topics)+1
rospy.Subscriber(t, std_msgs.msg.String, self.callback, key)
args = [cmd, 'pub', t, 'std_msgs/String', "{data: %s}"%s]
popen = Popen(args, stdout=PIPE, stderr=PIPE, close_fds=True)
# - give rostopic pub 5 seconds to send us a message
all = set(range(0, key+2))
timeout_t = time.time() + 5.
while time.time() < timeout_t and self.vals != all:
time.sleep(0.1)
# - check published value
try:
msg = self.msgs[key]
except KeyError:
self.fail("no message received on "+str(key))
self.assertEquals(s, msg.data)
os.kill(popen.pid, signal.SIGKILL)
PKG = 'test_rostopic'
NAME = 'test_rostopic_command_line_online'
if __name__ == '__main__':
rostest.run(PKG, NAME, TestRostopicOnline, sys.argv)

View File

@@ -0,0 +1,10 @@
<launch>
<node name="talker" pkg="rospy" type="talker.py" />
<group ns="foo">
<node name="talker" pkg="rospy" type="talker.py" />
</group>
<group ns="bar">
<node name="talker" pkg="rospy" type="talker.py" />
</group>
<test test-name="rostopic_command_line_online" pkg="rostopic" type="check_rostopic_command_line_online.py" />
</launch>

View File

@@ -0,0 +1,10 @@
<launch>
<node name="talker" pkg="rospy" type="talker.py" />
<group ns="foo">
<node name="talker" pkg="rospy" type="talker.py" />
</group>
<group ns="bar">
<node name="talker" pkg="rospy" type="talker.py" />
</group>
<test test-name="rostopic_unit" pkg="rostopic" type="test_rostopic.py" />
</launch>

View File

@@ -0,0 +1,355 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2009, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import unittest
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import time
import rostest
import rospy
import std_msgs.msg
from subprocess import Popen, PIPE, check_call, call
from contextlib import contextmanager
@contextmanager
def fakestdout():
realstdout = sys.stdout
fakestdout = StringIO()
sys.stdout = fakestdout
yield fakestdout
sys.stdout = realstdout
def todict(s):
d = {}
for l in s.split('\n'):
key, p, val = l.partition(':')
if p:
d[key] = val.strip()
return d
class TestRostopic(unittest.TestCase):
def __init__(self, *args):
unittest.TestCase.__init__(self, *args)
self.vals = set()
# wait for network to initialize
rospy.init_node('test')
topics = ['/chatter', '/foo/chatter', '/bar/chatter']
subs = [rospy.Subscriber(t, std_msgs.msg.String, self.callback, i) for i, t in enumerate(topics)]
all = set(range(0, len(topics)))
timeout_t = time.time() + 10.
while time.time() < timeout_t and self.vals != all and not rospy.is_shutdown():
time.sleep(0.1)
[s.unregister() for s in subs]
if rospy.is_shutdown():
self.fail("shutdown")
def test_offline(self):
import rostopic
orig_uri = os.environ['ROS_MASTER_URI']
os.environ['ROS_MASTER_URI'] = 'http://fake_host:12356'
try:
c = 'rostopic'
try:
rostopic._rostopic_cmd_list([c, 'list'])
self.fail("should have raised ROSTopicIOException")
except rostopic.ROSTopicIOException: pass
try:
rostopic._rostopic_cmd_info([c, 'info', '/chatter'])
self.fail("should have raised ROSTopicIOException")
except rostopic.ROSTopicIOException: pass
try:
rostopic._rostopic_cmd_type([c, 'type', '/chatter'])
self.fail("should have raised ROSTopicIOException")
except rostopic.ROSTopicIOException: pass
try:
rostopic._rostopic_cmd_find([c, 'find', 'std_msgs/String'])
self.fail("should have raised ROSTopicIOException")
except rostopic.ROSTopicIOException: pass
finally:
os.environ['ROS_MASTER_URI'] = orig_uri
def test_cmd_type(self):
import rostopic
cmd = 'rostopic'
s = '/rosout_agg'
t = 'rosgraph_msgs/Log'
try:
rostopic.rostopicmain([cmd, 'type', 'fake'])
self.fail("should have exited")
except SystemExit as e:
self.assertNotEquals(0, e.code)
for s in ['/chatter', 'chatter', 'foo/chatter', '/bar/chatter']:
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'type', s])
v = b.getvalue().strip()
self.assertEquals('std_msgs/String', v)
# check type of topic field
rostopic.rostopicmain([cmd, 'type', s + '/data'])
v = b.getvalue().strip()
self.assertEquals('std_msgs/String data string', v)
def test_main(self):
import rostopic
c = 'rostopic'
try:
rostopic.rostopicmain([c])
self.fail("should have exited with error")
except SystemExit as e:
self.assertNotEquals(0, e.code)
try:
rostopic.rostopicmain([c, 'foo'])
self.fail("should have exited with error")
except SystemExit as e:
self.assertNotEquals(0, e.code)
def test_cmd_pub(self):
import rostopic
cmd = 'rostopic'
# we can't actually test functional behavior because rostopic
# needs control over a node, though we can probably change the
# source code to just check for the existing node.
invalid = [['-r', '--once', '/foo', 'std_msgs/String', 'hello'],
['-r', 'a', '/foo', 'std_msgs/String', 'hello'],
['-r', '--', '-1', '/foo', 'std_msgs/String', 'hello'],
[],
['/foo'],
['/foo', 'std_msgs/String', 'a: b: !!c: d: e'],
]
for i in invalid:
try:
rostopic.rostopicmain([cmd, 'pub'] + i)
self.fail("should have exited with error"+str(i))
except SystemExit as e:
self.assert_(e.code != 0)
def test_full_usage(self):
import rostopic
try:
rostopic._fullusage()
self.fail("should have caused system exit")
except SystemExit: pass
def test_get_topic_type(self):
import rostopic
self.assertEquals((None, None, None), rostopic.get_topic_type('/fake', blocking=False))
t, n, f = rostopic.get_topic_type('/rosout', blocking=False)
self.assertEquals('rosgraph_msgs/Log', t)
self.assertEquals('/rosout', n)
self.assert_(f is None)
t, n, f = rostopic.get_topic_type('/rosout/name', blocking=False)
self.assertEquals('rosgraph_msgs/Log', t)
self.assertEquals('/rosout', n)
self.failIf(f is None)
from rosgraph_msgs.msg import Log
self.assertEquals("bob", f(Log(name="bob")))
def test_get_topic_class(self):
import rostopic
self.assertEquals((None, None, None), rostopic.get_topic_class('/fake'))
from rosgraph_msgs.msg import Log
c, n, f = rostopic.get_topic_class('/rosout')
self.assertEquals(Log, c)
self.assertEquals('/rosout', n)
self.assert_(f is None)
c, n, f = rostopic.get_topic_class('/rosout/name')
self.assertEquals(c, Log)
self.assertEquals('/rosout', n)
self.failIf(f is None)
self.assertEquals("bob", f(Log(name="bob")))
def test_cmd_info(self):
import rostopic
cmd = 'rostopic'
try:
rostopic.rostopicmain([cmd, 'info'])
self.fail("should have exited with error")
except SystemExit: pass
try:
rostopic.rostopicmain([cmd, 'info', '/fake_topic'])
self.fail("should have exited with error")
except SystemExit: pass
try:
rostopic.rostopicmain([cmd, 'info', '/chatter', '/bar/chatter'])
self.fail("should have exited with error")
except SystemExit: pass
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'info', 'rosout'])
v = b.getvalue()
for s in ["Publishers:", "Subscribers", "Type: rosgraph_msgs/Log", " * /rosout"]:
self.assert_(s in v, "failed on %s: %s"%(s, v))
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'info', '/chatter'])
v = b.getvalue()
for s in ["Publishers:", "Subscribers", "Type: std_msgs/String", " * /talker"]:
self.assert_(s in v, "failed on %s: %s"%(s, v))
def test_cmd_find(self):
import rostopic
cmd = 'rostopic'
try:
rostopic.rostopicmain([cmd, 'find'])
self.fail("arg parsing should have failed")
except SystemExit: pass
try:
rostopic.rostopicmain([cmd, 'find', 'std_msgs/String', 'std_msgs/Int32'])
self.fail("arg parsing should have failed")
except SystemExit: pass
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'find', 'std_msgs/String'])
d = [x for x in b.getvalue().split('\n') if x.strip()]
v = ['/foo/chatter', '/bar/chatter', '/chatter']
self.assertEquals(set(v), set(d))
def callback(self, msg, val):
self.vals.add(val)
def test_cmd_list(self):
import rostopic
cmd = 'rostopic'
s = '/add_two_ints'
# test failures
for invalid in [['-ps'], ['-b' 'file.bag', '-s'], ['-b' 'file.bag', '-p']]:
try:
rostopic.rostopicmain([cmd, 'list'] + invalid)
self.fail("should have failed")
except SystemExit: pass
# test main entry
rostopic.rostopicmain([cmd, 'list'])
# test directly
topics = ['/chatter', '/foo/chatter', '/bar/chatter', '/rosout', '/rosout_agg']
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list'])
v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
self.failIf(set(topics)-set(v))
# publishers-only
topics = ['/chatter', '/foo/chatter', '/bar/chatter', '/rosout', '/rosout_agg']
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', '-p'])
v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
self.failIf(set(topics)-set(v))
self.failIf('/clock' in v)
# subscribers-only
topics = ['/rosout']
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', '-s'])
v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
self.failIf(set(topics)-set(v), "%s vs. %s"%(topics, v))
self.failIf('/chatter' in v)
# turn on verbosity, not checking output as it's not as stable
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', '-v'])
v = b.getvalue()
self.assert_("Published topics:" in v)
self.assert_("Subscribed topics:" in v)
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', '-vs'])
v = b.getvalue()
self.failIf("Published topics:" in v)
self.assert_("Subscribed topics:" in v)
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', '-vp'])
v = b.getvalue()
self.assert_("Published topics:" in v)
self.failIf("Subscribed topics:" in v)
# test with multiple topic names
try:
rostopic.rostopicmain([cmd, 'list', 'rosout', 'rosout_agg'])
self.fail("should have caused parser error")
except SystemExit:
pass
# test with resolved names
for n in topics:
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', n])
self.assertEquals(n, b.getvalue().strip())
# test with relative names
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', 'rosout'])
self.assertEquals('/rosout', b.getvalue().strip())
# test with namespaces
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', '/foo'])
self.assertEquals('/foo/chatter', b.getvalue().strip())
with fakestdout() as b:
rostopic.rostopicmain([cmd, 'list', 'bar'])
self.assertEquals('/bar/chatter', b.getvalue().strip())
NAME = 'test_rostopic'
if __name__ == '__main__':
rostest.unitrun('test_rostopic', NAME, TestRostopic, sys.argv, coverage_packages=['rostopic'])

View File

@@ -0,0 +1,98 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2009, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import unittest
import time
from subprocess import Popen, PIPE, check_call, call
class TestRostopicOffline(unittest.TestCase):
def setUp(self):
pass
## test that the rosmsg command works
def test_cmd_help(self):
cmd = 'rostopic'
sub = ['bw', 'echo', 'hz', 'delay', 'info', 'list', 'pub', 'type','find']
output = Popen([cmd], stdout=PIPE).communicate()[0]
self.assert_('Commands' in output)
output = Popen([cmd, '-h'], stdout=PIPE).communicate()[0]
self.assert_('Commands' in output)
# make sure all the commands are in the usage
for c in sub:
cmd_sub = "%s %s"%(cmd, c)
self.assert_(cmd_sub in output, "'%s' is not in help: \n%s"%(cmd_sub, output))
for c in sub:
output = Popen([cmd, c, '-h'], stdout=PIPE, stderr=PIPE).communicate()
self.assert_("usage:" in output[0].lower(), output)
# make sure usage refers to the command
self.assert_("%s %s"%(cmd, c) in output[0], output)
# test no args on commands that require args
for c in ['bw', 'echo', 'hz', 'delay', 'info', 'pub', 'type', 'find']:
output = Popen([cmd, c], stdout=PIPE, stderr=PIPE).communicate()
self.assert_("usage:" in output[0].lower() or "usage:" in output[1].lower(), output)
# make sure usage refers to the command
self.assert_("%s %s"%(cmd, c) in output[1], output)
def test_offline(self):
cmd = 'rostopic'
# point at a different 'master'
env = os.environ.copy()
env['ROS_MASTER_URI'] = 'http://localhost:11312'
kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}
msg = "ERROR: Unable to communicate with master!\n"
output = Popen([cmd, 'bw', 'chatter'], **kwds).communicate()
self.assert_(output[1].endswith(msg))
output = Popen([cmd, 'echo', 'chatter'], **kwds).communicate()
self.assert_(output[1].endswith(msg))
output = Popen([cmd, 'hz', 'chatter'], **kwds).communicate()
self.assert_(output[1].endswith(msg))
output = Popen([cmd, 'delay', 'chatter'], **kwds).communicate()
self.assert_(output[1].endswith(msg))
output = Popen([cmd, 'list'], **kwds).communicate()
self.assert_(output[1].endswith(msg))
output = Popen([cmd, 'pub', 'chatter', 'std_msgs/String', 'hello'], **kwds).communicate()
self.assert_(output[1].endswith(msg))
output = Popen([cmd, 'type', 'chatter'], **kwds).communicate()
self.assert_(output[1].endswith(msg))
output = Popen([cmd, 'type', 'std_msgs/String'], **kwds).communicate()
self.assert_(output[1].endswith(msg))