test_rosgraph_masterapi_online.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 
38 import rosgraph.masterapi
39 import rostest
40 
41 _ID = '/caller_id'
42 
43 class MasterApiOnlineTest(unittest.TestCase):
44 
45  def setUp(self):
46  self.m = rosgraph.masterapi.Master(_ID)
47 
48  def test_getPid(self):
49  val = self.m.getPid()
50  val = int(val)
51 
52  def test_getUri(self):
53  val = self.m.getUri()
54  self.assert_(val.startswith('http://'))
55 
56  def test_lookupService(self):
57  uri = 'http://localhost:897'
58  rpcuri = 'rosrpc://localhost:9812'
59  self.m.registerService('/bar/service', rpcuri, uri)
60  self.assertEquals(rpcuri, self.m.lookupService('/bar/service'))
61  try:
62  self.assertEquals(uri, self.m.lookupService('/fake/service'))
63  self.fail("should have thrown")
64  except rosgraph.masterapi.Error:
65  pass
66 
68  self.m.registerService('/bar/service', 'rosrpc://localhost:9812', 'http://localhost:893')
69 
71  self.m.registerService('/unreg_service/service', 'rosrpc://localhost:9812', 'http://localhost:893')
72  val = self.m.registerService('/unreg_service/service', 'rosrpc://localhost:9812', 'http://localhost:893')
73  self.assertEquals(1, val)
74 
76  val = self.m.registerSubscriber('/reg_sub/node', 'std_msgs/String', 'http://localhost:9812')
77  self.assertEquals([], val)
78 
80  self.m.registerSubscriber('/reg_unsub/node', 'std_msgs/String', 'http://localhost:9812')
81  val = self.m.unregisterSubscriber('/reg_unsub/node', 'http://localhost:9812')
82  self.assertEquals(1, val)
83 
85  val = self.m.registerPublisher('/reg_pub/topic', 'std_msgs/String', 'http://localhost:9812')
86 
88  uri = 'http://localhost:9812'
89  self.m.registerPublisher('/unreg_pub/fake_topic', 'std_msgs/String', uri)
90  self.m.unregisterPublisher('/unreg_pub/fake_topic', uri)
91 
92  def test_lookupNode(self):
93  # register and lookup self
94  uri = 'http://localhost:12345'
95  self.m.registerPublisher('fake_topic', 'std_msgs/String', uri)
96  self.assertEquals(uri, self.m.lookupNode(_ID))
97 
98  try:
99  self.m.lookupNode('/non/existent')
100  self.fail("should have thrown")
101  except rosgraph.masterapi.Error:
102  pass
103 
105  topics = self.m.getPublishedTopics('/')
106 
108  topic_types = self.m.getTopicTypes()
109 
111  pub, sub, srvs = self.m.getSystemState()
112 
113  def test_is_online(self):
114  self.assert_(rosgraph.masterapi.is_online())
115  self.assert_(self.m.is_online())
116 
117  def test_getParam(self):
118  try:
119  self.m.getParam('fake_param')
120  self.fail("should have failed to lookup fake parameter")
121  except rosgraph.masterapi.Error:
122  pass
123 
124  def test_hasParam(self):
125  self.failIf(self.m.hasParam('fake_param'), "should have failed to lookup fake parameter")
126  self.assert_(self.m.hasParam('/run_id'), "should have failed to lookup fake parameter")
127 
128  def test_setParam(self):
129  self.m.setParam('/foo', 1)
130 
131  def test_searchParam(self):
132  self.assertEquals("/run_id", self.m.searchParam('run_id'))
133 
135  self.assert_(type(self.m.getParamNames()) == list)
136 
137 if __name__ == '__main__':
138  rostest.rosrun('test_rosgrap', 'test_rosgraph_masterapi_online', MasterApiOnlineTest)


test_rosgraph
Author(s): Ken Conley
autogenerated on Sun Feb 3 2019 03:30:18