예제 #1
0
    def test_Registrations(self):
        import rosmaster.exceptions
        from rosmaster.registrations import Registrations
        types = [Registrations.TOPIC_SUBSCRIPTIONS,
                 Registrations.TOPIC_PUBLICATIONS,
                 Registrations.SERVICE,
                 Registrations.PARAM_SUBSCRIPTIONS]
        # test enums
        self.assertEquals(4, len(set(types)))
        try:
            r = Registrations(-1)
            self.fail("Registrations accepted invalid type")
        except rosmaster.exceptions.InternalException: pass
        
        for t in types:
            r = Registrations(t)
            self.assertEquals(t, r.type)
            self.assert_(not r) #test nonzero
            self.failIf('topic1' in r) #test contains            
            self.failIf(r.has_key('topic1')) #test has_key
            self.failIf([k for k in r.iterkeys()]) #no keys
            self.assertEquals(None, r.get_service_api('non-existent'))

        # Test topic subs
        r = Registrations(Registrations.TOPIC_SUBSCRIPTIONS)
        self._subtest_Registrations_basic(r)
        r = Registrations(Registrations.TOPIC_PUBLICATIONS)        
        self._subtest_Registrations_basic(r)
        r = Registrations(Registrations.PARAM_SUBSCRIPTIONS)        
        self._subtest_Registrations_basic(r)

        r = Registrations(Registrations.SERVICE)        
        self._subtest_Registrations_services(r)
    def test_Registrations(self):
        import rosmaster.exceptions
        from rosmaster.registrations import Registrations
        types = [
            Registrations.TOPIC_SUBSCRIPTIONS,
            Registrations.TOPIC_PUBLICATIONS, Registrations.SERVICE,
            Registrations.PARAM_SUBSCRIPTIONS
        ]
        # test enums
        self.assertEquals(4, len(set(types)))
        try:
            r = Registrations(-1)
            self.fail("Registrations accepted invalid type")
        except rosmaster.exceptions.InternalException:
            pass

        for t in types:
            r = Registrations(t)
            self.assertEquals(t, r.type)
            self.assert_(not r)  #test nonzero
            self.failIf('topic1' in r)  #test contains
            self.failIf(r.has_key('topic1'))  #test has_key
            self.failIf([k for k in r.iterkeys()])  #no keys
            self.assertEquals(None, r.get_service_api('non-existent'))

        # Test topic subs
        r = Registrations(Registrations.TOPIC_SUBSCRIPTIONS)
        self._subtest_Registrations_basic(r)
        r = Registrations(Registrations.TOPIC_PUBLICATIONS)
        self._subtest_Registrations_basic(r)
        r = Registrations(Registrations.PARAM_SUBSCRIPTIONS)
        self._subtest_Registrations_basic(r)

        r = Registrations(Registrations.SERVICE)
        self._subtest_Registrations_services(r)
    def test_Registrations_unregister_all(self):
        import rosmaster.exceptions
        from rosmaster.registrations import Registrations

        r = Registrations(Registrations.TOPIC_SUBSCRIPTIONS)
        for k in ['topic1', 'topic1b', 'topic1c', 'topic1d']:
            r.register(k, 'node1', 'http://node1:5678')
        r.register('topic2', 'node2', 'http://node2:5678')
        r.unregister_all('node1')
        self.failIf(not r)
        for k in ['topic1', 'topic1b', 'topic1c', 'topic1d']:
            self.failIf(r.has_key(k))
        self.assertEquals(['topic2'], [k for k in r.iterkeys()])

        r = Registrations(Registrations.TOPIC_PUBLICATIONS)
        for k in ['topic1', 'topic1b', 'topic1c', 'topic1d']:
            r.register(k, 'node1', 'http://node1:5678')
        r.register('topic2', 'node2', 'http://node2:5678')
        r.unregister_all('node1')
        self.failIf(not r)
        for k in ['topic1', 'topic1b', 'topic1c', 'topic1d']:
            self.failIf(r.has_key(k))
        self.assertEquals(['topic2'], [k for k in r.iterkeys()])

        r = Registrations(Registrations.PARAM_SUBSCRIPTIONS)
        r.register('param2', 'node2', 'http://node2:5678')
        for k in ['param1', 'param1b', 'param1c', 'param1d']:
            r.register(k, 'node1', 'http://node1:5678')
        r.unregister_all('node1')
        self.failIf(not r)
        for k in ['param1', 'param1b', 'param1c', 'param1d']:
            self.failIf(r.has_key(k))
        self.assertEquals(['param2'], [k for k in r.iterkeys()])

        r = Registrations(Registrations.SERVICE)
        for k in ['service1', 'service1b', 'service1c', 'service1d']:
            r.register(k, 'node1', 'http://node1:5678', 'rosrpc://node1:1234')
        r.register('service2', 'node2', 'http://node2:5678',
                   'rosrpc://node2:1234')
        r.unregister_all('node1')
        self.failIf(not r)
        for k in ['service1', 'service1b', 'service1c', 'service1d']:
            self.failIf(r.has_key(k))
            self.assertEquals(None, r.get_service_api(k))
        self.assertEquals(['service2'], [k for k in r.iterkeys()])
        self.assertEquals('rosrpc://node2:1234', r.get_service_api('service2'))
