MCPcopy Create free account
hub / github.com/ImageEngine/cortex / testWriting

Method testWriting

test/IECoreScene/LinkedSceneTest.py:141–228  ·  view source on GitHub ↗
( self )

Source from the content-addressed store, hash-verified

139 self.assertEqual( attr, expectedAttr )
140
141 def testWriting( self ):
142
143 generateTestFiles = False # change this to True to recreate the LinkedScene files for other tests.
144 testFilesSuffix = "_newTags"
145 if generateTestFiles :
146 outputPath = os.path.join( "test", "IECore", "data", "sccFiles" )
147 else :
148 outputPath = self.tempDir
149
150 m = IECoreScene.SceneCache( os.path.join( "test", "IECore", "data", "sccFiles", "animatedSpheres.scc" ), IECore.IndexedIO.OpenMode.Read )
151 A = m.child("A")
152
153 l = IECoreScene.LinkedScene( os.path.join(outputPath,"instancedSpheres%s.lscc"%testFilesSuffix), IECore.IndexedIO.OpenMode.Write )
154 i0 = l.createChild("instance0")
155 i0.writeLink( m )
156 i1 = l.createChild("instance1")
157 i1.writeLink( m )
158 i1.writeAttribute( "testAttr", IECore.StringData("test"), 0 )
159 i1.writeTransform( IECore.M44dData( imath.M44d().translate( imath.V3d( 1, 0, 0 ) ) ), 0.0 )
160 i2 = l.createChild("instance2")
161 i2.writeLink( A )
162 i2.writeTransform( IECore.M44dData( imath.M44d().translate( imath.V3d( 2, 0, 0 ) ) ), 0.0 )
163 l.createChild("canHaveChildrenAtLinks")
164 i2.writeTags( ["canHaveTagsAtLinks"] )
165 self.assertRaises( RuntimeError, i2.writeObject, IECoreScene.SpherePrimitive( 1 ), 0.0 ) # cannot save objects at link locations.
166 b1 = l.createChild("branch1")
167 b1.writeObject( IECoreScene.SpherePrimitive( 1 ), 0.0 )
168 self.assertRaises( RuntimeError, b1.writeLink, A )
169 b2 = l.createChild("branch2")
170 c2 = b2.createChild("child2")
171 b2.writeLink( A )
172 del i0, i1, i2, l, b1, b2, c2
173
174 l = IECoreScene.LinkedScene( os.path.join(outputPath,"instancedSpheres%s.lscc"%testFilesSuffix), IECore.IndexedIO.OpenMode.Read )
175
176 self.assertEqual( l.numBoundSamples(), 4 )
177 self.assertEqual( set(l.childNames()), set(["canHaveChildrenAtLinks",'instance0','instance1','instance2','branch1','branch2']) )
178 i0 = l.child("instance0")
179 self.assertEqual( i0.numBoundSamples(), 4 )
180 self.assertTrue( LinkedSceneTest.compareBBox( i0.readBoundAtSample(0), imath.Box3d( imath.V3d( -1,-1,-1 ), imath.V3d( 2,2,1 ) ) ) )
181 self.assertTrue( LinkedSceneTest.compareBBox( i0.readBoundAtSample(1), imath.Box3d( imath.V3d( -1,-1,-1 ), imath.V3d( 3,3,1 ) ) ) )
182 self.assertTrue( LinkedSceneTest.compareBBox( i0.readBoundAtSample(2), imath.Box3d( imath.V3d( -2,-1,-2 ), imath.V3d( 4,5,2 ) ) ) )
183 self.assertTrue( LinkedSceneTest.compareBBox( i0.readBoundAtSample(3), imath.Box3d( imath.V3d( -3,-1,-3 ), imath.V3d( 4,6,3 ) ) ) )
184 self.assertTrue( LinkedSceneTest.compareBBox( i0.readBound(0), imath.Box3d( imath.V3d( -1,-1,-1 ), imath.V3d( 2,2,1 ) ) ) )
185
186 A = i0.child("A")
187 self.assertTrue( LinkedSceneTest.compareBBox( A.readBoundAtSample(0), imath.Box3d(imath.V3d( -1,-1,-1 ), imath.V3d( 1,1,1 ) ) ) )
188 self.assertTrue( LinkedSceneTest.compareBBox( A.readBoundAtSample(1), imath.Box3d(imath.V3d( -1,-1,-1 ), imath.V3d( 1,1,1 ) ) ) )
189 self.assertTrue( LinkedSceneTest.compareBBox( A.readBoundAtSample(2), imath.Box3d(imath.V3d( 0,-1,-1 ), imath.V3d( 2,1,1 ) ) ) )
190 self.assertEqual( i0.readTransform( 0 ), IECore.M44dData( imath.M44d() ) )
191
192 i1 = l.child("instance1")
193 self.assertEqual( i1.numBoundSamples(), 4 )
194 self.assertTrue( LinkedSceneTest.compareBBox( i1.readBoundAtSample(0), imath.Box3d( imath.V3d( -1,-1,-1 ), imath.V3d( 2,2,1 ) ) ) )
195 self.assertTrue( LinkedSceneTest.compareBBox( i1.readBoundAtSample(2), imath.Box3d( imath.V3d( -2,-1,-2 ), imath.V3d( 4,5,2 ) ) ) )
196 self.assertTrue( LinkedSceneTest.compareBBox( i1.readBoundAtSample(3), imath.Box3d( imath.V3d( -3,-1,-3 ), imath.V3d( 4,6,3 ) ) ) )
197 self.assertTrue( LinkedSceneTest.compareBBox( i1.readBound(0), imath.Box3d( imath.V3d( -1,-1,-1 ), imath.V3d( 2,2,1 ) ) ) )
198 self.assertEqual( i1.readTransform( 0 ), IECore.M44dData( imath.M44d().translate( imath.V3d( 1, 0, 0 ) ) ) )

Callers

nothing calls this directly

Calls 15

childMethod · 0.95
createChildMethod · 0.95
numBoundSamplesMethod · 0.95
childNamesMethod · 0.95
childMethod · 0.95
hasTagMethod · 0.95
sceneMethod · 0.95
joinMethod · 0.80
SceneCacheMethod · 0.80
LinkedSceneMethod · 0.80
writeLinkMethod · 0.80
writeAttributeMethod · 0.45

Tested by

no test coverage detected