test_rospy_client.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 import random
40 
41 import rosunit
42 
43 import rospy
44 
45 
46 class TestRospyClient(unittest.TestCase):
47 
48  def test_init_node(self):
49  failed = True
50  try:
51  # #1822
52  rospy.init_node('ns/node')
53  except ValueError:
54  failed = False
55  self.failIf(failed, "init_node allowed '/' in name")
56 
57  failed = True
58  try:
59  rospy.init_node(name=None)
60  except ValueError:
61  failed = False
62  self.failIf(failed, "init_node allowed None as name")
63 
64  failed = True
65  try:
66  rospy.init_node("")
67  except ValueError:
68  failed = False
69  self.failIf(failed, "init_node allowed empty string as name")
70 
71  def test_spin(self):
72  failed = True
73  try:
74  rospy.spin()
75  except rospy.ROSInitException:
76  failed = False
77  self.failIf(failed, "spin() should failed if not initialized")
78 
79  def test_myargv(self):
80  orig_argv = sys.argv
81  try:
82  from rospy.client import myargv
83  args = myargv()
84  self.assertEquals(args, sys.argv)
85  self.assertEquals(['foo', 'bar', 'baz'], myargv(['foo','bar', 'baz']))
86  self.assertEquals(['-foo', 'bar', '-baz'], myargv(['-foo','bar', '-baz']))
87 
88  self.assertEquals(['foo'], myargv(['foo','bar:=baz']))
89  self.assertEquals(['foo'], myargv(['foo','-bar:=baz']))
90  finally:
91  sys.argv = orig_argv
92 
94 
95  from rospy.client import load_command_line_node_params
96 
97  assert {} == load_command_line_node_params([])
98  assert {} == load_command_line_node_params(['a', 'b', 'c'])
99  assert {} == load_command_line_node_params(['a:=b'])
100  assert {'a': 'b'} == load_command_line_node_params(['_a:=b'])
101  assert {'a': 'b', 'foo': 'bar'} == load_command_line_node_params(['_a:=b', 'blah', '_foo:=bar', 'baz'])
102  # test yaml unmarshal
103  assert {'a': 1} == load_command_line_node_params(['_a:=1'])
104  try:
105  load_command_line_node_params(['_a:=b:=c'])
106  except rospy.exceptions.ROSInitException:
107  pass
108 
109 if __name__ == '__main__':
110  rosunit.unitrun('test_rospy', sys.argv[0], TestRospyClient, coverage_packages=['rospy.client'])


test_rospy
Author(s): Ken Conley, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:56