Esempio n. 1
0
    def test_cmd_info(self):
        import rostopic
        cmd = 'rostopic'

        try:
            rostopic.rostopicmain([cmd, 'info'])
            self.fail("should have exited with error")
        except SystemExit: pass
        try:
            rostopic.rostopicmain([cmd, 'info', '/fake_topic'])
            self.fail("should have exited with error")
        except SystemExit: pass
        try:
            rostopic.rostopicmain([cmd, 'info', '/chatter', '/bar/chatter'])
            self.fail("should have exited with error")
        except SystemExit: pass
        
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'info', 'rosout'])
            v = b.getvalue()
            for s in ["Publishers:", "Subscribers", "Type: rosgraph_msgs/Log", " * /rosout"]:
                self.assert_(s in v, "failed on %s: %s"%(s, v))
        with fakestdout() as b:            
            rostopic.rostopicmain([cmd, 'info', '/chatter'])
            v = b.getvalue()
            for s in ["Publishers:", "Subscribers", "Type: std_msgs/String", " * /talker"]:
                self.assert_(s in v, "failed on %s: %s"%(s, v))
 def test_main(self):
     import rostopic
     c = 'rostopic'
     try:
         rostopic.rostopicmain([c])
         self.fail("should have exited with error")
     except SystemExit, e:
         self.assertNotEquals(0, e.code)
    def test_cmd_type(self):
        import rostopic
        cmd = 'rostopic'
        s = '/rosout_agg'
        t = 'rosgraph_msgs/Log'

        try:
            rostopic.rostopicmain([cmd, 'type', 'fake'])
            self.fail("should have exited")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
    def test_cmd_type(self):
        import rostopic
        cmd = 'rostopic'
        s = '/rosout_agg'
        t = 'rosgraph_msgs/Log'

        try:
            rostopic.rostopicmain([cmd, 'type', 'fake'])
            self.fail("should have exited")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
Esempio n. 5
0
 def test_main(self):
     import rostopic
     c = 'rostopic'
     try:
         rostopic.rostopicmain([c])
         self.fail("should have exited with error")
     except SystemExit as e:
         self.assertNotEquals(0, e.code)
     try:
         rostopic.rostopicmain([c, 'foo'])
         self.fail("should have exited with error")
     except SystemExit as e:
         self.assertNotEquals(0, e.code)
Esempio n. 6
0
    def test_cmd_type(self):
        import rostopic
        cmd = 'rostopic'
        s = '/rosout_agg'
        t = 'rosgraph_msgs/Log'

        try:
            rostopic.rostopicmain([cmd, 'type', 'fake'])
            self.fail("should have exited")
        except SystemExit as e:
            self.assertNotEquals(0, e.code)
                
        for s in ['/chatter', 'chatter', 'foo/chatter', '/bar/chatter']:
            with fakestdout() as b:
                rostopic.rostopicmain([cmd, 'type', s])
                v = b.getvalue().strip()
                self.assertEquals('std_msgs/String', v)
Esempio n. 7
0
    def test_cmd_type(self):
        import rostopic
        cmd = 'rostopic'
        s = '/rosout_agg'
        t = 'rosgraph_msgs/Log'

        try:
            rostopic.rostopicmain([cmd, 'type', 'fake'])
            self.fail("should have exited")
        except SystemExit as e:
            self.assertNotEquals(0, e.code)

        for s in ['/chatter', 'chatter', 'foo/chatter', '/bar/chatter']:
            with fakestdout() as b:
                rostopic.rostopicmain([cmd, 'type', s])
                v = b.getvalue().strip()
                self.assertEquals('std_msgs/String', v)
