Exemple #1
0
    def test_cmd_call(self):
        from ros import rosservice
        cmd = 'rosservice'

        try:
            rosservice.rosservicemain([cmd, 'call'])
            self.fail("arg parsing should have failed")
        except SystemExit: pass
        try:
            rosservice.rosservicemain([cmd, 'call', 'add_two_ints', '1', '2', '3'])
            self.fail("should have failed with too many args")
        except SystemExit: pass
Exemple #2
0
    def test_cmd_find(self):
        from ros import rosservice
        cmd = 'rosservice'

        try:
            rosservice.rosservicemain([cmd, 'find'])
            self.fail("arg parsing should have failed")
        except SystemExit:
            pass
        try:
            rosservice.rosservicemain(
                [cmd, 'find', 'test_ros/AddTwoInts', 'test/AddThreeInts'])
            self.fail("arg parsing should have failed")
        except SystemExit:
            pass

        v = set(['/add_two_ints', '/bar/add_two_ints', '/foo/add_two_ints'])
        with fakestdout() as b:
            rosservice.rosservicemain([cmd, 'find', 'test_ros/AddTwoInts'])
            d = set([x for x in b.getvalue().split('\n') if x.strip()])
            self.assertEquals(v, d)

        with fakestdout() as b:
            rosservice.rosservicemain([cmd, 'find', 'fake/AddTwoInts'])
            self.assertEquals('', b.getvalue().strip())
Exemple #3
0
    def test_cmd_info(self):
        from ros import rosservice
        cmd = 'rosservice'

        try:
            rosservice.rosservicemain([cmd, 'info'])
            self.fail("should have exited with error")
        except SystemExit:
            pass
        try:
            rosservice.rosservicemain([cmd, 'info', '/fake_service'])
            self.fail("should have exited with error")
        except SystemExit:
            pass
        try:
            rosservice.rosservicemain(
                [cmd, 'info', '/add_two_ints', '/foo/add_two_ints'])
            self.fail("should have exited with error")
        except SystemExit:
            pass

        for s in ['/add_two_ints', 'add_two_ints', 'foo/add_two_ints']:
            with fakestdout() as b:
                rosservice.rosservicemain([cmd, 'info', s])
                d = todict(b.getvalue())
                if 'foo' in s:
                    self.assertEquals('/foo/a2iserver', d['Node'])
                else:
                    self.assertEquals('/a2iserver', d['Node'], repr(d['Node']))
                self.assertEquals('test_ros/AddTwoInts', d['Type'])
                self.assertEquals('a b', d['Args'])
                self.assert_('URI' in d)
Exemple #4
0
    def test_cmd_info(self):
        from ros import rosservice
        cmd = 'rosservice'

        try:
            rosservice.rosservicemain([cmd, 'info'])
            self.fail("should have exited with error")
        except SystemExit: pass
        try:
            rosservice.rosservicemain([cmd, 'info', '/fake_service'])
            self.fail("should have exited with error")
        except SystemExit: pass
        try:
            rosservice.rosservicemain([cmd, 'info', '/add_two_ints', '/foo/add_two_ints'])
            self.fail("should have exited with error")
        except SystemExit: pass
        
        for s in ['/add_two_ints', 'add_two_ints', 'foo/add_two_ints']:
            with fakestdout() as b:
                rosservice.rosservicemain([cmd, 'info', s])
                d = todict(b.getvalue())
                if 'foo' in s:
                    self.assertEquals('/foo/a2iserver', d['Node'])
                else:
                    self.assertEquals('/a2iserver', d['Node'], repr(d['Node']))
                self.assertEquals('test_ros/AddTwoInts', d['Type'])
                self.assertEquals('a b', d['Args'])
                self.assert_('URI' in d)
Exemple #5
0
    def test_cmd_call(self):
        from ros import rosservice
        cmd = 'rosservice'

        try:
            rosservice.rosservicemain([cmd, 'call'])
            self.fail("arg parsing should have failed")
        except SystemExit:
            pass
        try:
            rosservice.rosservicemain(
                [cmd, 'call', 'add_two_ints', '1', '2', '3'])
            self.fail("should have failed with too many args")
        except SystemExit:
            pass
Exemple #6
0
    def test_cmd_uri(self):
        from ros import rosservice
        cmd = 'rosservice'
        with fakestdout() as b:
            try:
                rosservice.rosservicemain([cmd, 'uri', '/fake_service'])
                self.fail("should have triggered error exit")
            except SystemExit:
                pass

        for s in ['/add_two_ints', 'add_two_ints', 'foo/add_two_ints']:
            with fakestdout() as b:
                rosservice.rosservicemain([cmd, 'uri', s])
                v = b.getvalue().strip()
                self.assert_(v.startswith('rosrpc://'), v)
