Ejemplo n.º 1
0
    def test_rosparam_list(self):
        from ros import rosparam
        cmd = 'rosparam'

        params = ['/string', '/int', '/float',
                  '/g1/string', '/g1/int', '/g1/float',
                  '/g2/string', '/g2/int', '/g2/float',
                  ]
        l = rosparam.list_params('')
        for t in params:
            self.assert_(t in l)

        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list'])
            self._check(params, tolist(b))
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/'])
            self._check(params, tolist(b))
            
        # test with namespace
        g1p = [p for p in params if p.startswith('/g1/')]
        not_g1p = [p for p in params if not p.startswith('/g1/')]
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/g1'])
            self._check(g1p, tolist(b))
            self._notcheck(not_g1p, tolist(b))            
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/g1/'])
            self._check(g1p, tolist(b))
            self._notcheck(not_g1p, tolist(b))
        # test with no match        
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/not/a/namespace/'])
            self.assertEquals([], tolist(b))
Ejemplo n.º 2
0
 def test_rosparam_get(self):
     from ros import rosparam
     cmd = 'rosparam'
     try:
         rosparam.yamlmain([cmd, 'get'])
         self.fail("command-line arg should have failed")
     except SystemExit, e:
         self.assertNotEquals(0, e.code)
Ejemplo n.º 3
0
 def test_rosparam_get(self):
     from ros import rosparam
     cmd = 'rosparam'
     try:
         rosparam.yamlmain([cmd, 'get'])
         self.fail("command-line arg should have failed")
     except SystemExit, e:
         self.assertNotEquals(0, e.code)
Ejemplo n.º 4
0
    def test_rosparam_delete(self):
        from ros import rosparam
        cmd = 'rosparam'
        ps = get_param_server()

        try:
            rosparam.yamlmain([cmd, 'delete'])
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
Ejemplo n.º 5
0
    def test_rosparam_delete(self):
        from ros import rosparam
        cmd = 'rosparam'
        ps = get_param_server()

        try:
            rosparam.yamlmain([cmd, 'delete'])
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
Ejemplo n.º 6
0
 def test_fullusage(self):
     from ros import rosparam
     try:
         rosparam._fullusage()
     except SystemExit: pass
     try:
         rosparam.yamlmain(['rosparam'])
     except SystemExit: pass
     try:
         rosparam.yamlmain(['rosparam', 'invalid'])        
     except SystemExit: pass
Ejemplo n.º 7
0
 def test_rosparam_load(self):
     from ros import rosparam
     import roslib.packages
     f = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'), 'test', 'test.yaml')
     f_ns = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'), 'test', 'test_ns.yaml')
     
     cmd = 'rosparam'
     try:
         rosparam.yamlmain([cmd, 'load'])
         self.fail("command-line arg should have failed")
     except SystemExit, e:
         self.assertNotEquals(0, e.code)
Ejemplo n.º 8
0
    def test_rosparam_dump(self):
        from ros import rosparam
        import roslib.packages
        f = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'), 'test', 'test.yaml')
        f_out = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'), 'test', 'test_dump.yaml')
        
        cmd = 'rosparam'
        ps = get_param_server()

        try:
            rosparam.yamlmain([cmd, 'dump'])
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
Ejemplo n.º 9
0
 def test_fullusage(self):
     from ros import rosparam
     try:
         rosparam._fullusage()
     except SystemExit:
         pass
     try:
         rosparam.yamlmain(['rosparam'])
     except SystemExit:
         pass
     try:
         rosparam.yamlmain(['rosparam', 'invalid'])
     except SystemExit:
         pass
