test_rosservice_command_line_offline.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2009, 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 unittest
37 import time
38 
39 import rostest
40 
41 from subprocess import Popen, PIPE, check_call, call
42 
43 class TestRosserviceOffline(unittest.TestCase):
44 
45  def setUp(self):
46  pass
47 
48  ## test that the usage command works
49  def test_cmd_help(self):
50  cmd = 'rosservice'
51  sub = ['args', 'info', 'list', 'call', 'type', 'uri', 'find']
52 
53  output = Popen([cmd], stdout=PIPE).communicate()[0]
54  output = output.decode()
55  self.assert_('Commands' in output)
56  output = Popen([cmd, '-h'], stdout=PIPE).communicate()[0]
57  output = output.decode()
58  self.assert_('Commands' in output)
59  # make sure all the commands are in the usage
60  for c in sub:
61  self.assert_("%s %s"%(cmd, c) in output, output)
62 
63  for c in sub:
64  output = Popen([cmd, c, '-h'], stdout=PIPE).communicate()
65  self.assert_("Usage:" in output[0].decode(), output)
66  # make sure usage refers to the command
67  self.assert_("%s %s" % (cmd, c) in output[0].decode(), output)
68 
69  def test_offline(self):
70  cmd = 'rosservice'
71 
72  # point at a different 'master'
73  env = os.environ.copy()
74  env['ROS_MASTER_URI'] = 'http://localhost:11312'
75  kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}
76 
77  msg = "ERROR: Unable to communicate with master!\n"
78 
79  output = Popen([cmd, 'list'], **kwds).communicate()
80  self.assert_(output[1].decode().endswith(msg))
81  output = Popen([cmd, 'type', 'add_two_ints'], **kwds).communicate()
82  self.assert_(output[1].decode().endswith(msg))
83  output = Popen([cmd, 'uri', 'add_two_ints'], **kwds).communicate()
84  self.assert_(output[1].decode().endswith(msg))
85  output = Popen([cmd, 'call', 'add_two_ints', '1', '2'], **kwds).communicate()
86  self.assert_(output[1].decode().endswith(msg))
87  # - wait should still fail if master is offline
88  output = Popen([cmd, 'call', '--wait', 'add_two_ints', '1', '2'], **kwds).communicate()
89  self.assert_(output[1].decode().endswith(msg))
90  output = Popen([cmd, 'find', 'test_ros/AddTwoInts'], **kwds).communicate()
91  self.assert_(output[1].decode().endswith(msg))
92 
93 if __name__ == '__main__':
94  rostest.unitrun('test_rosservice', NAME, TestRosserviceOffline, sys.argv, coverage_packages=[])


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