def test_param_values(self):
        import math
        from rosmaster.paramserver import ParamDictionary
        param_server = ParamDictionary(None)
        test_vals = [
            ['int', [0, 1024, 2147483647, -2147483647]],
            ['boolean', [True, False]],
            #no longer testing null char
            #['string', ['', '\0', 'x', 'hello', ''.join([chr(n) for n in xrange(0, 255)])]],
            ['unicode-string', [u'', u'hello', unicode('Andr\302\202', 'utf-8'), unicode('\377\376A\000n\000d\000r\000\202\000', 'utf-16')]],
            ['string-easy-ascii', [chr(n) for n in xrange(32, 128)]],

            #['string-mean-ascii-low', [chr(n) for n in xrange(9, 10)]], #separate for easier book-keeping
            #['string-mean-ascii-low', [chr(n) for n in xrange(1, 31)]], #separate for easier book-keeping
            #['string-mean-signed', [chr(n) for n in xrange(129, 256)]],
            ['string', ['', 'x', 'hello-there', 'new\nline', 'tab\t']],
            ['double', [0.0, math.pi, -math.pi, 3.4028235e+38, -3.4028235e+38]],
            #TODO: microseconds?
            ['datetime', [datetime.datetime(2005, 12, 6, 12, 13, 14), datetime.datetime(1492, 12, 6, 12, 13, 14)]],
            ['array', [[], [1, 2, 3], ['a', 'b', 'c'], [0.0, 0.1, 0.2, 2.0, 2.1, -4.0],
                       [1, 'a', True], [[1, 2, 3], ['a', 'b', 'c'], [1.0, 2.1, 3.2]]]
             ],
            ]

        print "Putting parameters onto the server"
        # put our params into the parameter server
        contexts = ['', 'scope1', 'scope/subscope1', 'scope/sub1/sub2']
        my_state = {}
        failures = []
        for ctx in contexts:
            self._set_param(ctx, my_state, test_vals, param_server)
        self._check_param_state(param_server, my_state)
        
        print "Deleting all of our parameters"
        # delete all of our parameters
        param_keys = my_state.keys()
        count = 0
        for key in param_keys:
            count += 1
            param_server.delete_param(key)
            del my_state[key]
            # far too intensive to check every time
            if count % 50 == 0:
                self._check_param_state(param_server, my_state)
        self._check_param_state(param_server, my_state)
Exemplo n.º 2
0
    def test_delete_param(self):
        from rosmaster.paramserver import ParamDictionary
        param_server = ParamDictionary(None)
        try:
            param_server.delete_param('/fake')
            self.fail("delete_param of non-existent should have failed")
        except: pass
        try:
            param_server.delete_param('/')
            self.fail("delete_param of root should have failed")
        except: pass

        param_server.set_param('/foo', 'foo')
        param_server.set_param('/bar', 'bar')        
        self.assert_(param_server.has_param('/foo'))
        self.assert_(param_server.has_param('/bar'))        
        param_server.delete_param('/foo')
        self.failIf(param_server.has_param('/foo'))
        # - test with trailing slash
        param_server.delete_param('/bar/')
        self.failIf(param_server.has_param('/bar'))

        # test with namespaces
        param_server.set_param("/sub/key/x", 1)
        param_server.set_param("/sub/key/y", 2)
        try:
            param_server.delete_param('/sub/key/z')
            self.fail("delete_param of non-existent should have failed")
        except: pass
        try:
            param_server.delete_param('/sub/sub2/z')
            self.fail("delete_param of non-existent should have failed")
        except: pass

        self.assert_(param_server.has_param('/sub/key/x'))
        self.assert_(param_server.has_param('/sub/key/y'))
        self.assert_(param_server.has_param('/sub/key'))                  
        param_server.delete_param('/sub/key')
        self.failIf(param_server.has_param('/sub/key'))      
        self.failIf(param_server.has_param('/sub/key/x'))
        self.failIf(param_server.has_param('/sub/key/y'))

        # test with namespaces (dictionary vals)
        param_server.set_param('/sub2', {'key': { 'x' : 1, 'y' : 2}})
        self.assert_(param_server.has_param('/sub2/key/x'))
        self.assert_(param_server.has_param('/sub2/key/y'))
        self.assert_(param_server.has_param('/sub2/key'))                  
        param_server.delete_param('/sub2/key')
        self.failIf(param_server.has_param('/sub2/key'))      
        self.failIf(param_server.has_param('/sub2/key/x'))
        self.failIf(param_server.has_param('/sub2/key/y'))

        # test with namespaces: treat value as if its a namespace
        # - try to get the dictionary-of-dictionary code to fail
        #   by descending a value key as if it is a namespace
        param_server.set_param('/a', 'b')
        self.assert_(param_server.has_param('/a'))
        try:
            param_server.delete_param('/a/b/c')
            self.fail_("should have raised key error")
        except: pass
