Ejemplo n.º 1
0
    def test_slicing(self):
        from test_rostopic.msg import ArrayVal, Val
        from rostopic import msgevalgen as f

        # prepare a sliceable msg
        msg = ArrayVal()
        for v in ['ABCDEFG', 'abcdefg', '1234567', 'short']:
            msg.vals.append(Val(val=v))

        self.assertEqual(f(''), None)
        self.assertEqual(f('/'), None)
        self.assertListEqual(f('/vals')(msg), msg.vals)
        self.assertListEqual(f('/vals/')(msg), msg.vals)
        # first-level slicing
        self.assertListEqual(f('/vals[:]')(msg), msg.vals)
        self.assertListEqual(f('/vals[0:2]')(msg), msg.vals[0:2])
        # element access
        self.assertEqual(f('/vals[0]')(msg), msg.vals[0])
        self.assertEqual(f('/vals[1]')(msg), msg.vals[1])
        self.assertEqual(f('/vals['), None)
        self.assertEqual(f('/vals[]'), None)
        self.assertEqual(f('/vals[0'), None)
        # element access continued
        self.assertEqual(f('/vals[0]/val')(msg), msg.vals[0].val)
        self.assertEqual(f('/vals[1]/val')(msg), msg.vals[1].val)
        self.assertEqual(f('/vals[/val'), None)
        self.assertEqual(f('/vals[]/val'), None)
        self.assertEqual(f('/vals[0/val'), None)
        # second-level slicing
        self.assertEqual(f('/vals[0]/val[:]')(msg), msg.vals[0].val)
        self.assertEqual(f('/vals[0]/val[0:2]')(msg), msg.vals[0].val[0:2])
        self.assertEqual(f('/vals[0]/val[:-3]')(msg), msg.vals[0].val[:-3])
        self.assertEqual(f('/vals[0]/val[2]')(msg), msg.vals[0].val[2])
        # first-level slicing + second-level access
        self.assertListEqual(f('/vals[:3]/val[0]')(msg), ['A', 'a', '1'])
        self.assertListEqual(f('/vals[:3]/val[0]')(msg), ['A', 'a', '1'])
        self.assertListEqual(f('/vals[1:3]/val[0]')(msg), ['a', '1'])
        self.assertListEqual(f('/vals[:]/val[-1]')(msg), ['G', 'g', '7', 't'])
        # multiple slicing
        self.assertListEqual(f('/vals[:3]/val[1:3]')(msg), ['BC', 'bc', '23'])
        # out-of-range errors
        self.assertEqual(f('/vals[5]/val')(msg), None)
        self.assertListEqual(f('/vals[:]/val[6]')(msg), ['G', 'g', '7', None])
        # invalid descriptions
        self.assertEqual(f('/vals[:]/val[]'), None)
        self.assertEqual(f('/unknown[:]/val[0]')(msg), None)
        self.assertListEqual(
            f('/vals[:]/unknown[0]')(msg), [None, None, None, None])
        self.assertEqual(f('/vals/unknown[0]')(msg), None)
