Skip to content

Commit

Permalink
Fix unit test failures on older UFE versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
JGamache-autodesk committed Nov 23, 2022
1 parent db2cd33 commit 1f218c2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
11 changes: 3 additions & 8 deletions test/lib/ufe/testBatchOpsHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,16 @@ def testUfeDuplicateRelationships(self):
self.assertIsNotNone(batchOpsHandler)

# Duplicating without batching means the new plane will not see the new material:
dGeom = ufe.SceneItemOps.sceneItemOps(geomItem).duplicateItemCmdNoExecute()
dGeom.execute()
dGeom = ufe.SceneItemOps.sceneItemOps(geomItem).duplicateItemCmd()
dMat = ufe.SceneItemOps.sceneItemOps(matItem).duplicateItemCmd()

dGeomPrim = usdUtils.getPrimFromSceneItem(dGeom.sceneItem)
self.assertEqual(dGeomPrim.GetPath(), Sdf.Path("/pPlane7"))
dGeomPrim = usdUtils.getPrimFromSceneItem(dGeom.item)
dGeomBindAPI = UsdShade.MaterialBindingAPI(dGeomPrim)
# Points to original ss3SG, we would like ss3SG1
self.assertEqual(dGeomBindAPI.GetDirectBinding().GetMaterialPath(), Sdf.Path("/mtl/ss3SG"))

dMat.undoableCommand.undo()
dGeom.undo()

undoneGeomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNone(undoneGeomItem)
dGeom.undoableCommand.undo()

sel = ufe.Selection()
sel.append(geomItem)
Expand Down
66 changes: 66 additions & 0 deletions test/lib/ufe/testDuplicateCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import ufe

import unittest
import os

def firstSubLayer(context, routingData):
prim = context.get('prim')
Expand Down Expand Up @@ -399,5 +400,70 @@ def testEditRouter(self):
self.assertIsNotNone(sublayer01)
self.assertIsNotNone(sublayer01.GetPrimAtPath('/A1/B'))

@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '4041', 'Test only available in UFE preview version 0.4.41 and greater')
def testUfeDuplicateCommandAPI(self):
'''Test that the duplicate command can be invoked using the 3 known APIs.'''

testFile = testUtils.getTestScene('MaterialX', 'BatchOpsTestScene.usda')
shapeNode,shapeStage = mayaUtils.createProxyFromFile(testFile)

geomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNotNone(geomItem)

# Test NoExecute API:
duplicateCmd = ufe.SceneItemOps.sceneItemOps(geomItem).duplicateItemCmdNoExecute()
self.assertIsNotNone(duplicateCmd)
duplicateCmd.execute()

duplicateItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNotNone(duplicateItem)
self.assertEqual(duplicateItem, duplicateCmd.sceneItem)

duplicateCmd.undo()

nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNone(nonExistentItem)

duplicateCmd.redo()

duplicateItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNotNone(duplicateItem)
self.assertEqual(duplicateItem, duplicateCmd.sceneItem)

duplicateCmd.undo()

# Test Exec but undoable API:
duplicateCmd = ufe.SceneItemOps.sceneItemOps(geomItem).duplicateItemCmd()
self.assertIsNotNone(duplicateCmd)

duplicateItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNotNone(duplicateItem)
self.assertEqual(duplicateItem, duplicateCmd.item)

duplicateCmd.undoableCommand.undo()

nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNone(nonExistentItem)

duplicateCmd.undoableCommand.redo()

duplicateItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNotNone(duplicateItem)
self.assertEqual(duplicateItem, duplicateCmd.item)

duplicateCmd.undoableCommand.undo()

# Test non-undoable API:
geomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNotNone(geomItem)

duplicatedItem = ufe.SceneItemOps.sceneItemOps(geomItem).duplicateItem()
self.assertIsNotNone(duplicateCmd)

plane7Item = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNotNone(plane7Item)
self.assertEqual(plane7Item, duplicatedItem)


if __name__ == '__main__':
unittest.main(verbosity=2)
1 change: 1 addition & 0 deletions test/lib/ufe/testRename.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ def testPaths(self, shapeStage, cubeName):

testPaths(self, shapeStage, "pCube1")

@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '4041', 'Test only available in UFE preview version 0.4.41 and greater')
def testUfeRenameCommandAPI(self):
'''Test that the rename command can be invoked using the 3 known APIs.'''

Expand Down

0 comments on commit 1f218c2

Please sign in to comment.