Exemplo n.º 3
0
    def test_subscribe_param_deletion(self):
        from rosmaster.registrations import RegistrationManager
        from rosmaster.paramserver import ParamDictionary

        # setup node and subscriber data
        reg_manager = RegistrationManager(ThreadPoolMock())
        param_server = ParamDictionary(reg_manager)

        # subscription to then delete parameter
        self.assertEquals({}, param_server.subscribe_param('/foo', ('node1', 'http://node1:1')))
        param_server.set_param('/foo', 1, notify_task=self.notify_task)
        param_server.delete_param('/foo', notify_task=self.notify_task)
        self.assertEquals([([('node1', 'http://node1:1')], '/foo/', {}), ], self.last_update)
        
        # subscribe to and delete whole tree
        gains = {'p': 'P', 'i': 'I', 'd' : 'D'}
        self.assertEquals({}, param_server.subscribe_param('/gains', ('deltree', 'http://deltree:1')))
        param_server.set_param('/gains', gains.copy(), notify_task=self.notify_task)
        param_server.delete_param('/gains', notify_task=self.notify_task)
        self.assertEquals([([('deltree', 'http://deltree:1')], '/gains/', {}), ], self.last_update)

        # subscribe to and delete params within subtree
        self.assertEquals({}, param_server.subscribe_param('/gains2', ('deltree2', 'http://deltree2:2')))
        param_server.set_param('/gains2', gains.copy(), notify_task=self.notify_task)
        param_server.delete_param('/gains2/p', notify_task=self.notify_task)
        self.assertEquals([([('deltree2', 'http://deltree2:2')], '/gains2/p/', {}), ], self.last_update)
        param_server.delete_param('/gains2/i', notify_task=self.notify_task)
        self.assertEquals([([('deltree2', 'http://deltree2:2')], '/gains2/i/', {}), ], self.last_update)        
        param_server.delete_param('/gains2', notify_task=self.notify_task)
        self.assertEquals([([('deltree2', 'http://deltree2:2')], '/gains2/', {}), ], self.last_update)
        
        # delete parent tree
        k = '/ns1/ns2/ns3/key'
        self.assertEquals({}, param_server.subscribe_param(k, ('del_parent', 'http://del_parent:1')))
        param_server.set_param(k, 1, notify_task=self.notify_task)
        param_server.delete_param('/ns1/ns2', notify_task=self.notify_task)
        self.assertEquals([([('del_parent', 'http://del_parent:1')], '/ns1/ns2/ns3/key/', {}), ], self.last_update)
