예제 #1
0
  def test___convert_val(self):
    from roslib.msgs import _convert_val, MsgSpecException
    self.assertEquals(0., _convert_val('float32', '0.0'))
    self.assertEquals(0., _convert_val('float64', '0.0'))
    
    self.assertEquals('fo o', _convert_val('string', '   fo o '))

    self.assertEquals(1, _convert_val('byte', '1'))
    self.assertEquals(1, _convert_val('char', '1'))
    self.assertEquals(1, _convert_val('int8', '1'))
    self.assertEquals(12, _convert_val('int16', '12'))
    self.assertEquals(-13, _convert_val('int32', '-13'))
    self.assertEquals(14, _convert_val('int64', '14'))
    self.assertEquals(0, _convert_val('uint8', '0'))
    self.assertEquals(18, _convert_val('uint16', '18'))
    self.assertEquals(19, _convert_val('uint32', '19'))    
    self.assertEquals(20, _convert_val('uint64', '20'))

    width_fail = [('int8', '129'), ('uint8', '256'),
                  ('int16', '35536'), ('uint16', '-1'),('uint16', '65536'),
                  ('int32', '3000000000'),('int32', '-2700000000'),
                  ('uint32', '-1'),('uint32', '41000000000'),
                  ('uint64', '-1')]
    for t, v in width_fail:
      try:
        _convert_val(t, v)
        self.fail("should have failed width check: %s, %s"%(t, v))
      except MsgSpecException: pass
    type_fail = [('int32', 'f'), ('float32', 'baz')]
    for t, v in type_fail:
      try:
        _convert_val(t, v)
        self.fail("should have failed type check: %s, %s"%(t, v))
      except ValueError: pass
    try:
      _convert_val('foo', '1')
      self.fail("should have failed invalid type")
    except MsgSpecException: pass
예제 #2
0
    def test___convert_val(self):
        from roslib.msgs import _convert_val, MsgSpecException
        self.assertEquals(0., _convert_val('float32', '0.0'))
        self.assertEquals(0., _convert_val('float64', '0.0'))

        self.assertEquals('fo o', _convert_val('string', '   fo o '))

        self.assertEquals(1, _convert_val('byte', '1'))
        self.assertEquals(1, _convert_val('char', '1'))
        self.assertEquals(1, _convert_val('int8', '1'))
        self.assertEquals(12, _convert_val('int16', '12'))
        self.assertEquals(-13, _convert_val('int32', '-13'))
        self.assertEquals(14, _convert_val('int64', '14'))
        self.assertEquals(0, _convert_val('uint8', '0'))
        self.assertEquals(18, _convert_val('uint16', '18'))
        self.assertEquals(19, _convert_val('uint32', '19'))
        self.assertEquals(20, _convert_val('uint64', '20'))

        width_fail = [('int8', '129'), ('uint8', '256'), ('int16', '35536'),
                      ('uint16', '-1'), ('uint16', '65536'),
                      ('int32', '3000000000'), ('int32', '-2700000000'),
                      ('uint32', '-1'), ('uint32', '41000000000'),
                      ('uint64', '-1')]
        for t, v in width_fail:
            try:
                _convert_val(t, v)
                self.fail("should have failed width check: %s, %s" % (t, v))
            except MsgSpecException:
                pass
        type_fail = [('int32', 'f'), ('float32', 'baz')]
        for t, v in type_fail:
            try:
                _convert_val(t, v)
                self.fail("should have failed type check: %s, %s" % (t, v))
            except ValueError:
                pass
        try:
            _convert_val('foo', '1')
            self.fail("should have failed invalid type")
        except MsgSpecException:
            pass
예제 #3
0
    def test___convert_val(self):
        from roslib.msgs import _convert_val, MsgSpecException

        self.assertEquals(0.0, _convert_val("float32", "0.0"))
        self.assertEquals(0.0, _convert_val("float64", "0.0"))

        self.assertEquals("fo o", _convert_val("string", "   fo o "))

        self.assertEquals(1, _convert_val("byte", "1"))
        self.assertEquals(1, _convert_val("char", "1"))
        self.assertEquals(1, _convert_val("int8", "1"))
        self.assertEquals(12, _convert_val("int16", "12"))
        self.assertEquals(-13, _convert_val("int32", "-13"))
        self.assertEquals(14, _convert_val("int64", "14"))
        self.assertEquals(0, _convert_val("uint8", "0"))
        self.assertEquals(18, _convert_val("uint16", "18"))
        self.assertEquals(19, _convert_val("uint32", "19"))
        self.assertEquals(20, _convert_val("uint64", "20"))

        width_fail = [
            ("int8", "129"),
            ("uint8", "256"),
            ("int16", "35536"),
            ("uint16", "-1"),
            ("uint16", "65536"),
            ("int32", "3000000000"),
            ("int32", "-2700000000"),
            ("uint32", "-1"),
            ("uint32", "41000000000"),
            ("uint64", "-1"),
        ]
        for t, v in width_fail:
            try:
                _convert_val(t, v)
                self.fail("should have failed width check: %s, %s" % (t, v))
            except MsgSpecException:
                pass
        type_fail = [("int32", "f"), ("float32", "baz")]
        for t, v in type_fail:
            try:
                _convert_val(t, v)
                self.fail("should have failed type check: %s, %s" % (t, v))
            except ValueError:
                pass
        try:
            _convert_val("foo", "1")
            self.fail("should have failed invalid type")
        except MsgSpecException:
            pass