Exemple #7
0
    def test_cmd_type(self):
        from ros import rosservice
        cmd = 'rosservice'
        s = '/add_two_ints'
        try:
            rosservice.rosservicemain([cmd, 'type', '/fake_service'])
            self.fail("should have triggered error exit")
        except SystemExit:
            pass

        for s in ['/add_two_ints', 'add_two_ints', 'foo/add_two_ints']:
            with fakestdout() as b:
                rosservice.rosservicemain([cmd, 'type', s])
                v = b.getvalue().strip()
                self.assertEquals('test_ros/AddTwoInts', v)
Exemple #8
0
 def test_cmd_node(self):
     from ros import rosservice
     cmd = 'rosservice'
     for s in ['/add_two_ints', 'add_two_ints', 'foo/add_two_ints']:
         with fakestdout() as b:
             rosservice.rosservicemain([cmd, 'node', s])
             v = b.getvalue().strip()
             if 'foo' in s:
                 self.assertEquals('/foo/a2iserver', v)
             else:
                 self.assertEquals('/a2iserver', v)
     try:
         rosservice.rosservicemain([cmd, 'node', '/fake_two_ints'])
         self.fail("should have exited with error")
     except SystemExit: pass
Exemple #9
0
    def test_cmd_uri(self):
        from ros import rosservice
        cmd = 'rosservice'
        with fakestdout() as b:
            try:
                rosservice.rosservicemain([cmd, 'uri', '/fake_service'])
                self.fail("should have triggered error exit")
            except SystemExit:
                pass

        for s in ['/add_two_ints', 'add_two_ints', 'foo/add_two_ints']:
            with fakestdout() as b:
                rosservice.rosservicemain([cmd, 'uri', s])
                v = b.getvalue().strip()
                self.assert_(v.startswith('rosrpc://'), v)
Exemple #10
0
    def test_cmd_type(self):
        from ros import rosservice
        cmd = 'rosservice'
        s = '/add_two_ints'
        try:
            rosservice.rosservicemain([cmd, 'type', '/fake_service'])
            self.fail("should have triggered error exit")
        except SystemExit:
            pass

        for s in ['/add_two_ints', 'add_two_ints', 'foo/add_two_ints']:
            with fakestdout() as b:
                rosservice.rosservicemain([cmd, 'type', s])
                v = b.getvalue().strip()
                self.assertEquals('test_ros/AddTwoInts', v)
Exemple #11
0
 def test_cmd_node(self):
     from ros import rosservice
     cmd = 'rosservice'
     for s in ['/add_two_ints', 'add_two_ints', 'foo/add_two_ints']:
         with fakestdout() as b:
             rosservice.rosservicemain([cmd, 'node', s])
             v = b.getvalue().strip()
             if 'foo' in s:
                 self.assertEquals('/foo/a2iserver', v)
             else:
                 self.assertEquals('/a2iserver', v)
     try:
         rosservice.rosservicemain([cmd, 'node', '/fake_two_ints'])
         self.fail("should have exited with error")
     except SystemExit:
         pass
Exemple #12
0
    def test_cmd_find(self):
        from ros import rosservice
        cmd = 'rosservice'

        try:
            rosservice.rosservicemain([cmd, 'find'])
            self.fail("arg parsing should have failed")
        except SystemExit: pass
        try:
            rosservice.rosservicemain([cmd, 'find', 'test_ros/AddTwoInts', 'test/AddThreeInts'])
            self.fail("arg parsing should have failed")
        except SystemExit: pass
        
        v = set(['/add_two_ints', '/bar/add_two_ints', '/foo/add_two_ints'])
        with fakestdout() as b:
            rosservice.rosservicemain([cmd, 'find', 'test_ros/AddTwoInts'])
            d = set([x for x in b.getvalue().split('\n') if x.strip()])
            self.assertEquals(v, d)

        with fakestdout() as b:
            rosservice.rosservicemain([cmd, 'find', 'fake/AddTwoInts'])
            self.assertEquals('', b.getvalue().strip())