Ejemplo n.º 10
0
    def test_rosparam_load(self):
        from ros import rosparam
        import roslib.packages
        f = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'), 'test',
                         'test.yaml')
        f_ns = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'),
                            'test', 'test_ns.yaml')

        cmd = 'rosparam'
        try:
            rosparam.yamlmain([cmd, 'load'])
            self.fail("command-line arg should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
Ejemplo n.º 11
0
    def test_rosparam_dump(self):
        from ros import rosparam
        import roslib.packages
        f = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'), 'test',
                         'test.yaml')
        f_out = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'),
                             'test', 'test_dump.yaml')

        cmd = 'rosparam'
        ps = get_param_server()

        try:
            rosparam.yamlmain([cmd, 'dump'])
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
Ejemplo n.º 12
0
    def test_rosparam_list(self):
        from ros import rosparam
        cmd = 'rosparam'

        params = [
            '/string',
            '/int',
            '/float',
            '/g1/string',
            '/g1/int',
            '/g1/float',
            '/g2/string',
            '/g2/int',
            '/g2/float',
        ]
        l = rosparam.list_params('')
        for t in params:
            self.assert_(t in l)

        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list'])
            self._check(params, tolist(b))
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/'])
            self._check(params, tolist(b))

        # test with namespace
        g1p = [p for p in params if p.startswith('/g1/')]
        not_g1p = [p for p in params if not p.startswith('/g1/')]
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/g1'])
            self._check(g1p, tolist(b))
            self._notcheck(not_g1p, tolist(b))
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/g1/'])
            self._check(g1p, tolist(b))
            self._notcheck(not_g1p, tolist(b))
        # test with no match
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/not/a/namespace/'])
            self.assertEquals([], tolist(b))
Ejemplo n.º 13
0
    def test_rosparam_set(self):
        from ros import rosparam
        cmd = 'rosparam'

        ps = get_param_server()
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/test1", "1"])
            self.assertEquals(1, ps.getParam('/', '/rosparam_set/test1')[2])
        with fakestdout() as b:
            # -- verbose
            rosparam.yamlmain([cmd, 'set', '-v', "/rosparam_set/test1", "1"])
            self.assertEquals(1, ps.getParam('/', '/rosparam_set/test1')[2])
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'set', "rosparam_set/test1", "2"])
            self.assertEquals(2, ps.getParam('/', '/rosparam_set/test1')[2])

        with fakestdout() as b:
            # - floats
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/test2", "1.0"])
            self.assertEquals(1., ps.getParam('/', '/rosparam_set/test2')[2])
        with fakestdout() as b:
            # - floats
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/test2", "2.0"])
            self.assertEquals(2., ps.getParam('/', '/rosparam_set/test2')[2])
        with fakestdout() as b:
            # - booleans
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/testbool", "true"])
            self.assertEquals(True,
                              ps.getParam('/', '/rosparam_set/testbool')[2])
        with fakestdout() as b:
            # - strings
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/teststr", "hi"])
            self.assertEquals("hi",
                              ps.getParam('/', '/rosparam_set/teststr')[2])
        with fakestdout() as b:
            # - list
            rosparam.yamlmain(
                [cmd, 'set', "/rosparam_set/testlist", "[1, 2, 3]"])
            self.assertEquals([1, 2, 3],
                              ps.getParam('/', '/rosparam_set/testlist')[2])
        with fakestdout() as b:
            # - dictionary
            rosparam.yamlmain(
                [cmd, 'set', "/rosparam_set/testdict", "{a: b, c: d}"])
            self.assertEquals('b',
                              ps.getParam('/', '/rosparam_set/testdict/a')[2])
            self.assertEquals('d',
                              ps.getParam('/', '/rosparam_set/testdict/c')[2])
        with fakestdout() as b:
            #   - empty dictionary should be a noop
            rosparam.yamlmain([cmd, 'set', "set/testdict", "{}"])
            self.assertEquals('b',
                              ps.getParam('/', '/rosparam_set/testdict/a')[2])
            self.assertEquals('d',
                              ps.getParam('/', '/rosparam_set/testdict/c')[2])
        with fakestdout() as b:
            #   - this should be an update
            rosparam.yamlmain(
                [cmd, 'set', "/rosparam_set/testdict", "{e: f, g: h}"])
            self.assertEquals('b',
                              ps.getParam('/', '/rosparam_set/testdict/a')[2])
            self.assertEquals('d',
                              ps.getParam('/', '/rosparam_set/testdict/c')[2])
            self.assertEquals('f',
                              ps.getParam('/', '/rosparam_set/testdict/e')[2])
            self.assertEquals('h',
                              ps.getParam('/', '/rosparam_set/testdict/g')[2])
        with fakestdout() as b:
            # -- verbose
            rosparam.yamlmain([
                cmd, 'set', '-v', "/rosparam_set/testdictverbose",
                "{e: f, g: h}"
            ])
            self.assertEquals(
                'f',
                ps.getParam('/', '/rosparam_set/testdictverbose/e')[2])
            self.assertEquals(
                'h',
                ps.getParam('/', '/rosparam_set/testdictverbose/g')[2])
