Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edit router parent test. #2068

Merged
merged 3 commits into from
Feb 4, 2022

Conversation

ppt-adsk
Copy link
Collaborator

@ppt-adsk ppt-adsk commented Feb 3, 2022

No description provided.

@ppt-adsk ppt-adsk requested a review from boudrey February 3, 2022 18:55
@ppt-adsk ppt-adsk added the unit test Related to unit tests (both python or c++) label Feb 3, 2022
@@ -24,7 +24,6 @@

from pxr import Sdf, Tf

from functools import partial
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed dead code.

@@ -63,6 +63,9 @@ void UsdSetMatrix4dUndoableCommand::executeUndoBlock()
// transform stack, but not for a fallback Maya transform stack, and
// both can be edited by this command.
auto t3d = Ufe::Transform3d::editTransform3d(sceneItem());
if (!TF_VERIFY(t3d)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing nullptr check was causing crash.

// Return built-in default edit routers.
EditRouters editRouterDefaults();
EditRouters defaultEditRouters();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed for consistency. All other edit router-related functions end with the suffix "editRouter", so for familiarity renamed this one to match.

// the currently-registered edit router. Returns false if no such default
// exists.
MAYAUSD_CORE_PUBLIC
bool registerDefaultEditRouter(const PXR_NS::TfToken& operation);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a way to restore the default, which the testParentCmd must do, otherwise it leaves the mayapy process with the test edit router, which causes other parenting tests to fail.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we call it restoreDefaultEditRouter? I needed to read the understand what this method is supposed to do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me.


def childrenNames(children):
return [str(child.path().back()) for child in children]

def firstSubLayer(context, routingData):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into test itself.

layer = Sdf.Layer.Find(layerId)
# Make sure the destination exists in the target layer, otherwise
# SdfCopySpec will error.
Sdf.JustCreatePrimInLayer(layer, prim.GetPath())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the crucial change in the test: the destination layer is completely empty, but SdfCopySpec requires a destination prim. Just create an empty prim in the destination layer.

mayaUsd.lib.registerEditRouter('parent', firstSubLayer)

# Check that layer B is empty.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various test improvements: ensure the destination layer is empty before parenting, that it has the expected over's after parenting, etc.

'over "C"\n{\n def Xform "B"\n {\n }\n}')

# Restore default edit router.
mayaUsd.lib.registerDefaultEditRouter('parent')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore default edit router on test exit, otherwise other parenting tests will fail.

kxl-adsk
kxl-adsk previously approved these changes Feb 4, 2022
@@ -74,4 +74,9 @@ void wrapEditRouter()
return MayaUsd::registerEditRouter(
operation, std::make_shared<PyEditRouter>(editRouter));
});

def(
"restoreDefaultEditRouter", +[](const PXR_NS::TfToken& operation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just setting the address of the function to call instead of creating a lambda function that is calling the function directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite right! I just mindlessly copy-pasted the code above, there's no need for a lambda in this case, good catch.

boudrey
boudrey previously approved these changes Feb 4, 2022
@ppt-adsk ppt-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Feb 4, 2022
@kxl-adsk kxl-adsk merged commit e02e9ce into dev Feb 4, 2022
@kxl-adsk kxl-adsk deleted the tremblp/MAYA-121230/testParentCmd_edit_router branch February 4, 2022 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge unit test Related to unit tests (both python or c++)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants