示例#1
0
    def test_ValueValidity(self):
        validValues = [("hello", 'string'), (True, 'bool'), (1, 'uchar'),
                       (1, 'int'), (1, 'uint'), (1, 'int64'), (1, 'uint64'),
                       (1.0, 'half'), (1.0, 'float'), (1.0, 'double'),
                       (Gf.Vec2d(1, 2), 'double2'), (Gf.Vec2f(1, 2), 'float2'),
                       (Gf.Vec2h(1, 2), 'half2'), (Gf.Vec2i(1, 2), 'int2'),
                       (Gf.Vec3d(1, 2, 3), 'double3'),
                       (Gf.Vec3f(1, 2, 3), 'float3'),
                       (Gf.Vec3h(1, 2, 3), 'half3'), (Gf.Vec3i(1, 2,
                                                               3), 'int3'),
                       (Gf.Vec4d(1, 2, 3, 4), 'double4'),
                       (Gf.Vec4f(1, 2, 3, 4), 'float4'),
                       (Gf.Vec4h(1, 2, 3, 4), 'half4'),
                       (Gf.Vec4i(1, 2, 3, 4), 'int4'),
                       (Gf.Matrix4d(3), 'matrix4d'), (Gf.Quatd(1), 'quatd'),
                       (Gf.Quatf(2), 'quatf'), (Gf.Quath(2), 'quath'),
                       (Vt.StringArray(), 'string[]'),
                       (Vt.Vec2dArray(), 'double2[]'),
                       (Vt.Vec2fArray(), 'float2[]'),
                       (Vt.Vec2hArray(), 'half2[]'),
                       (Vt.Vec2iArray(), 'int2[]')]

        for value, typeName in validValues:
            self.assertTrue(Sdf.ValueHasValidType(value))

            # Special case -- python floats will always report 'double', and
            # integers will always report 'int' for the values we're testing here.
            if typeName in ['half', 'float']:
                self.assertEqual(Sdf.GetValueTypeNameForValue(value), 'double')
            elif typeName in ['uchar', 'uint', 'int64', 'uint64']:
                self.assertEqual(Sdf.GetValueTypeNameForValue(value), 'int')
            else:
                self.assertEqual(Sdf.GetValueTypeNameForValue(value), typeName)

            self._TestRoundTrippingValue(typeName, value)
示例#2
0
    def test_AliasedTypes(self):
        # A list of value, type and the corresponding basic type.
        validAliasValues = [
            # Color types
            (Gf.Vec3d(1, 2, 3), 'color3d', 'double3'),
            (Gf.Vec3f(1, 2, 3), 'color3f', 'float3'),
            (Gf.Vec3h(1, 2, 3), 'color3h', 'half3'),
            (Gf.Vec4d(1, 2, 3, 4), 'color4d', 'double4'),
            (Gf.Vec4f(1, 2, 3, 4), 'color4f', 'float4'),
            (Gf.Vec4h(1, 2, 3, 4), 'color4h', 'half4'),
            (Vt.Vec3dArray(), 'color3d[]', 'double3[]'),
            (Vt.Vec3fArray(), 'color3f[]', 'float3[]'),
            (Vt.Vec3hArray(), 'color3h[]', 'half3[]'),
            (Vt.Vec4dArray(), 'color4d[]', 'double4[]'),
            (Vt.Vec4fArray(), 'color4f[]', 'float4[]'),
            (Vt.Vec4hArray(), 'color4h[]', 'half4[]'),

            # Point types
            (Gf.Vec3d(1, 2, 3), 'point3d', 'double3'),
            (Gf.Vec3f(1, 2, 3), 'point3f', 'float3'),
            (Gf.Vec3h(1, 2, 3), 'point3h', 'half3'),
            (Vt.Vec3dArray(), 'point3d[]', 'double3[]'),
            (Vt.Vec3fArray(), 'point3f[]', 'float3[]'),
            (Vt.Vec3hArray(), 'point3h[]', 'half3[]'),

            # Normal types
            (Gf.Vec3d(1, 2, 3), 'normal3d', 'double3'),
            (Gf.Vec3f(1, 2, 3), 'normal3f', 'float3'),
            (Gf.Vec3h(1, 2, 3), 'normal3h', 'half3'),
            (Vt.Vec3dArray(), 'normal3d[]', 'double3[]'),
            (Vt.Vec3fArray(), 'normal3f[]', 'float3[]'),
            (Vt.Vec3hArray(), 'normal3h[]', 'half3[]'),

            # Vector types
            (Gf.Vec3d(1, 2, 3), 'vector3d', 'double3'),
            (Gf.Vec3f(1, 2, 3), 'vector3f', 'float3'),
            (Gf.Vec3h(1, 2, 3), 'vector3h', 'half3'),
            (Vt.Vec3dArray(), 'vector3d[]', 'double3[]'),
            (Vt.Vec3fArray(), 'vector3f[]', 'float3[]'),
            (Vt.Vec3hArray(), 'vector3h[]', 'half3[]'),

            # Frame type
            (Gf.Matrix4d(3), 'frame4d', 'matrix4d')
        ]

        for value, typeName, baseTypeName in validAliasValues:
            self.assertTrue(Sdf.ValueHasValidType(value))
            self.assertEqual(Sdf.GetValueTypeNameForValue(value), baseTypeName)
            self._TestRoundTrippingValue(typeName, value)