예제 #4
0
    def test_Registrations_unregister_all(self):
        import rosmaster.exceptions
        from rosmaster.registrations import Registrations

        r = Registrations(Registrations.TOPIC_SUBSCRIPTIONS)        
        for k in ['topic1', 'topic1b', 'topic1c', 'topic1d']:        
            r.register(k, 'node1', 'http://node1:5678')
        r.register('topic2', 'node2', 'http://node2:5678')
        r.unregister_all('node1')
        self.failIf(not r)
        for k in ['topic1', 'topic1b', 'topic1c', 'topic1d']:        
            self.failIf(r.has_key(k))
        self.assertEquals(['topic2'], [k for k in r.iterkeys()])
        
        r = Registrations(Registrations.TOPIC_PUBLICATIONS)        
        for k in ['topic1', 'topic1b', 'topic1c', 'topic1d']:        
            r.register(k, 'node1', 'http://node1:5678')
        r.register('topic2', 'node2', 'http://node2:5678')
        r.unregister_all('node1')
        self.failIf(not r)
        for k in ['topic1', 'topic1b', 'topic1c', 'topic1d']:        
            self.failIf(r.has_key(k))
        self.assertEquals(['topic2'], [k for k in r.iterkeys()])

        r = Registrations(Registrations.PARAM_SUBSCRIPTIONS)        
        r.register('param2', 'node2', 'http://node2:5678')
        for k in ['param1', 'param1b', 'param1c', 'param1d']:
            r.register(k, 'node1', 'http://node1:5678')
        r.unregister_all('node1')
        self.failIf(not r)
        for k in ['param1', 'param1b', 'param1c', 'param1d']:
            self.failIf(r.has_key(k))
        self.assertEquals(['param2'], [k for k in r.iterkeys()])
        
        r = Registrations(Registrations.SERVICE)        
        for k in ['service1', 'service1b', 'service1c', 'service1d']:
            r.register(k, 'node1', 'http://node1:5678', 'rosrpc://node1:1234')
        r.register('service2', 'node2', 'http://node2:5678', 'rosrpc://node2:1234')
        r.unregister_all('node1')
        self.failIf(not r)
        for k in ['service1', 'service1b', 'service1c', 'service1d']:
            self.failIf(r.has_key(k))
            self.assertEquals(None, r.get_service_api(k))
        self.assertEquals(['service2'], [k for k in r.iterkeys()])
        self.assertEquals('rosrpc://node2:1234', r.get_service_api('service2'))