Exemple #13
0
    def test_cmd_list(self):
        from ros import rosservice
        cmd = 'rosservice'
        s = '/add_two_ints'

        # test main entry
        rosservice.rosservicemain([cmd, 'list'])

        # test directly
        services = [
            '/add_two_ints',
            '/foo/add_two_ints',
            '/bar/add_two_ints',
            '/header_echo',
        ]
        services_nodes = [
            '/add_two_ints /a2iserver',
            '/foo/add_two_ints /foo/a2iserver',
            '/bar/add_two_ints /bar/a2iserver',
            '/header_echo /headerserver',
        ]

        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            v = [x for x in v if not x.startswith('/rosout/')]
            self.assertEquals(set(services), set(v))
        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list', '-n'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            v = [x for x in v if not x.startswith('/rosout/')]
            self.assertEquals(set(services_nodes), set(v))
        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list', '--nodes'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            v = [x for x in v if not x.startswith('/rosout/')]
            self.assertEquals(set(services_nodes), set(v))

        # test with multiple service names
        try:
            rosservice._rosservice_cmd_list([cmd, 'list', s, s])
            self.fail("should have caused parser error")
        except SystemExit:
            pass

        # test with resolved service names
        for s in services:
            with fakestdout() as b:
                rosservice._rosservice_cmd_list([cmd, 'list', s])
                self.assertEquals(s, b.getvalue().strip())

        # test with relative service names
        s = 'add_two_ints'
        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list', s])
            self.assertEquals('/add_two_ints', b.getvalue().strip())
        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list', s, '-n'])
            self.assertEquals('/add_two_ints /a2iserver', b.getvalue().strip())
        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list', s, '--nodes'])
            self.assertEquals('/add_two_ints /a2iserver', b.getvalue().strip())

        # test with namespaces
        s = '/foo'
        rosservice._rosservice_cmd_list([cmd, 'list', s])
        rosservice._rosservice_cmd_list([cmd, 'list', s, '-n'])
        rosservice._rosservice_cmd_list([cmd, 'list', s, '--nodes'])
        s = 'foo'
        rosservice._rosservice_cmd_list([cmd, 'list', s])
        rosservice._rosservice_cmd_list([cmd, 'list', s, '-n'])
        rosservice._rosservice_cmd_list([cmd, 'list', s, '--nodes'])
Exemple #14
0
    def test_cmd_list(self):
        from ros import rosservice
        cmd = 'rosservice'
        s = '/add_two_ints'
        
        # test main entry
        rosservice.rosservicemain([cmd, 'list'])

        # test directly
        services = ['/add_two_ints',
                    '/foo/add_two_ints',
                    '/bar/add_two_ints',
                    '/header_echo',
                    ]
        services_nodes = ['/add_two_ints /a2iserver',
                          '/foo/add_two_ints /foo/a2iserver',
                          '/bar/add_two_ints /bar/a2iserver',
                          '/header_echo /headerserver',
                          ]

        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            v = [x for x in v if not x.startswith('/rosout/')]
            self.assertEquals(set(services), set(v))
        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list', '-n'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            v = [x for x in v if not x.startswith('/rosout/')]
            self.assertEquals(set(services_nodes), set(v))
        with fakestdout() as b:            
            rosservice._rosservice_cmd_list([cmd, 'list', '--nodes'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            v = [x for x in v if not x.startswith('/rosout/')]
            self.assertEquals(set(services_nodes), set(v))

        # test with multiple service names
        try:
            rosservice._rosservice_cmd_list([cmd, 'list', s, s])
            self.fail("should have caused parser error")
        except SystemExit:
            pass

        # test with resolved service names
        for s in services:
            with fakestdout() as b:
                rosservice._rosservice_cmd_list([cmd, 'list', s])
                self.assertEquals(s, b.getvalue().strip())

        # test with relative service names
        s = 'add_two_ints'       
        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list', s])
            self.assertEquals('/add_two_ints', b.getvalue().strip())
        with fakestdout() as b:
            rosservice._rosservice_cmd_list([cmd, 'list', s, '-n'])
            self.assertEquals('/add_two_ints /a2iserver', b.getvalue().strip())
        with fakestdout() as b:            
            rosservice._rosservice_cmd_list([cmd, 'list', s, '--nodes'])
            self.assertEquals('/add_two_ints /a2iserver', b.getvalue().strip())
            
        # test with namespaces
        s = '/foo'
        rosservice._rosservice_cmd_list([cmd, 'list', s])
        rosservice._rosservice_cmd_list([cmd, 'list', s, '-n'])
        rosservice._rosservice_cmd_list([cmd, 'list', s, '--nodes'])
        s = 'foo'
        rosservice._rosservice_cmd_list([cmd, 'list', s])
        rosservice._rosservice_cmd_list([cmd, 'list', s, '-n'])
        rosservice._rosservice_cmd_list([cmd, 'list', s, '--nodes'])