Skip to content

Commit

Permalink
MAYA-128764 fixing unit tests.
Browse files Browse the repository at this point in the history
- Make sure undo/redo also are flagged as attribute-setting and not adding attributes.
- Fix expected count of add/set in the attribute unit test.
- Fix the UI node unit test.
  • Loading branch information
pierrebai-adsk committed Apr 24, 2023
1 parent f43855b commit 0ab4fee
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 29 deletions.
24 changes: 24 additions & 0 deletions lib/mayaUsd/ufe/UsdAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ class SetUndoableCommand : public MayaUsd::ufe::UsdUndoableCommand<Ufe::Undoable
{
}

void undo() override
{
MayaUsd::ufe::InSetAttribute inSetAttr;
MayaUsd::ufe::UsdUndoableCommand<Ufe::UndoableCommand>::undo();
}

void redo() override
{
MayaUsd::ufe::InSetAttribute inSetAttr;
MayaUsd::ufe::UsdUndoableCommand<Ufe::UndoableCommand>::redo();
}

protected:
void executeImplementation() override { _attr->set(_newValue); }

Expand All @@ -287,6 +299,18 @@ class SetUndoableMetadataCommand : public MayaUsd::ufe::UsdUndoableCommand<Ufe::
{
}

void undo() override
{
MayaUsd::ufe::InSetAttribute inSetAttr;
MayaUsd::ufe::UsdUndoableCommand<Ufe::UndoableCommand>::undo();
}

void redo() override
{
MayaUsd::ufe::InSetAttribute inSetAttr;
MayaUsd::ufe::UsdUndoableCommand<Ufe::UndoableCommand>::redo();
}

protected:
void executeImplementation() override
{
Expand Down
58 changes: 29 additions & 29 deletions test/lib/ufe/testAttribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,68 +1248,68 @@ def testObservationWithFineGrainedNotifications(self):
# "Props" and "Room_set". Ufe should be filtering out those notifications
# so the global observer should still only see one notification.
ufeCmd.execute(ball34XlateAttr.setCmd(ufe.Vector3d(4, 4, 15)))
ball34Obs.assertNotificationCount(self, numAdded = 1, numValue = 1)
ball34Obs.assertNotificationCount(self, numValue = 2)
ball35Obs.assertNotificationCount(self)
globalObs.assertNotificationCount(self, numAdded = 1, numValue = 1)
globalObs.assertNotificationCount(self, numValue = 2)

# The second modification only sends one USD notification for "xformOps:translate"
# because all the spec's already exist. Ufe should also see one notification.
ufeCmd.execute(ball34XlateAttr.setCmd(ufe.Vector3d(4, 4, 20)))
ball34Obs.assertNotificationCount(self, numAdded = 1, numValue = 2)
ball34Obs.assertNotificationCount(self, numValue = 3)
ball35Obs.assertNotificationCount(self)
globalObs.assertNotificationCount(self, numAdded = 1, numValue = 2)
globalObs.assertNotificationCount(self, numValue = 3)

# Undo, redo
cmds.undo()
ball34Obs.assertNotificationCount(self, numAdded = 1, numValue = 3)
ball34Obs.assertNotificationCount(self, numValue = 4)
ball35Obs.assertNotificationCount(self)
globalObs.assertNotificationCount(self, numAdded = 1, numValue = 3)
globalObs.assertNotificationCount(self, numValue = 4)

cmds.redo()
ball34Obs.assertNotificationCount(self, numAdded = 1, numValue = 4)
ball34Obs.assertNotificationCount(self, numValue = 5)
ball35Obs.assertNotificationCount(self)
globalObs.assertNotificationCount(self, numAdded = 1, numValue = 4)
globalObs.assertNotificationCount(self, numValue = 5)

# get ready to undo the first modification
cmds.undo()
ball34Obs.assertNotificationCount(self, numAdded = 1, numValue = 5)
ball34Obs.assertNotificationCount(self, numValue = 6)
ball35Obs.assertNotificationCount(self)
globalObs.assertNotificationCount(self, numAdded = 1, numValue = 5)
globalObs.assertNotificationCount(self, numValue = 6)

# Undo-ing the modification which created the USD specs is a little
# different in USD, but from Ufe we should just still see one notification.
cmds.undo()
ball34Obs.assertNotificationCount(self, numAdded = 1, numRemoved = 1, numValue = 5)
ball34Obs.assertNotificationCount(self, numRemoved = 1, numValue = 6)
ball35Obs.assertNotificationCount(self)
globalObs.assertNotificationCount(self, numAdded = 1, numRemoved = 1, numValue = 5)
globalObs.assertNotificationCount(self, numRemoved = 1, numValue = 6)

cmds.redo()
# Note that UsdUndoHelper add an attribute with its value in one shot, which results in a
# single AttributeAdded notification:
ball34Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 5)
ball34Obs.assertNotificationCount(self, numRemoved = 1, numValue = 7)
ball35Obs.assertNotificationCount(self)
globalObs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 5)
globalObs.assertNotificationCount(self, numRemoved = 1, numValue = 7)