Ejemplo n.º 14
0
    def test_rosparam_set(self):
        from ros import rosparam
        cmd = 'rosparam'

        ps = get_param_server()
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/test1", "1"])
            self.assertEquals(1, ps.getParam('/', '/rosparam_set/test1')[2])
        with fakestdout() as b:            
            # -- verbose
            rosparam.yamlmain([cmd, 'set', '-v', "/rosparam_set/test1", "1"])
            self.assertEquals(1, ps.getParam('/', '/rosparam_set/test1')[2])
        with fakestdout() as b:            
            rosparam.yamlmain([cmd, 'set', "rosparam_set/test1", "2"])
            self.assertEquals(2, ps.getParam('/', '/rosparam_set/test1')[2])
            
        with fakestdout() as b:
            # - floats
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/test2", "1.0"])
            self.assertEquals(1., ps.getParam('/', '/rosparam_set/test2')[2])
        with fakestdout() as b:
            # - floats
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/test2", "2.0"])
            self.assertEquals(2., ps.getParam('/', '/rosparam_set/test2')[2])
        with fakestdout() as b:            
            # - booleans
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/testbool", "true"])
            self.assertEquals(True, ps.getParam('/', '/rosparam_set/testbool')[2])
        with fakestdout() as b:            
            # - strings
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/teststr", "hi"])
            self.assertEquals("hi", ps.getParam('/', '/rosparam_set/teststr')[2])
        with fakestdout() as b: 
            # - list
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/testlist", "[1, 2, 3]"])
            self.assertEquals([1, 2, 3], ps.getParam('/', '/rosparam_set/testlist')[2])
        with fakestdout() as b: 
            # - dictionary
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/testdict", "{a: b, c: d}"])
            self.assertEquals('b', ps.getParam('/', '/rosparam_set/testdict/a')[2])
            self.assertEquals('d', ps.getParam('/', '/rosparam_set/testdict/c')[2])
        with fakestdout() as b:             
            #   - empty dictionary should be a noop
            rosparam.yamlmain([cmd, 'set', "set/testdict", "{}"])
            self.assertEquals('b', ps.getParam('/', '/rosparam_set/testdict/a')[2])
            self.assertEquals('d', ps.getParam('/', '/rosparam_set/testdict/c')[2])
        with fakestdout() as b:                         
            #   - this should be an update
            rosparam.yamlmain([cmd, 'set', "/rosparam_set/testdict", "{e: f, g: h}"])
            self.assertEquals('b', ps.getParam('/', '/rosparam_set/testdict/a')[2])
            self.assertEquals('d', ps.getParam('/', '/rosparam_set/testdict/c')[2])
            self.assertEquals('f', ps.getParam('/', '/rosparam_set/testdict/e')[2])
            self.assertEquals('h', ps.getParam('/', '/rosparam_set/testdict/g')[2])
        with fakestdout() as b:                                     
            # -- verbose
            rosparam.yamlmain([cmd, 'set', '-v', "/rosparam_set/testdictverbose", "{e: f, g: h}"])
            self.assertEquals('f', ps.getParam('/', '/rosparam_set/testdictverbose/e')[2])
            self.assertEquals('h', ps.getParam('/', '/rosparam_set/testdictverbose/g')[2])
