本文整理汇总了Python中xmlrpc.client.ServerProxy.getPublications方法的典型用法代码示例。如果您正苦于以下问题:Python ServerProxy.getPublications方法的具体用法?Python ServerProxy.getPublications怎么用?Python ServerProxy.getPublications使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrpc.client.ServerProxy
的用法示例。
在下文中一共展示了ServerProxy.getPublications方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unpublish
# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import getPublications [as 别名]
def test_unpublish(self):
node_proxy = ServerProxy(rospy.get_node_uri())
_, _, pubs = node_proxy.getPublications('/foo')
pubs = [p for p in pubs if p[0] != '/rosout']
self.assert_(not pubs, pubs)
print("Publishing ", PUBTOPIC)
pub = rospy.Publisher(PUBTOPIC, String)
topic = rospy.resolve_name(PUBTOPIC)
_, _, pubs = node_proxy.getPublications('/foo')
pubs = [p for p in pubs if p[0] != '/rosout']
self.assertEquals([[topic, String._type]], pubs, "Pubs were %s"%pubs)
# publish about 10 messages for fun
for i in range(0, 10):
pub.publish(String("hi [%s]"%i))
time.sleep(0.1)
# begin actual test by unsubscribing
pub.unregister()
# make sure no new messages are received in the next 2 seconds
timeout_t = time.time() + 2.0
while timeout_t < time.time():
time.sleep(1.0)
self.assert_(_last_callback is None)
# verify that close cleaned up master and node state
_, _, pubs = node_proxy.getPublications('/foo')
pubs = [p for p in pubs if p[0] != '/rosout']
self.assert_(not pubs, "Node still has pubs: %s"%pubs)
n = rospy.get_caller_id()
self.assert_(not rostest.is_publisher(topic, n), "publication is still active on master")
示例2: check_if_still_publisher
# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import getPublications [as 别名]
def check_if_still_publisher(resolved_topic_name, pub_uri):
try:
s = ServerProxy(pub_uri)
code, msg, val = s.getPublications(rospy.names.get_name())
if code == 1:
return len([t for t in val if t[0] == resolved_topic_name]) > 0
else:
return False
except:
return False
示例3: SlaveTestCase
# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import getPublications [as 别名]
class SlaveTestCase(TestRosClient):
def setUp(self):
super(SlaveTestCase, self).setUp()
# retrieve handle on node
self.caller_id = rospy.get_caller_id()
self.node_api = self.apiSuccess(self.master.lookupNode(self.caller_id, 'test_node'))
self.assert_(self.node_api.startswith('http'))
self.node = ServerProxy(self.node_api)
def testGetPid(self):
pid = self.apiSuccess(self.node.getPid(self.caller_id))
self.assert_(pid > 0)
def testGetPublications(self):
publications = self.apiSuccess(self.node.getPublications(self.caller_id))
self.assert_(publications is not None)
expected = [rospy.resolve_name(t) for t in _required_publications]
missing = set(expected) - set(publications)
self.failIf(len(missing), 'missing required topics: %s'%(','.join(missing)))
def _subTestSourceRequestFlow(self, testName, protocols, testEval):
master = self.master
tests = [
[['testSourceRequestFlow-%s-nodeA','testSourceRequestFlow-%s-nodeB',],
['node', 'testSourceRequestFlow-%s-nodeA.out', 'testSourceRequestFlow-%s-nodeB.in']],
[['g1.testSourceRequestFlow-%s-nodeA','g1.testSourceRequestFlow-%s-nodeB',],
['g1.node', 'testSourceRequestFlow-%s-nodeA.out', 'testSourceRequestFlow-%s-nodeB.in']],
[['g1.g2.g3.testSourceRequestFlow-%s-nodeA','g1.g2.testSourceRequestFlow-%s-nodeB',],
['g1.g2.node', 'g3.testSourceRequestFlow-%s-nodeA.out', 'testSourceRequestFlow-%s-nodeB.in']],
[['g1.g2.testSourceRequestFlow-%s-nodeA','g1.g2.g3.testSourceRequestFlow-%s-nodeB',],
['g1.g2.node', 'testSourceRequestFlow-%s-nodeA.out', 'g3.testSourceRequestFlow-%s-nodeB.in']],
]
sources = {}
#start the nodes
# - save the source as we will be making calls on it
pkg, node = testNode
for test in tests:
sourceName, sinkName = [val%testName for val in test[0]]
port = apiSuccess(master.addNode('', '', sourceName, pkg, node, TEST_MACHINE, 0))
apiSuccess(master.addNode('', '', sinkName, pkg, node, TEST_MACHINE, 0))
sourceUri = 'http://%s:%s/'%(testNodeAddr[0], port)
sources[sourceName] = ServerProxy(sourceUri)
for test in tests:
sourceName, sinkName = [val%testName for val in test[0]]
source = sources[sourceName]
callerId = test[1][0]
sourceLocator, sinkLocator = [val%testName for val in test[1][1:]]
args = source.sourceRequestFlow(callerId, sourceLocator, sinkLocator, protocols)
testEval(args)
#TODO: test locator name resolution
def testSourceRequestFlow_TCPROS1(self):
def testEval(args):
protocol = apiSuccess(args)
assert type(protocol) == list
assert string.upper(protocol[0]) == 'TCPROS', "source should have returned TCPROS as the desired protocol"
assert len(protocol) == 3, "TCPROS parameter spec should be length 3"
protocols = [['TCPROS']]
self._subTestSourceRequestFlow('TCPROS1', protocols, testEval)
def testSourceRequestFlow_TCPROS2(self):
def testEval(args):
protocol = apiSuccess(args)
assert type(protocol) == list
assert string.upper(protocol[0]) == 'TCPROS', "source should have returned TCPROS as the desired protocol"
assert len(protocol) == 3, "TCPROS parameter spec should be length 3"
protocols = [['Fake1', 123, 132], ['Fake2', 1.0], ['Fake3'], ['Fake4', 'string'], ['Fake5', ['a', 'list'], ['a', 'nother', 'list']], ['TCPROS'], ['Fakelast', 'fake'] ]
self._subTestSourceRequestFlow('TCPROS2', protocols, testEval)
def testSourceRequestFlow_Fail(self):
protocols = [['Fake1', 123, 132], ['Fake2', 1.0], ['Fake3'], ['Fake4', 'string'], ['Fake5', ['a', 'list'], ['a', 'nother', 'list']], ['Fakelast', 'fake'] ]
self._subTestSourceRequestFlow('Fail', protocols, apiFail)
def testSourceRequestFlow_Errors(self):
slave = self.slave
master = self.master
#test that malformed locators return error codes
apiError(slave.sourceRequestFlow('', '', ''))
apiError(slave.sourceRequestFlow('', 'good.locator', 'badlocator'))
apiError(slave.sourceRequestFlow('', 'badlocator', 'good.locator'))
# sourceKillFlow(callerId, sourceLocator, sinkLocator)
#
# * called by master
# * returns int
def testSourceKillFlow(self):
slave = self.slave
master = self.master
#test that malformed locators return error codes
apiError(slave.sourceKillFlow('', '', ''))
apiError(slave.sourceKillFlow('', 'good.locator', 'badlocator'))
apiError(slave.sourceKillFlow('', 'badlocator', 'good.locator'))
tests = [
[['testSourceKillFlow-nodeA','testSourceKillFlow-nodeB',],
['node', 'testSourceKillFlow-nodeA.out', 'testSourceKillFlow-nodeB.in']],
[['g1.testSourceKillFlow-nodeA','g1.testSourceKillFlow-nodeB',],
#.........这里部分代码省略.........
示例4: TestSlaveApi
# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import getPublications [as 别名]
#.........这里部分代码省略.........
if msg:
assert self.last_code == -1, "%s (return msg was %s)"%(msg, self.last_msg)
else:
assert self.last_code == -1, "Call should have returned error -1 code: %s"%self.last_msg
def check_uri(self, uri):
"""
validates a URI as being http(s)
"""
import urlparse
parsed = urlparse.urlparse(uri)
self.assert_(parsed[0] in ['http', 'https'], 'protocol [%s] is [%s] invalid'%(parsed[0], uri))
self.assert_(parsed[1], 'host missing [%s]'%uri)
self.assert_(parsed.port, 'port missing/invalid [%s]'%uri)
def test_getPid(self):
"""
validate node.getPid(caller_id)
"""
# test success
pid = self.apiSuccess(self.node.getPid(self.caller_id))
self.assert_(pid > 0)
# test with bad arity: accept error or fault
try:
self.apiError(self.node.getPid())
except Fault:
pass
def test_rosout(self):
"""
make sure rosout is in publication and connection list
"""
val = self.apiSuccess(self.node.getPublications(self.caller_id))
pubs_d = TopicDescriptionList(val).as_dict()
self.assertTrue('/rosout' in pubs_d, "node is not publishing to rosout")
self.assertEquals('rosgraph_msgs/Log', pubs_d['/rosout'], "/rosout is not correct type")
def test_simtime(self):
"""
test that node obeys simtime (/Clock) contract
http://www.ros.org/wiki/Clock
"""
try:
use_sim_time = self.master.getParam('/use_sim_time')
except:
use_sim_time = False
val = self.apiSuccess(self.node.getSubscriptions(self.caller_id))
subs_d = TopicDescriptionList(val).as_dict()
if use_sim_time:
self.assertTrue('/clock' in subs_d, "node is not subscribing to clock")
self.assertEquals('rosgraph_msgs/Clock', subs_d['/clock'], "/clock is not correct type")
else:
self.assertFalse('/clock' in subs_d, "node is subscribed to /clock even though /use_sim_time is false")
def test_getPublications(self):
"""
validate node.getPublications(caller_id)
"""
# test success
pubs_value = self.apiSuccess(self.node.getPublications(self.caller_id))
pubs = TopicDescriptionList(pubs_value)
pubs_dict = pubs.as_dict()