Exemple #1
0
    def testSerializationChecksSomeTypes(self):
        """When using a simple structure like Point, everything works fine."""
        # Point has required fields. Serialization fails if you don't set them.
        point = Point()
        self.assertRaises(TProtocolException, SerializeThriftMsg, point)
        
        # Of course, serialization works when you set fields correctly.
        point.x, point.y = 1.0, 1.2
        SerializeThriftMsg(point)

        # Point.x is a double. If it's a string then you can't serialize.
        point.x = "asdf"
        self.assertRaises(Exception, SerializeThriftMsg, point)
        
        # Same is true for point.y
        point.y = "also a string"
        self.assertRaises(Exception, SerializeThriftMsg, point)
    def testSimpleCase(self):
        """When using a simple structure like Point, everything works fine."""
        # point.x and point.y are required and unset
        point = Point()
        self.assertRaises(Exception, point.validate)

        # point.y is required and unset
        point.x = 1.0
        self.assertRaises(Exception, point.validate)

        # both point.x and point.y are set, so point is valid.
        point.y = 1.2
        point.validate()

        # But here's something weird you should know about:
        # point.x is supposed to be a double, but if you set
        # to a string it will still validate
        point.x = 'this is not a double'
        point.validate()