Ejemplo n.º 15
0
class TestRosparam(unittest.TestCase):
    def setUp(self):
        pass

    def _check(self, expected, actual):
        """
        Make sure all elements of expected are present in actual
        """
        for t in expected:
            self.assert_(t in actual)

    def _notcheck(self, not_expected, actual):
        """
        Make sure all elements of not_expected are not present in actual
        """
        for t in not_expected:
            self.failIf(t in actual)

    def test_rosparam_list(self):
        from ros import rosparam
        cmd = 'rosparam'

        params = [
            '/string',
            '/int',
            '/float',
            '/g1/string',
            '/g1/int',
            '/g1/float',
            '/g2/string',
            '/g2/int',
            '/g2/float',
        ]
        l = rosparam.list_params('')
        for t in params:
            self.assert_(t in l)

        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list'])
            self._check(params, tolist(b))
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/'])
            self._check(params, tolist(b))

        # test with namespace
        g1p = [p for p in params if p.startswith('/g1/')]
        not_g1p = [p for p in params if not p.startswith('/g1/')]
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/g1'])
            self._check(g1p, tolist(b))
            self._notcheck(not_g1p, tolist(b))
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/g1/'])
            self._check(g1p, tolist(b))
            self._notcheck(not_g1p, tolist(b))
        # test with no match
        with fakestdout() as b:
            rosparam.yamlmain([cmd, 'list', '/not/a/namespace/'])
            self.assertEquals([], tolist(b))

    def test_rosparam_load(self):
        from ros import rosparam
        import roslib.packages
        f = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'), 'test',
                         'test.yaml')
        f_ns = os.path.join(roslib.packages.get_pkg_dir('test_rosparam'),
                            'test', 'test_ns.yaml')

        cmd = 'rosparam'
        try:
            rosparam.yamlmain([cmd, 'load'])
            self.fail("command-line arg should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
        try:
            rosparam.yamlmain([cmd, 'load', 'fake-file.yaml'])
            self.fail("command-line arg should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
Ejemplo n.º 16
0
        cmd = 'rosparam'
        try:
            rosparam.yamlmain([cmd, 'load'])
            self.fail("command-line arg should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
        try:
            rosparam.yamlmain([cmd, 'load', 'fake-file.yaml'])
            self.fail("command-line arg should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)

        ps = get_param_server()

        # load into top-level
        rosparam.yamlmain([cmd, 'load', f])
        self.assertEquals('bar', ps.getParam('/', '/foo')[2])
        # - make sure it did an overlay, not erase
        self.assertEquals('foo-value', ps.getParam('/', '/string')[2])

        rosparam.yamlmain([cmd, 'load', '-v', f])
        self.assertEquals('bar', ps.getParam('/', '/foo')[2])

        # load into namespace
        rosparam.yamlmain([cmd, 'load', f, '/rosparam_load/test'])
        self.assertEquals('bar',
                          ps.getParam('/', '/rosparam_load/test/foo')[2])
        rosparam.yamlmain([cmd, 'load', '-v', f, '/rosparam_load/test'])
        self.assertEquals('bar',
                          ps.getParam('/', '/rosparam_load/test/foo')[2])
Ejemplo n.º 17
0
        cmd = 'rosparam'
        try:
            rosparam.yamlmain([cmd, 'load'])
            self.fail("command-line arg should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
        try:
            rosparam.yamlmain([cmd, 'load', 'fake-file.yaml'])
            self.fail("command-line arg should have failed")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)

        ps = get_param_server()

        # load into top-level
        rosparam.yamlmain([cmd, 'load', f])
        self.assertEquals('bar', ps.getParam('/', '/foo')[2])
        # - make sure it did an overlay, not erase
        self.assertEquals('foo-value', ps.getParam('/', '/string')[2])
        
        rosparam.yamlmain([cmd, 'load', '-v', f])
        self.assertEquals('bar', ps.getParam('/', '/foo')[2])
        
        # load into namespace
        rosparam.yamlmain([cmd, 'load', f, '/rosparam_load/test'])
        self.assertEquals('bar', ps.getParam('/', '/rosparam_load/test/foo')[2])
        rosparam.yamlmain([cmd, 'load', '-v', f, '/rosparam_load/test'])
        self.assertEquals('bar', ps.getParam('/', '/rosparam_load/test/foo')[2])

        # load file with namespace spec in it
        # - load into top-level