test_rospy_api.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2008, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of Willow Garage, Inc. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 
34 import os
35 import sys
36 import struct
37 import unittest
38 import time
39 
40 # test rospy API verifies that the rospy module exports the required symbols
41 class TestRospyApi(unittest.TestCase):
42 
43  def test_msg(self):
44  # rospy.Message really only exists at the client level, as the internal
45  # implementation is built around the roslib reference, so we put the test here
46 
47  import rospy
48  #trip wires against Message API
49  m = rospy.Message()
50  try:
51  from cStringIO import StringIO
52  except ImportError:
53  from io import StringIO
54  buff = StringIO()
55  m.serialize(buff)
56  self.assertEquals(0, buff.tell())
57  m.deserialize('')
58 
59  def test_anymsg(self):
60  # rospy.AnyMsg really only exists at the client level as nothing within
61  # rospy uses its functionality.
62 
63 
64  try:
65  from cStringIO import StringIO
66  except ImportError:
67  from io import StringIO
68  import rospy
69  import rospy.exceptions
70  #trip wires against AnyMsg API
71  m = rospy.AnyMsg()
72  try:
73  m.serialize(StringIO())
74  self.fail("AnyMsg should not allow serialization")
75  except rospy.exceptions.ROSException:
76  pass
77 
78  teststr = 'foostr-%s'%time.time()
79  m.deserialize(teststr)
80  self.assertEquals(teststr, m._buff)
81 
82  #test AnyMsg ctor error checking
83  try:
84  m = rospy.AnyMsg('foo')
85  self.fail("AnyMsg ctor should not allow args")
86  except: pass
87 
88  def test_rospy_api(self):
89  import rospy
90 
91  # just a laundry list of API methods to make sure that they still exist
92 
93  # removed
94  try:
95  rospy.add_shutdown_hook
96  self.fail("add_shutdown_hookshould not longer be top-level API")
97  except AttributeError: pass
98 
99  rospy.DEBUG
100  rospy.INFO
101  rospy.WARN
102  rospy.ERROR
103  rospy.FATAL
104 
105  rospy.get_caller_id
106  rospy.get_name
107  rospy.get_master
108  rospy.get_namespace
109  rospy.get_published_topics
110  rospy.get_node_uri
111  rospy.get_ros_root
112  rospy.get_time
113  rospy.get_rostime
114  rospy.init_node
115  rospy.is_shutdown
116  rospy.logdebug
117  rospy.logerr
118  rospy.logfatal
119  rospy.loginfo
120  rospy.logout #deprecated
121  rospy.logwarn
122  rospy.logdebug_throttle
123  rospy.logerr_throttle
124  rospy.logfatal_throttle
125  rospy.loginfo_throttle
126  rospy.logwarn_throttle
127  rospy.logdebug_once
128  rospy.logerr_once
129  rospy.logfatal_once
130  rospy.loginfo_once
131  rospy.logwarn_once
132  rospy.myargv
133  rospy.on_shutdown
134  rospy.parse_rosrpc_uri
135  rospy.resolve_name
136  rospy.remap_name
137  rospy.signal_shutdown
138  rospy.sleep
139  rospy.spin
140  rospy.wait_for_message
141  rospy.wait_for_service
142 
143  rospy.delete_param
144  rospy.get_param
145  rospy.get_param_names
146  rospy.has_param
147  rospy.set_param
148  rospy.search_param
149 
150  rospy.AnyMsg
151  rospy.Duration
152  rospy.Header
153  rospy.MasterProxy
154  rospy.Message
155  rospy.Publisher
156  rospy.Rate
157  rospy.ROSException
158  rospy.ROSInternalException
159  rospy.ROSSerializationException
160  rospy.ServiceException
161  rospy.Service
162  rospy.ServiceProxy
163  rospy.SubscribeListener
164  rospy.Subscriber
165  rospy.Time
166  rospy.TransportException
167  rospy.TransportTerminated
168  rospy.TransportInitError


test_rospy
Author(s): Ken Conley
autogenerated on Sun Feb 3 2019 03:30:22