Ejemplo n.º 2
0
    def test_slicing(self):
        from test_rostopic.msg import ArrayVal, Val
        from rostopic import msgevalgen as f

        # prepare a sliceable msg
        msg = ArrayVal()
        for v in ['ABCDEFG', 'abcdefg', '1234567', 'short']:
            msg.vals.append(Val(val=v))

        self.assertEqual(f(''), None)
        self.assertEqual(f('/'), None)
        self.assertListEqual(f('/vals')(msg), msg.vals)
        self.assertListEqual(f('/vals/')(msg), msg.vals)
        # first-level slicing
        self.assertListEqual(f('/vals[:]')(msg), msg.vals)
        self.assertListEqual(f('/vals[0:2]')(msg), msg.vals[0:2])
        # element access
        self.assertEqual(f('/vals[0]')(msg), msg.vals[0])
        self.assertEqual(f('/vals[1]')(msg), msg.vals[1])
        self.assertEqual(f('/vals['), None)
        self.assertEqual(f('/vals[]'), None)
        self.assertEqual(f('/vals[0'), None)
        # element access continued
        self.assertEqual(f('/vals[0]/val')(msg), msg.vals[0].val)
        self.assertEqual(f('/vals[1]/val')(msg), msg.vals[1].val)
        self.assertEqual(f('/vals[/val'), None)
        self.assertEqual(f('/vals[]/val'), None)
        self.assertEqual(f('/vals[0/val'), None)
        # second-level slicing
        self.assertEqual(f('/vals[0]/val[:]')(msg), msg.vals[0].val)
        self.assertEqual(f('/vals[0]/val[0:2]')(msg), msg.vals[0].val[0:2])
        self.assertEqual(f('/vals[0]/val[:-3]')(msg), msg.vals[0].val[:-3])
        self.assertEqual(f('/vals[0]/val[2]')(msg), msg.vals[0].val[2])
        # first-level slicing + second-level access
        self.assertListEqual(f('/vals[:3]/val[0]')(msg), ['A', 'a', '1'])
        self.assertListEqual(f('/vals[:3]/val[0]')(msg), ['A', 'a', '1'])
        self.assertListEqual(f('/vals[1:3]/val[0]')(msg), ['a', '1'])
        self.assertListEqual(f('/vals[:]/val[-1]')(msg), ['G', 'g', '7', 't'])
        # multiple slicing
        self.assertListEqual(f('/vals[:3]/val[1:3]')(msg), ['BC', 'bc', '23'])
        # out-of-range errors
        self.assertEqual(f('/vals[5]/val')(msg), None)
        self.assertListEqual(f('/vals[:]/val[6]')(msg), ['G', 'g', '7', None])
        # invalid descriptions
        self.assertEqual(f('/vals[:]/val[]'), None)
        self.assertEqual(f('/unknown[:]/val[0]')(msg), None)
        self.assertListEqual(f('/vals[:]/unknown[0]')(msg), [None, None, None, None])
        self.assertEqual(f('/vals/unknown[0]')(msg), None)
Ejemplo n.º 3
0
    def test_create_field_filter(self):
        from std_msgs.msg import Header, Int32, String
        from test_rostopic.msg import Arrays, Embed, Floats, Simple, TVals

        from rostopic import create_field_filter
        f = create_field_filter(echo_nostr=False, echo_noarr=False)
        m = String()
        self.assertEquals(['data'], list(f(m)))
        m = Int32()
        self.assertEquals(['data'], list(f(m)))
        m = Arrays()
        self.assertEquals([
            'int8_arr', 'uint8_arr', 'int32_arr', 'uint32_arr', 'string_arr',
            'time_arr'
        ], list(f(m)))
        m = Embed()
        self.assertEquals(['simple', 'arrays'], list(f(m)))
        m = Simple()
        self.assertEquals([
            'b', 'int16', 'int32', 'int64', 'c', 'uint16', 'uint32', 'uint64',
            'str'
        ], list(f(m)))
        m = Floats()
        self.assertEquals(['float32', 'float64'], list(f(m)))
        m = TVals()
        self.assertEquals(['t', 'd'], list(f(m)))
        m = Header()
        self.assertEquals(['seq', 'stamp', 'frame_id'], list(f(m)))

        f = create_field_filter(echo_nostr=True, echo_noarr=False)
        m = String()
        self.assertEquals([], list(f(m)))
        m = Int32()
        self.assertEquals(['data'], list(f(m)))
        m = Arrays()
        self.assertEquals(
            ['int8_arr', 'uint8_arr', 'int32_arr', 'uint32_arr', 'time_arr'],
            list(f(m)))
        m = Embed()
        self.assertEquals(['simple', 'arrays'], list(f(m)))
        m = Simple()
        self.assertEquals([
            'b', 'int16', 'int32', 'int64', 'c', 'uint16', 'uint32', 'uint64'
        ], list(f(m)))
        m = Floats()
        self.assertEquals(['float32', 'float64'], list(f(m)))
        m = TVals()
        self.assertEquals(['t', 'd'], list(f(m)))
        m = Header()
        self.assertEquals(['seq', 'stamp'], list(f(m)))

        f = create_field_filter(echo_nostr=False, echo_noarr=True)
        m = String()
        self.assertEquals(['data'], list(f(m)))
        m = Int32()
        self.assertEquals(['data'], list(f(m)))
        m = Arrays()
        self.assertEquals([], list(f(m)))
        m = Embed()
        self.assertEquals(['simple', 'arrays'], list(f(m)))
        m = Simple()
        self.assertEquals([
            'b', 'int16', 'int32', 'int64', 'c', 'uint16', 'uint32', 'uint64',
            'str'
        ], list(f(m)))
        m = Floats()
        self.assertEquals(['float32', 'float64'], list(f(m)))
        m = TVals()
        self.assertEquals(['t', 'd'], list(f(m)))
        m = Header()
        self.assertEquals(['seq', 'stamp', 'frame_id'], list(f(m)))

        f = create_field_filter(echo_nostr=True, echo_noarr=True)
        m = String()
        self.assertEquals([], list(f(m)))
        m = Int32()
        self.assertEquals(['data'], list(f(m)))
        m = Arrays()
        self.assertEquals([], list(f(m)))
        m = Embed()
        self.assertEquals(['simple', 'arrays'], list(f(m)))
        m = Simple()
        self.assertEquals([
            'b', 'int16', 'int32', 'int64', 'c', 'uint16', 'uint32', 'uint64'
        ], list(f(m)))
        m = Floats()
        self.assertEquals(['float32', 'float64'], list(f(m)))
        m = TVals()
        self.assertEquals(['t', 'd'], list(f(m)))
        m = Header()
        self.assertEquals(['seq', 'stamp'], list(f(m)))
