|
32 | 32 | # |
33 | 33 | ########################################################################## |
34 | 34 |
|
35 | | -import math |
36 | 35 | import unittest |
37 | 36 | import IECore |
38 | | -import random |
39 | | -import os |
| 37 | +import datetime |
| 38 | +import imath |
| 39 | + |
40 | 40 |
|
41 | 41 | class DataTraitsTest( unittest.TestCase ) : |
42 | 42 |
|
@@ -129,6 +129,65 @@ def testIsSequenceDataType( self ) : |
129 | 129 | for data in falseData : |
130 | 130 | self.assertFalse( IECore.DataTraits.isSequenceDataType( data ) ) |
131 | 131 |
|
| 132 | + def testDataFromElement( self ) : |
| 133 | + |
| 134 | + dataMap = ( |
| 135 | + ( True, IECore.BoolData, IECore.BoolVectorData ), |
| 136 | + ( 10, IECore.IntData, IECore.IntVectorData ), |
| 137 | + ( "abc", IECore.StringData, IECore.StringVectorData ), |
| 138 | + ( IECore.InternedString( "abc" ), IECore.InternedStringData, IECore.InternedStringVectorData ), |
| 139 | + ( 1.1, IECore.DoubleData, IECore.DoubleVectorData ), |
| 140 | + ( imath.V2f( 1.0, 2.0 ), IECore.V2fData, IECore.V2fVectorData ), |
| 141 | + ( imath.V2d( 1.0, 2.0 ), IECore.V2dData, IECore.V2dVectorData ), |
| 142 | + ( imath.V2i( 1, 2 ), IECore.V2iData, IECore.V2iVectorData ), |
| 143 | + ( imath.V3i( 1, 2, 3 ), IECore.V3iData, IECore.V3iVectorData ), |
| 144 | + ( imath.V3f( 1.0, 2.0, 3.0 ), IECore.V3fData, IECore.V3fVectorData ), |
| 145 | + ( imath.V3d( 1.0, 2.0, 3.0 ), IECore.V3dData, IECore.V3dVectorData ), |
| 146 | + ( imath.Quatf(), IECore.QuatfData, IECore.QuatfVectorData ), |
| 147 | + ( imath.Quatd(), IECore.QuatdData, IECore.QuatdVectorData ), |
| 148 | + ( imath.Color3f(), IECore.Color3fData, IECore.Color3fVectorData ), |
| 149 | + ( imath.Color4f(), IECore.Color4fData, IECore.Color4fVectorData ), |
| 150 | + ( imath.Box2i(), IECore.Box2iData, IECore.Box2iVectorData ), |
| 151 | + ( imath.Box3i(), IECore.Box3iData, IECore.Box3iVectorData ), |
| 152 | + ( imath.Box2f(), IECore.Box2fData, IECore.Box2fVectorData ), |
| 153 | + ( imath.Box2d(), IECore.Box2dData, IECore.Box2dVectorData ), |
| 154 | + ( imath.Box3f(), IECore.Box3fData, IECore.Box3fVectorData ), |
| 155 | + ( imath.Box3d(), IECore.Box3dData, IECore.Box3dVectorData ), |
| 156 | + ( imath.M33f(), IECore.M33fData, IECore.M33fVectorData ), |
| 157 | + ( imath.M33d(), IECore.M33dData, IECore.M33dVectorData ), |
| 158 | + ( imath.M44f(), IECore.M44fData, IECore.M44fVectorData ), |
| 159 | + ( imath.M44d(), IECore.M44dData, IECore.M44dVectorData ), |
| 160 | + ( { "age" : 10 }, IECore.CompoundData, None ), |
| 161 | + ( IECore.TransformationMatrixf(), IECore.TransformationMatrixfData, None ), |
| 162 | + ( IECore.TransformationMatrixd(), IECore.TransformationMatrixdData, None ), |
| 163 | + ( IECore.LineSegment3f( imath.V3f( 0 ), imath.V3f( 1 ) ), IECore.LineSegment3fData, None ), |
| 164 | + ( IECore.LineSegment3d( imath.V3d( 0 ), imath.V3d( 1 ) ), IECore.LineSegment3dData, None ), |
| 165 | + ( IECore.Splineff(), IECore.SplineffData, None ), |
| 166 | + ( IECore.Splinedd(), IECore.SplineddData, None ), |
| 167 | + ( IECore.SplinefColor3f(), IECore.SplinefColor3fData, None ), |
| 168 | + ( IECore.SplinefColor4f(), IECore.SplinefColor4fData, None ), |
| 169 | + ( datetime.datetime( 2023, 7, 14 ), IECore.DateTimeData, None ), |
| 170 | + ( IECore.TimeCode(), IECore.TimeCodeData, None ), |
| 171 | + ( IECore.PathMatcher(), IECore.PathMatcherData, None ), |
| 172 | + ) |
| 173 | + |
| 174 | + for element, dataType, vectorType in dataMap : |
| 175 | + # test single element conversion |
| 176 | + self.assertEqual( IECore.dataFromElement( element ), dataType( element ) ) |
| 177 | + if vectorType is None : |
| 178 | + continue |
| 179 | + |
| 180 | + # test list of elements conversion to a vector data |
| 181 | + self.assertEqual( |
| 182 | + IECore.dataFromElement( [ element ] ), |
| 183 | + vectorType( [ element ] ), |
| 184 | + ) |
| 185 | + |
| 186 | + def testDataTypeFromElementType( self ) : |
| 187 | + self.assertEqual( IECore.dataTypeFromElementType( int ) , IECore.IntData ) |
| 188 | + self.assertRaises( TypeError, IECore.dataTypeFromElementType, list ) |
| 189 | + |
| 190 | + |
132 | 191 | if __name__ == "__main__": |
133 | | - unittest.main() |
| 192 | + unittest.main() |
134 | 193 |
|
0 commit comments