Exemplo n.º 4
0
    def test_subscribe_param_tree(self):
        from rosmaster.registrations import RegistrationManager
        from rosmaster.paramserver import ParamDictionary

        # setup node and subscriber data
        reg_manager = RegistrationManager(ThreadPoolMock())
        param_server = ParamDictionary(reg_manager)

        # Test Parameter Tree Subscriptions

        # simple case - subscribe and set whole tree
        gains = {'p': 'P', 'i': 'I', 'd' : 'D'}
        self.assertEquals({}, param_server.subscribe_param('/gains', ('ptnode', 'http://ptnode:1')))
        param_server.set_param('/gains', gains.copy(), notify_task=self.notify_task)
        self.assertEquals([([('ptnode', 'http://ptnode:1')], '/gains/', gains), ], self.last_update)
        # - test with trailing slash
        param_server.set_param('/gains/', gains.copy(), notify_task=self.notify_task)
        self.assertEquals([([('ptnode', 'http://ptnode:1')], '/gains/', gains), ], self.last_update)

        # change params within tree
        param_server.set_param('/gains/p', 'P2', notify_task=self.notify_task)
        self.assertEquals([([('ptnode', 'http://ptnode:1')], '/gains/p/', 'P2'), ], self.last_update)
        param_server.set_param('/gains/i', 'I2', notify_task=self.notify_task)
        self.assertEquals([([('ptnode', 'http://ptnode:1')], '/gains/i/', 'I2'), ], self.last_update)

        # test overlapping subscriptions
        self.assertEquals('P2', param_server.subscribe_param('/gains/p', ('ptnode2', 'http://ptnode2:2')))
        param_server.set_param('/gains', gains.copy(), notify_task=self.notify_task)
        self.assertEquals([([('ptnode', 'http://ptnode:1')], '/gains/', gains), \
                           ([('ptnode2', 'http://ptnode2:2')], '/gains/p/', 'P'), \
                           ], self.last_update)
        # - retest with trailing slash on subscribe
        self.last_update = None
        self.assertEquals('P', param_server.subscribe_param('/gains/p/', ('ptnode2', 'http://ptnode2:2')))
        param_server.set_param('/gains', gains.copy(), notify_task=self.notify_task)
        self.assertEquals([([('ptnode', 'http://ptnode:1')], '/gains/', gains), \
                           ([('ptnode2', 'http://ptnode2:2')], '/gains/p/', 'P'), \
                           ], self.last_update)
        # test with overlapping (change to sub param)
        param_server.set_param('/gains/p', 'P3', notify_task=self.notify_task)
        # - this is a bit overtuned as a more optimal ps could use one update
        ptnode2 = ([('ptnode2', 'http://ptnode2:2')], '/gains/p/', 'P3')
        ptnode = ([('ptnode', 'http://ptnode:1')], '/gains/p/', 'P3')
        self.assertTrue(len(self.last_update) == 2)
        self.assertTrue(ptnode2 in self.last_update)
        self.assertTrue(ptnode in self.last_update)

        # virtual deletion: subscribe to subparam, parameter tree reset
        self.last_update = None
        param_server.set_param('/gains2', gains.copy(), notify_task=self.notify_task)
        self.assertEquals('P', param_server.subscribe_param('/gains2/p/', ('ptnode3', 'http://ptnode3:3')))
        # - erase the sub parameters
        param_server.set_param('/gains2', {}, notify_task=self.notify_task)        
        self.assertEquals([([('ptnode3', 'http://ptnode3:3')], '/gains2/p/', {}), ], self.last_update)        

        #Final test: test subscription to entire tree
        self.last_update = None
        param_server.delete_param('/gains')
        param_server.delete_param('/gains2')        
        self.assertEquals({}, param_server.get_param('/'))
        self.assertEquals({}, param_server.subscribe_param('/', ('allnode', 'http://allnode:1')))
        param_server.set_param('/one', 1, notify_task=self.notify_task)
        self.assertEquals([([('allnode', 'http://allnode:1')], '/one/', 1), ], self.last_update)
        param_server.set_param('/two', 2, notify_task=self.notify_task)
        self.assertEquals([([('allnode', 'http://allnode:1')], '/two/', 2), ], self.last_update)
        param_server.set_param('/foo/bar', 'bar', notify_task=self.notify_task)
        self.assertEquals([([('allnode', 'http://allnode:1')], '/foo/bar/', 'bar'), ], self.last_update)