# Make a change to ball35, global and ball35 observers change.
ball35Attrs = ufe.Attributes.attributes(ball35)
ball35XlateAttr = ball35Attrs.attribute('xformOp:translate')

# "xformOp:translate"
ufeCmd.execute(ball35XlateAttr.setCmd(ufe.Vector3d(4, 8, 15)))
ball34Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 5)
ball35Obs.assertNotificationCount(self, numAdded = 1, numValue = 1)
globalObs.assertNotificationCount(self, numAdded = 3, numRemoved = 1, numValue = 6)
ball34Obs.assertNotificationCount(self, numRemoved = 1, numValue = 7)
ball35Obs.assertNotificationCount(self, numValue = 2)
globalObs.assertNotificationCount(self, numRemoved = 1, numValue = 9)

# Undo, redo
cmds.undo()
ball34Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 5)
ball35Obs.assertNotificationCount(self, numAdded = 1, numRemoved = 1, numValue = 1)
globalObs.assertNotificationCount(self, numAdded = 3, numRemoved = 2, numValue = 6)
ball34Obs.assertNotificationCount(self, numRemoved = 1, numValue = 7)
ball35Obs.assertNotificationCount(self, numRemoved = 1, numValue = 2)
globalObs.assertNotificationCount(self, numRemoved = 2, numValue = 9)

cmds.redo()
ball34Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 5)
ball35Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 1)
globalObs.assertNotificationCount(self, numAdded = 4, numRemoved = 2, numValue = 6)
ball34Obs.assertNotificationCount(self, numRemoved = 1, numValue = 7)
ball35Obs.assertNotificationCount(self, numRemoved = 1, numValue = 3)
globalObs.assertNotificationCount(self, numRemoved = 2, numValue = 10)

# Test removeObserver.
ufe.Attributes.removeObserver(ball34, ball34Obs)
Expand All @@ -1322,19 +1322,19 @@ def testObservationWithFineGrainedNotifications(self):

ufeCmd.execute(ball34XlateAttr.setCmd(ufe.Vector3d(4, 4, 25)))

ball34Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 5)
ball35Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 1)
globalObs.assertNotificationCount(self, numAdded = 4, numRemoved = 2, numValue = 7)
ball34Obs.assertNotificationCount(self, numRemoved = 1, numValue = 7)
ball35Obs.assertNotificationCount(self, numRemoved = 1, numValue = 3)
globalObs.assertNotificationCount(self, numRemoved = 2, numValue = 11)

ufe.Attributes.removeObserver(globalObs)

self.assertEqual(ufe.Attributes.nbObservers(), kNbGlobalObs)

ufeCmd.execute(ball34XlateAttr.setCmd(ufe.Vector3d(7, 8, 9)))

ball34Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 5)
ball35Obs.assertNotificationCount(self, numAdded = 2, numRemoved = 1, numValue = 1)
globalObs.assertNotificationCount(self, numAdded = 4, numRemoved = 2, numValue = 7)
ball34Obs.assertNotificationCount(self, numRemoved = 1, numValue = 7)
ball35Obs.assertNotificationCount(self, numRemoved = 1, numValue = 3)
globalObs.assertNotificationCount(self, numRemoved = 2, numValue = 11)

def testAttrChangeRedoAfterPrimCreateRedo(self):
'''Redo attribute change after redo of prim creation.'''
Expand Down
7 changes: 7 additions & 0 deletions test/lib/ufe/testUINodeGraphNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,19 @@ def testPosition(self):
self.doPosAndSizeTests(uiNodeGraphNode.hasPosition, uiNodeGraphNode.setPosition,
uiNodeGraphNode.getPosition, uiNodeGraphNode.setPositionCmd)

# None of these changes should force a render refresh:
self.assertEqual(initialUpdateCount, cmds.getAttr('|transform1|proxyShape1.updateId'))
self.assertEqual(initialResyncCount, cmds.getAttr('|transform1|proxyShape1.resyncId'))

@unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '4100',
'Size interface only available in Ufe preview version greater equal to 4.0.100, or 0.5.0.')
def testSize(self):
ball3Path = ufe.PathString.path('|transform1|proxyShape1,/Ball_set/Props/Ball_3')
ball3SceneItem = ufe.Hierarchy.createItem(ball3Path)

initialUpdateCount = cmds.getAttr('|transform1|proxyShape1.updateId')
initialResyncCount = cmds.getAttr('|transform1|proxyShape1.resyncId')

if(hasattr(ufe, "UINodeGraphNode_v4_1")):
uiNodeGraphNode = ufe.UINodeGraphNode_v4_1.uiNodeGraphNode(ball3SceneItem)
else:
Expand Down

0 comments on commit 0ab4fee

Please sign in to comment.