Esempio n. 8
0
    def test_cmd_pub(self):
        import rostopic
        cmd = 'rostopic'

        # we can't actually test functional behavior because rostopic
        # needs control over a node, though we can probably change the
        # source code to just check for the existing node.

        invalid = [['-r', '--once', '/foo', 'std_msgs/String', 'hello'],
                   ['-r', 'a', '/foo', 'std_msgs/String', 'hello'],
                   ['-r', '--', '-1', '/foo', 'std_msgs/String', 'hello'],                   
                   [],
                   ['/foo'],
                   ['/foo', 'std_msgs/String', 'a: b: !!c: d: e'],                                      
                   ]
        for i in invalid:
            try:
                rostopic.rostopicmain([cmd, 'pub'] + i)
                self.fail("should have exited with error"+str(i))
            except SystemExit as e:
                self.assert_(e.code != 0)
    def test_cmd_pub(self):
        import rostopic
        cmd = 'rostopic'

        # we can't actually test functional behavior because rostopic
        # needs control over a node, though we can probably change the
        # source code to just check for the existing node.

        invalid = [
            ['-r', '--once', '/foo', 'std_msgs/String', 'hello'],
            ['-r', 'a', '/foo', 'std_msgs/String', 'hello'],
            ['-r', '--', '-1', '/foo', 'std_msgs/String', 'hello'],
            [],
            ['/foo'],
            ['/foo', 'std_msgs/String', 'a: b: !!c: d: e'],
        ]
        for i in invalid:
            try:
                rostopic.rostopicmain([cmd, 'pub'] + i)
                self.fail("should have exited with error" + str(i))
            except SystemExit, e:
                self.assert_(e.code != 0)
    def test_cmd_info(self):
        import rostopic
        cmd = 'rostopic'

        try:
            rostopic.rostopicmain([cmd, 'info'])
            self.fail("should have exited with error")
        except SystemExit:
            pass
        try:
            rostopic.rostopicmain([cmd, 'info', '/fake_topic'])
            self.fail("should have exited with error")
        except SystemExit:
            pass
        try:
            rostopic.rostopicmain([cmd, 'info', '/chatter', '/bar/chatter'])
            self.fail("should have exited with error")
        except SystemExit:
            pass

        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'info', 'rosout'])
            v = b.getvalue()
            for s in [
                    "Publishers:", "Subscribers", "Type: rosgraph_msgs/Log",
                    " * /rosout"
            ]:
                self.assert_(s in v, "failed on %s: %s" % (s, v))
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'info', '/chatter'])
            v = b.getvalue()
            for s in [
                    "Publishers:", "Subscribers", "Type: std_msgs/String",
                    " * /talker"
            ]:
                self.assert_(s in v, "failed on %s: %s" % (s, v))
Esempio n. 11
0
    def test_cmd_find(self):
        import rostopic
        cmd = 'rostopic'

        try:
            rostopic.rostopicmain([cmd, 'find'])
            self.fail("arg parsing should have failed")
        except SystemExit: pass
        try:
            rostopic.rostopicmain([cmd, 'find', 'std_msgs/String', 'std_msgs/Int32'])
            self.fail("arg parsing should have failed")
        except SystemExit: pass


        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'find', 'std_msgs/String'])
            d = [x for x in b.getvalue().split('\n') if x.strip()]
            v = ['/foo/chatter', '/bar/chatter', '/chatter']
            self.assertEquals(set(v), set(d))
    def test_cmd_find(self):
        import rostopic
        cmd = 'rostopic'

        try:
            rostopic.rostopicmain([cmd, 'find'])
            self.fail("arg parsing should have failed")
        except SystemExit:
            pass
        try:
            rostopic.rostopicmain(
                [cmd, 'find', 'std_msgs/String', 'std_msgs/Int32'])
            self.fail("arg parsing should have failed")
        except SystemExit:
            pass

        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'find', 'std_msgs/String'])
            d = [x for x in b.getvalue().split('\n') if x.strip()]
            v = ['/foo/chatter', '/bar/chatter', '/chatter']
            self.assertEquals(set(v), set(d))
        for s in ['/chatter', 'chatter', 'foo/chatter', '/bar/chatter']:
            with fakestdout() as b:
                rostopic.rostopicmain([cmd, 'type', s])
                v = b.getvalue().strip()
                self.assertEquals('std_msgs/String', v)

    def test_main(self):
        import rostopic
        c = 'rostopic'
        try:
            rostopic.rostopicmain([c])
            self.fail("should have exited with error")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
        try:
            rostopic.rostopicmain([c, 'foo'])
            self.fail("should have exited with error")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)

    def test_cmd_pub(self):
        import rostopic
        cmd = 'rostopic'

        # we can't actually test functional behavior because rostopic
        # needs control over a node, though we can probably change the
        # source code to just check for the existing node.

        invalid = [
            ['-r', '--once', '/foo', 'std_msgs/String', 'hello'],
            ['-r', 'a', '/foo', 'std_msgs/String', 'hello'],
    def test_cmd_list(self):
        import rostopic
        cmd = 'rostopic'
        s = '/add_two_ints'

        # test failures
        for invalid in [['-ps'], ['-b'
                                  'file.bag', '-s'], ['-b'
                                                      'file.bag', '-p']]:
            try:
                rostopic.rostopicmain([cmd, 'list'] + invalid)
                self.fail("should have failed")
            except SystemExit:
                pass

        # test main entry
        rostopic.rostopicmain([cmd, 'list'])

        # test directly
        topics = [
            '/chatter', '/foo/chatter', '/bar/chatter', '/rosout',
            '/rosout_agg'
        ]

        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            self.failIf(set(topics) - set(v))

        # publishers-only
        topics = [
            '/chatter', '/foo/chatter', '/bar/chatter', '/rosout',
            '/rosout_agg'
        ]
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', '-p'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            self.failIf(set(topics) - set(v))
            self.failIf('/clock' in v)

        # subscribers-only
        topics = ['/rosout']
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', '-s'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            self.failIf(set(topics) - set(v), "%s vs. %s" % (topics, v))
            self.failIf('/chatter' in v)

        # turn on verbosity, not checking output as it's not as stable
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', '-v'])
            v = b.getvalue()
            self.assert_("Published topics:" in v)
            self.assert_("Subscribed topics:" in v)

        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', '-vs'])
            v = b.getvalue()
            self.failIf("Published topics:" in v)
            self.assert_("Subscribed topics:" in v)

        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', '-vp'])
            v = b.getvalue()
            self.assert_("Published topics:" in v)
            self.failIf("Subscribed topics:" in v)

        # test with multiple topic names
        try:
            rostopic.rostopicmain([cmd, 'list', 'rosout', 'rosout_agg'])
            self.fail("should have caused parser error")
        except SystemExit:
            pass

        # test with resolved names
        for n in topics:
            with fakestdout() as b:
                rostopic.rostopicmain([cmd, 'list', n])
                self.assertEquals(n, b.getvalue().strip())

        # test with relative names
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', 'rosout'])
            self.assertEquals('/rosout', b.getvalue().strip())

        # test with namespaces
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', '/foo'])
            self.assertEquals('/foo/chatter', b.getvalue().strip())
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', 'bar'])
            self.assertEquals('/bar/chatter', b.getvalue().strip())
Esempio n. 15
0
    def test_cmd_list(self):
        import rostopic
        cmd = 'rostopic'
        s = '/add_two_ints'

        # test failures
        for invalid in [['-ps'], ['-b' 'file.bag', '-s'], ['-b' 'file.bag', '-p']]:
            try:
                rostopic.rostopicmain([cmd, 'list'] + invalid)
                self.fail("should have failed")
            except SystemExit: pass
        
        # test main entry
        rostopic.rostopicmain([cmd, 'list'])

        # test directly
        topics = ['/chatter', '/foo/chatter', '/bar/chatter', '/rosout', '/rosout_agg'] 

        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            self.failIf(set(topics)-set(v))

        # publishers-only
        topics = ['/chatter', '/foo/chatter', '/bar/chatter', '/rosout', '/rosout_agg'] 
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', '-p'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            self.failIf(set(topics)-set(v))
            self.failIf('/clock' in v)
            
        # subscribers-only
        topics = ['/rosout'] 
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', '-s'])
            v = [x.strip() for x in b.getvalue().split('\n') if x.strip()]
            self.failIf(set(topics)-set(v), "%s vs. %s"%(topics, v))
            self.failIf('/chatter' in v)

        # turn on verbosity, not checking output as it's not as stable
        with fakestdout() as b:            
            rostopic.rostopicmain([cmd, 'list', '-v'])
            v = b.getvalue()
            self.assert_("Published topics:" in v)
            self.assert_("Subscribed topics:" in v)
            
        with fakestdout() as b:            
            rostopic.rostopicmain([cmd, 'list', '-vs'])
            v = b.getvalue()
            self.failIf("Published topics:" in v)        
            self.assert_("Subscribed topics:" in v)

        with fakestdout() as b:            
            rostopic.rostopicmain([cmd, 'list', '-vp'])
            v = b.getvalue()
            self.assert_("Published topics:" in v)        
            self.failIf("Subscribed topics:" in v)
            
        # test with multiple topic names
        try:
            rostopic.rostopicmain([cmd, 'list', 'rosout', 'rosout_agg'])
            self.fail("should have caused parser error")
        except SystemExit:
            pass

        # test with resolved names
        for n in topics:
            with fakestdout() as b:
                rostopic.rostopicmain([cmd, 'list', n])
                self.assertEquals(n, b.getvalue().strip())

        # test with relative names
        with fakestdout() as b:
            rostopic.rostopicmain([cmd, 'list', 'rosout'])
            self.assertEquals('/rosout', b.getvalue().strip())
            
        # test with namespaces
        with fakestdout() as b:        
            rostopic.rostopicmain([cmd, 'list', '/foo'])
            self.assertEquals('/foo/chatter', b.getvalue().strip())
        with fakestdout() as b:        
            rostopic.rostopicmain([cmd, 'list', 'bar'])
            self.assertEquals('/bar/chatter', b.getvalue().strip())
class TestRostopic(unittest.TestCase):
    def __init__(self, *args):
        unittest.TestCase.__init__(self, *args)
        self.vals = set()

        # wait for network to initialize
        rospy.init_node('test')
        topics = ['/chatter', '/foo/chatter', '/bar/chatter']
        subs = [
            rospy.Subscriber(t, std_msgs.msg.String, self.callback, i)
            for i, t in enumerate(topics)
        ]
        all = set(range(0, len(topics)))

        timeout_t = time.time() + 10.
        while time.time(
        ) < timeout_t and self.vals != all and not rospy.is_shutdown():
            time.sleep(0.1)
        [s.unregister() for s in subs]
        if rospy.is_shutdown():
            self.fail("shutdown")

    def test_offline(self):
        import rostopic
        orig_uri = os.environ['ROS_MASTER_URI']
        os.environ['ROS_MASTER_URI'] = 'http://fake_host:12356'

        try:
            c = 'rostopic'

            try:
                rostopic._rostopic_cmd_list([c, 'list'])
                self.fail("should have raised ROSTopicIOException")
            except rostopic.ROSTopicIOException:
                pass

            try:
                rostopic._rostopic_cmd_info([c, 'info', '/chatter'])
                self.fail("should have raised ROSTopicIOException")
            except rostopic.ROSTopicIOException:
                pass

            try:
                rostopic._rostopic_cmd_type([c, 'type', '/chatter'])
                self.fail("should have raised ROSTopicIOException")
            except rostopic.ROSTopicIOException:
                pass

            try:
                rostopic._rostopic_cmd_find([c, 'find', 'std_msgs/String'])
                self.fail("should have raised ROSTopicIOException")
            except rostopic.ROSTopicIOException:
                pass

        finally:
            os.environ['ROS_MASTER_URI'] = orig_uri

    def test_cmd_type(self):
        import rostopic
        cmd = 'rostopic'
        s = '/rosout_agg'
        t = 'rosgraph_msgs/Log'

        try:
            rostopic.rostopicmain([cmd, 'type', 'fake'])
            self.fail("should have exited")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)

        for s in ['/chatter', 'chatter', 'foo/chatter', '/bar/chatter']:
            with fakestdout() as b:
                rostopic.rostopicmain([cmd, 'type', s])
                v = b.getvalue().strip()
                self.assertEquals('std_msgs/String', v)
Esempio n. 17
0
        for s in ['/chatter', 'chatter', 'foo/chatter', '/bar/chatter']:
            with fakestdout() as b:
                rostopic.rostopicmain([cmd, 'type', s])
                v = b.getvalue().strip()
                self.assertEquals('std_msgs/String', v)

    def test_main(self):
        import rostopic
        c = 'rostopic'
        try:
            rostopic.rostopicmain([c])
            self.fail("should have exited with error")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
        try:
            rostopic.rostopicmain([c, 'foo'])
            self.fail("should have exited with error")
        except SystemExit, e:
            self.assertNotEquals(0, e.code)
        
    def test_cmd_pub(self):
        import rostopic
        cmd = 'rostopic'

        # we can't actually test functional behavior because rostopic
        # needs control over a node, though we can probably change the
        # source code to just check for the existing node.

        invalid = [['-r', '--once', '/foo', 'std_msgs/String', 'hello'],
                   ['-r', 'a', '/foo', 'std_msgs/String', 'hello'],
                   ['-r', '--', '-1', '/foo', 'std_msgs/String', 'hello'],