Skip to content

Commit

Permalink
Added unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
JGamache-autodesk committed Mar 22, 2023
1 parent 292dae3 commit fb516d2
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions test/lib/ufe/testContextOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ufeUtils
import testUtils
import mayaUsd
import mayaUsd_createStageWithNewLayer

from pxr import UsdGeom
from pxr import UsdShade
Expand Down Expand Up @@ -312,7 +313,6 @@ def testAddNewPrim(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create our UFE notification observer
Expand Down Expand Up @@ -416,7 +416,6 @@ def testAddNewPrimInWeakerLayer(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create our UFE notification observer
Expand Down Expand Up @@ -514,7 +513,6 @@ def testMaterialBinding(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create a ContextOps interface for the proxy shape.
Expand Down Expand Up @@ -585,7 +583,6 @@ def testMaterialCreationForSingleObject(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create a ContextOps interface for the proxy shape.
Expand Down Expand Up @@ -699,7 +696,6 @@ def testMaterialCreationForMultipleObjects(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create a ContextOps interface for the proxy shape.
Expand Down Expand Up @@ -847,7 +843,6 @@ def testMaterialCreationScopeName(self):
cmds.file(new=True, force=True)

# Helper function to create a new proxy shape.
import mayaUsd_createStageWithNewLayer
def createProxyShape():
proxyShapePathString = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
proxyShapePath = ufe.PathString.path(proxyShapePathString)
Expand Down Expand Up @@ -1038,7 +1033,6 @@ def testAddMaterialToScope(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create a ContextOps interface for the proxy shape.
Expand Down Expand Up @@ -1111,7 +1105,6 @@ def testMaterialBindingWithNodeDefHandler(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create a ContextOps interface for the proxy shape.
Expand Down Expand Up @@ -1191,7 +1184,6 @@ def testMaterialBindingToSelection(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create a ContextOps interface for the proxy shape.
Expand Down Expand Up @@ -1250,7 +1242,6 @@ def testAddNewPrimWithDelete(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create a ContextOps interface for the proxy shape.
Expand Down Expand Up @@ -1423,7 +1414,6 @@ def testAssignExistingMaterialToSingleObject(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create a ContextOps interface for the proxy shape.
Expand Down Expand Up @@ -1476,5 +1466,31 @@ def testAssignExistingMaterialToSingleObject(self):
cmds.undo()
self.assertFalse(capsulePrim.HasAPI(UsdShade.MaterialBindingAPI))

@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '4010', 'Test only available in UFE preview version 0.4.10 and greater')
@unittest.skipUnless(Usd.GetVersion() >= (0, 21, 8), 'Requires CanApplySchema from USD')
def testGeomCoponentAssignment(self):
'''Duplicate a Maya cube to USD and then assign a material on a face.'''

cubeXForm, _ = cmds.polyCube(name='MyCube')
psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

mayaUsd.lib.PrimUpdaterManager.duplicate(cmds.ls(cubeXForm, long=True)[0], psPathStr)

topPath = ufe.PathString.path(psPathStr + ',/' + cubeXForm + "/" + "top")
topItem = ufe.Hierarchy.createItem(topPath)
topSubset = UsdGeom.Subset(usdUtils.getPrimFromSceneItem(topItem))

self.assertEqual(topSubset.GetFamilyNameAttr().Get(), "componentTag")
self.assertFalse(topSubset.GetPrim().HasAPI(UsdShade.MaterialBindingAPI))

contextOps = ufe.ContextOps.contextOps(topItem)
cmd = contextOps.doOpCmd(['Assign New Material', 'USD', 'UsdPreviewSurface'])
self.assertIsNotNone(cmd)
ufeCmd.execute(cmd)

self.assertEqual(topSubset.GetFamilyNameAttr().Get(), "materialBind")
self.assertTrue(topSubset.GetPrim().HasAPI(UsdShade.MaterialBindingAPI))


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit fb516d2

Please sign in to comment.