Ejemplo n.º 4
0
    def test_create_field_filter(self):
        from std_msgs.msg import Header, Int32, String
        from test_rostopic.msg import Arrays, Embed, Floats, Simple, TVals

        from rostopic import create_field_filter
        f = create_field_filter(echo_nostr=False, echo_noarr=False)
        m = String()
        self.assertEquals(['data'], list(f(m)))
        m = Int32()
        self.assertEquals(['data'], list(f(m)))
        m = Arrays()
        self.assertEquals(['int8_arr', 'uint8_arr', 'int32_arr', 'uint32_arr', 'string_arr', 'time_arr'], list(f(m)))
        m = Embed()
        self.assertEquals(['simple', 'arrays'], list(f(m)))
        m = Simple()
        self.assertEquals(['b', 'int16', 'int32', 'int64', 'c', 'uint16', 'uint32', 'uint64', 'str'], list(f(m)))
        m = Floats()
        self.assertEquals(['float32', 'float64'], list(f(m)))
        m = TVals()
        self.assertEquals(['t', 'd'], list(f(m)))
        m = Header()
        self.assertEquals(['seq', 'stamp', 'frame_id'], list(f(m)))

        f = create_field_filter(echo_nostr=True, echo_noarr=False)
        m = String()
        self.assertEquals([], list(f(m)))
        m = Int32()
        self.assertEquals(['data'], list(f(m)))
        m = Arrays()
        self.assertEquals(['int8_arr', 'uint8_arr', 'int32_arr', 'uint32_arr', 'time_arr'], list(f(m)))
        m = Embed()
        self.assertEquals(['simple', 'arrays'], list(f(m)))
        m = Simple()
        self.assertEquals(['b', 'int16', 'int32', 'int64', 'c', 'uint16', 'uint32', 'uint64'], list(f(m)))
        m = Floats()
        self.assertEquals(['float32', 'float64'], list(f(m)))
        m = TVals()
        self.assertEquals(['t', 'd'], list(f(m)))
        m = Header()
        self.assertEquals(['seq', 'stamp'], list(f(m)))

        f = create_field_filter(echo_nostr=False, echo_noarr=True)
        m = String()
        self.assertEquals(['data'], list(f(m)))
        m = Int32()
        self.assertEquals(['data'], list(f(m)))
        m = Arrays()
        self.assertEquals([], list(f(m)))
        m = Embed()
        self.assertEquals(['simple', 'arrays'], list(f(m)))
        m = Simple()
        self.assertEquals(['b', 'int16', 'int32', 'int64', 'c', 'uint16', 'uint32', 'uint64', 'str'], list(f(m)))
        m = Floats()
        self.assertEquals(['float32', 'float64'], list(f(m)))
        m = TVals()
        self.assertEquals(['t', 'd'], list(f(m)))
        m = Header()
        self.assertEquals(['seq', 'stamp', 'frame_id'], list(f(m)))

        f = create_field_filter(echo_nostr=True, echo_noarr=True)
        m = String()
        self.assertEquals([], list(f(m)))
        m = Int32()
        self.assertEquals(['data'], list(f(m)))
        m = Arrays()
        self.assertEquals([], list(f(m)))
        m = Embed()
        self.assertEquals(['simple', 'arrays'], list(f(m)))
        m = Simple()
        self.assertEquals(['b', 'int16', 'int32', 'int64', 'c', 'uint16', 'uint32', 'uint64'], list(f(m)))
        m = Floats()
        self.assertEquals(['float32', 'float64'], list(f(m)))
        m = TVals()
        self.assertEquals(['t', 'd'], list(f(m)))
        m = Header()
        self.assertEquals(['seq', 'stamp'], list(f(m)))