From a95b06260fd9b9e8376f6ff3f17c5b4cedfde638 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 31 Jul 2020 18:12:39 -0700 Subject: [PATCH 1/5] [mayaUsd] load Plug libraries when finding and loading in the registry This change ensures that even if a Plug plugin does not identify a Maya plugin to be loaded in the "mayaPlugin" field, we still instruct the Plug library to load its plugin, since doing so might be required to cause readers/writers/adapters/etc. to register. This became problematic after some restructuring of the maya-usd repo such that the translator code was moved under lib/usd/translators, which though it is still considered "core" mayaUsd, it is built as a separate component library. Simply importing mayaUsd in Python does *not* cause that library to be loaded, but loading the pxrUsd Maya plugin does. The prim writers and readers are still identified in the plugInfo.json, but there is no longer a pxrUsdTranslators plugin on the Maya side that goes with them. This manifested as UsdMayaAdaptors not working in Python unless you specifically loaded the pxrUsd plugin beforehand. With this change, that shouldn't be necessary. To verify this, the loadPlugin("pxrUsd") command was removed from the testUsdMayaAdaptor test to make sure that the library is loaded correctly through the registry discovery mechanism. The one gotcha here is that the undo/redo test *does* depend on the pxrUsd plugin being loaded because the adaptors can be used with or without undo support, and it is only available when the plugin *is* loaded. To deal with that, the undo/redo test was just moved into its own test script rather than trying to carefully control when the plugin gets loaded and having to ensure that the suite of tests run in a specific order. (Internal change: 2088800) --- lib/mayaUsd/fileio/registryHelper.cpp | 9 ++- plugin/pxr/maya/lib/usdMaya/CMakeLists.txt | 13 +++ .../lib/usdMaya/testenv/testUsdMayaAdaptor.py | 41 +--------- .../testenv/testUsdMayaAdaptorUndoRedo.py | 80 +++++++++++++++++++ 4 files changed, 105 insertions(+), 38 deletions(-) create mode 100644 plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorUndoRedo.py diff --git a/lib/mayaUsd/fileio/registryHelper.cpp b/lib/mayaUsd/fileio/registryHelper.cpp index 324cedd41b..e5a7a61157 100644 --- a/lib/mayaUsd/fileio/registryHelper.cpp +++ b/lib/mayaUsd/fileio/registryHelper.cpp @@ -189,10 +189,17 @@ UsdMaya_RegistryHelper::FindAndLoadMayaPlug( } else { TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg( - "Found usdMaya plugin %s: %s = %s. No maya plugin.\n", + "Found %s usdMaya plugin %s: %s = %s. No maya plugin.\n", + plug->IsLoaded() ? "loaded" : "unloaded", plug->GetName().c_str(), _PluginDictScopeToDebugString(scope).c_str(), value.c_str()); + + // Make sure that the Plug plugin is loaded to ensure that the + // library is loaded in case it is a "library" type plugin with + // no accompanying Maya plugin. This is a noop if the plugin is + // already loaded. + plug->Load(); } break; } diff --git a/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt b/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt index 22d0c14ed3..7723593535 100644 --- a/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt +++ b/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt @@ -80,6 +80,7 @@ pxr_test_scripts( testenv/testUsdMayaAdaptor.py testenv/testUsdMayaAdaptorGeom.py testenv/testUsdMayaAdaptorMetadata.py + testenv/testUsdMayaAdaptorUndoRedo.py testenv/testUsdMayaBlockSceneModificationContext.py testenv/testUsdMayaDiagnosticDelegate.py testenv/testUsdMayaGetVariantSetSelections.py @@ -284,6 +285,18 @@ pxr_register_test(testUsdMayaAdaptorMetadata MAYA_APP_DIR=/maya_profile ) +pxr_register_test(testUsdMayaAdaptorUndoRedo + CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} + COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaAdaptorUndoRedo" + TESTENV testUsdMayaAdaptorUndoRedo + ENV + MAYA_PLUG_IN_PATH=${TEST_INSTALL_PREFIX}/maya/plugin + MAYA_SCRIPT_PATH=${TEST_INSTALL_PREFIX}/maya/lib/usd/usdMaya/resources + MAYA_DISABLE_CIP=1 + MAYA_NO_STANDALONE_ATEXIT=1 + MAYA_APP_DIR=/maya_profile +) + pxr_register_test(testUsdMayaBlockSceneModificationContext CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaBlockSceneModificationContext" diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py b/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py index 9fee5df3aa..6ceca172b7 100644 --- a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py +++ b/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py @@ -33,8 +33,11 @@ class testUsdMayaAdaptor(unittest.TestCase): @classmethod def setUpClass(cls): + # Note that we do *not* explicitly load any USD plugins in this test. + # We are testing that the Plug-based lookup mechanism correctly + # identifies and loads the necessary libraries when a schema adapter is + # requested. standalone.initialize('usd') - cmds.loadPlugin('pxrUsd') @classmethod def tearDownClass(cls): @@ -293,42 +296,6 @@ def testConcreteSchemaRegistrations(self): self.assertTrue( mayaUsdLib.Adaptor("TestParticles").GetSchema(UsdGeom.Points)) - def testUndoRedo(self): - """Tests that adaptors work with undo/redo.""" - cmds.file(new=True, force=True) - cmds.group(name="group1", empty=True) - adaptor = mayaUsdLib.Adaptor("group1") - self.assertEqual(adaptor.GetAppliedSchemas(), []) - - # Do a single operation, then undo, then redo. - adaptor.ApplySchema(UsdGeom.ModelAPI) - self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) - cmds.undo() - self.assertEqual(adaptor.GetAppliedSchemas(), []) - cmds.redo() - self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) - - # Do a compound operation, then undo, then redo. - cmds.undoInfo(openChunk=True) - adaptor.ApplySchema(UsdGeom.MotionAPI).CreateAttribute( - UsdGeom.Tokens.motionVelocityScale).Set(0.42) - self.assertEqual(adaptor.GetAppliedSchemas(), - ["GeomModelAPI", "MotionAPI"]) - self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( - UsdGeom.Tokens.motionVelocityScale).Get(), 0.42) - cmds.undoInfo(closeChunk=True) - cmds.undo() - self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) - self.assertFalse(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( - UsdGeom.Tokens.motionVelocityScale)) - self.assertIsNone(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( - UsdGeom.Tokens.motionVelocityScale).Get()) - cmds.redo() - self.assertEqual(adaptor.GetAppliedSchemas(), - ["GeomModelAPI", "MotionAPI"]) - self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( - UsdGeom.Tokens.motionVelocityScale).Get(), 0.42) - def testGetAttributeAliases(self): """Tests the GetAttributeAliases function.""" self.assertEqual( diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorUndoRedo.py b/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorUndoRedo.py new file mode 100644 index 0000000000..a4ab7c6122 --- /dev/null +++ b/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorUndoRedo.py @@ -0,0 +1,80 @@ +#!/pxrpythonsubst +# +# Copyright 2020 Pixar +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import mayaUsd.lib as mayaUsdLib + +from pxr import UsdGeom + +from maya import cmds +from maya import standalone + +import unittest + + +class testUsdMayaAdaptorUndoRedo(unittest.TestCase): + @classmethod + def setUpClass(cls): + standalone.initialize('usd') + + # We load the pxrUsd plugin here to ensure that the usdUndoHelperCmd + # has been registered. See the documentation on UsdMayaAdaptor for more + # detail. + cmds.loadPlugin('pxrUsd') + + @classmethod + def tearDownClass(cls): + standalone.uninitialize() + + def testUndoRedo(self): + """Tests that adaptors work with undo/redo.""" + cmds.file(new=True, force=True) + cmds.group(name="group1", empty=True) + adaptor = mayaUsdLib.Adaptor("group1") + self.assertEqual(adaptor.GetAppliedSchemas(), []) + + # Do a single operation, then undo, then redo. + adaptor.ApplySchema(UsdGeom.ModelAPI) + self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) + cmds.undo() + self.assertEqual(adaptor.GetAppliedSchemas(), []) + cmds.redo() + self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) + + # Do a compound operation, then undo, then redo. + cmds.undoInfo(openChunk=True) + adaptor.ApplySchema(UsdGeom.MotionAPI).CreateAttribute( + UsdGeom.Tokens.motionVelocityScale).Set(0.42) + self.assertEqual(adaptor.GetAppliedSchemas(), + ["GeomModelAPI", "MotionAPI"]) + self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( + UsdGeom.Tokens.motionVelocityScale).Get(), 0.42) + cmds.undoInfo(closeChunk=True) + cmds.undo() + self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) + self.assertFalse(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( + UsdGeom.Tokens.motionVelocityScale)) + self.assertIsNone(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( + UsdGeom.Tokens.motionVelocityScale).Get()) + cmds.redo() + self.assertEqual(adaptor.GetAppliedSchemas(), + ["GeomModelAPI", "MotionAPI"]) + self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( + UsdGeom.Tokens.motionVelocityScale).Get(), 0.42) + + +if __name__ == '__main__': + unittest.main(verbosity=2) From c56253f496488e3c0ce5647646e72ebc21460b74 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Wed, 5 Aug 2020 10:39:04 -0700 Subject: [PATCH 2/5] [fixturesUtils] create export/import command aliases only when loading mayaUsdPlugin If the plugin is not loaded, the mayaUSDExport and mayaUSDImport commands will not exist and AttributeErrors will be raised if we try to access them. --- test/lib/usd/translators/fixturesUtils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/lib/usd/translators/fixturesUtils.py b/test/lib/usd/translators/fixturesUtils.py index 4394412eb1..61cd4ce02e 100644 --- a/test/lib/usd/translators/fixturesUtils.py +++ b/test/lib/usd/translators/fixturesUtils.py @@ -29,9 +29,11 @@ def _setUpClass(modulePathName, loadPlugin): if loadPlugin: cmds.loadPlugin('mayaUsdPlugin', quiet=True) - # Monkey patch cmds so that usdExport and usdImport becomes aliases. - cmds.usdExport = cmds.mayaUSDExport - cmds.usdImport = cmds.mayaUSDImport + # Monkey patch cmds so that usdExport and usdImport becomes aliases. We + # *only* do this if we're loading the plugin, since otherwise the + # export/import commands will not exist. + cmds.usdExport = cmds.mayaUSDExport + cmds.usdImport = cmds.mayaUSDImport realPath = os.path.realpath(modulePathName) return os.path.split(realPath) From 39c4735671d2ac445fb4a34f6b02cfa33fbe615b Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Wed, 5 Aug 2020 09:54:20 -0700 Subject: [PATCH 3/5] migrate UsdMayaAdaptor tests from plugin/pxr/... to test/... --- plugin/pxr/maya/lib/usdMaya/CMakeLists.txt | 60 ------------------- test/lib/usd/translators/CMakeLists.txt | 4 ++ .../UsdMayaAdaptorGeomTest/UsdAttrs.usda | 0 .../UsdMayaAdaptorMetadataTest/UsdAttrs.usda | 0 .../usd/translators}/testUsdMayaAdaptor.py | 0 .../translators}/testUsdMayaAdaptorGeom.py | 0 .../testUsdMayaAdaptorMetadata.py | 0 .../testUsdMayaAdaptorUndoRedo.py | 0 8 files changed, 4 insertions(+), 60 deletions(-) rename {plugin/pxr/maya/lib/usdMaya/testenv => test/lib/usd/translators}/UsdMayaAdaptorGeomTest/UsdAttrs.usda (100%) rename {plugin/pxr/maya/lib/usdMaya/testenv => test/lib/usd/translators}/UsdMayaAdaptorMetadataTest/UsdAttrs.usda (100%) rename {plugin/pxr/maya/lib/usdMaya/testenv => test/lib/usd/translators}/testUsdMayaAdaptor.py (100%) rename {plugin/pxr/maya/lib/usdMaya/testenv => test/lib/usd/translators}/testUsdMayaAdaptorGeom.py (100%) rename {plugin/pxr/maya/lib/usdMaya/testenv => test/lib/usd/translators}/testUsdMayaAdaptorMetadata.py (100%) rename {plugin/pxr/maya/lib/usdMaya/testenv => test/lib/usd/translators}/testUsdMayaAdaptorUndoRedo.py (100%) diff --git a/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt b/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt index 7723593535..c564117036 100644 --- a/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt +++ b/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt @@ -77,10 +77,6 @@ pxr_test_scripts( testenv/testUsdImportAsAssemblies.py testenv/testUsdImportNestedAssemblyAnimation.py testenv/testUsdTranslateTypelessDefs.py - testenv/testUsdMayaAdaptor.py - testenv/testUsdMayaAdaptorGeom.py - testenv/testUsdMayaAdaptorMetadata.py - testenv/testUsdMayaAdaptorUndoRedo.py testenv/testUsdMayaBlockSceneModificationContext.py testenv/testUsdMayaDiagnosticDelegate.py testenv/testUsdMayaGetVariantSetSelections.py @@ -241,62 +237,6 @@ pxr_register_test(testUsdTranslateTypelessDefs MAYA_APP_DIR=/maya_profile ) -pxr_register_test(testUsdMayaAdaptor - CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} - COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaAdaptor" - TESTENV testUsdMayaAdaptor - ENV - MAYA_PLUG_IN_PATH=${TEST_INSTALL_PREFIX}/maya/plugin - MAYA_SCRIPT_PATH=${TEST_INSTALL_PREFIX}/maya/lib/usd/usdMaya/resources - MAYA_DISABLE_CIP=1 - MAYA_NO_STANDALONE_ATEXIT=1 - MAYA_APP_DIR=/maya_profile -) - -pxr_install_test_dir( - SRC testenv/UsdMayaAdaptorGeomTest - DEST testUsdMayaAdaptorGeom -) -pxr_register_test(testUsdMayaAdaptorGeom - CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} - COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaAdaptorGeom" - TESTENV testUsdMayaAdaptorGeom - ENV - MAYA_PLUG_IN_PATH=${TEST_INSTALL_PREFIX}/maya/plugin - MAYA_SCRIPT_PATH=${TEST_INSTALL_PREFIX}/maya/lib/usd/usdMaya/resources - MAYA_DISABLE_CIP=1 - MAYA_NO_STANDALONE_ATEXIT=1 - MAYA_APP_DIR=/maya_profile -) - -pxr_install_test_dir( - SRC testenv/UsdMayaAdaptorMetadataTest - DEST testUsdMayaAdaptorMetadata -) -pxr_register_test(testUsdMayaAdaptorMetadata - CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} - COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaAdaptorMetadata" - TESTENV testUsdMayaAdaptorMetadata - ENV - MAYA_PLUG_IN_PATH=${TEST_INSTALL_PREFIX}/maya/plugin - MAYA_SCRIPT_PATH=${TEST_INSTALL_PREFIX}/maya/lib/usd/usdMaya/resources - MAYA_DISABLE_CIP=1 - MAYA_NO_STANDALONE_ATEXIT=1 - MAYA_APP_DIR=/maya_profile -) - -pxr_register_test(testUsdMayaAdaptorUndoRedo - CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} - COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaAdaptorUndoRedo" - TESTENV testUsdMayaAdaptorUndoRedo - ENV - MAYA_PLUG_IN_PATH=${TEST_INSTALL_PREFIX}/maya/plugin - MAYA_SCRIPT_PATH=${TEST_INSTALL_PREFIX}/maya/lib/usd/usdMaya/resources - MAYA_DISABLE_CIP=1 - MAYA_NO_STANDALONE_ATEXIT=1 - MAYA_APP_DIR=/maya_profile -) - pxr_register_test(testUsdMayaBlockSceneModificationContext CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaBlockSceneModificationContext" diff --git a/test/lib/usd/translators/CMakeLists.txt b/test/lib/usd/translators/CMakeLists.txt index 2f72a68078..e99ef15559 100644 --- a/test/lib/usd/translators/CMakeLists.txt +++ b/test/lib/usd/translators/CMakeLists.txt @@ -51,6 +51,10 @@ set(TEST_SCRIPT_FILES testUsdExportImportRoundtripPreviewSurface.py testUsdImportSkeleton.py testUsdImportXforms.py + testUsdMayaAdaptor.py + testUsdMayaAdaptorGeom.py + testUsdMayaAdaptorMetadata.py + testUsdMayaAdaptorUndoRedo.py ) add_custom_target(${TARGET_NAME} ALL) diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/UsdMayaAdaptorGeomTest/UsdAttrs.usda b/test/lib/usd/translators/UsdMayaAdaptorGeomTest/UsdAttrs.usda similarity index 100% rename from plugin/pxr/maya/lib/usdMaya/testenv/UsdMayaAdaptorGeomTest/UsdAttrs.usda rename to test/lib/usd/translators/UsdMayaAdaptorGeomTest/UsdAttrs.usda diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/UsdMayaAdaptorMetadataTest/UsdAttrs.usda b/test/lib/usd/translators/UsdMayaAdaptorMetadataTest/UsdAttrs.usda similarity index 100% rename from plugin/pxr/maya/lib/usdMaya/testenv/UsdMayaAdaptorMetadataTest/UsdAttrs.usda rename to test/lib/usd/translators/UsdMayaAdaptorMetadataTest/UsdAttrs.usda diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py b/test/lib/usd/translators/testUsdMayaAdaptor.py similarity index 100% rename from plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py rename to test/lib/usd/translators/testUsdMayaAdaptor.py diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorGeom.py b/test/lib/usd/translators/testUsdMayaAdaptorGeom.py similarity index 100% rename from plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorGeom.py rename to test/lib/usd/translators/testUsdMayaAdaptorGeom.py diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorMetadata.py b/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py similarity index 100% rename from plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorMetadata.py rename to test/lib/usd/translators/testUsdMayaAdaptorMetadata.py diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorUndoRedo.py b/test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py similarity index 100% rename from plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorUndoRedo.py rename to test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py From ba66d66db355600f3ac037ddb64a09a9e289c365 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Wed, 5 Aug 2020 10:01:10 -0700 Subject: [PATCH 4/5] minor cleanup of Python imports in UsdMayaAdaptor tests --- test/lib/usd/translators/testUsdMayaAdaptor.py | 2 -- test/lib/usd/translators/testUsdMayaAdaptorGeom.py | 4 +++- test/lib/usd/translators/testUsdMayaAdaptorMetadata.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/lib/usd/translators/testUsdMayaAdaptor.py b/test/lib/usd/translators/testUsdMayaAdaptor.py index 6ceca172b7..6ca9bedc72 100644 --- a/test/lib/usd/translators/testUsdMayaAdaptor.py +++ b/test/lib/usd/translators/testUsdMayaAdaptor.py @@ -15,8 +15,6 @@ # limitations under the License. # -from pxr import UsdMaya - import mayaUsd.lib as mayaUsdLib from pxr import Sdf diff --git a/test/lib/usd/translators/testUsdMayaAdaptorGeom.py b/test/lib/usd/translators/testUsdMayaAdaptorGeom.py index 18bad08490..8c08152033 100644 --- a/test/lib/usd/translators/testUsdMayaAdaptorGeom.py +++ b/test/lib/usd/translators/testUsdMayaAdaptorGeom.py @@ -15,12 +15,14 @@ # limitations under the License. # +from pxr import Usd +from pxr import UsdGeom + from maya import cmds from maya import standalone import os import unittest -from pxr import Usd, UsdGeom class testUsdMayaAdaptorGeom(unittest.TestCase): diff --git a/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py b/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py index 98955c3bcc..a140809879 100644 --- a/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py +++ b/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py @@ -15,11 +15,11 @@ # limitations under the License. # +import mayaUsd.lib as mayaUsdLib + from pxr import Usd from pxr import UsdGeom -import mayaUsd.lib as mayaUsdLib - from maya import cmds from maya import standalone From ec6780a51d38b4c5c16ed4dad5085444fbaf038a Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Wed, 5 Aug 2020 10:18:57 -0700 Subject: [PATCH 5/5] use fixturesUtils in all UsdMayaAdaptor tests --- .../lib/usd/translators/testUsdMayaAdaptor.py | 4 ++- .../usd/translators/testUsdMayaAdaptorGeom.py | 8 +++-- .../translators/testUsdMayaAdaptorMetadata.py | 29 +++++++++---------- .../translators/testUsdMayaAdaptorUndoRedo.py | 11 ++++--- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/test/lib/usd/translators/testUsdMayaAdaptor.py b/test/lib/usd/translators/testUsdMayaAdaptor.py index 6ca9bedc72..bafb31f227 100644 --- a/test/lib/usd/translators/testUsdMayaAdaptor.py +++ b/test/lib/usd/translators/testUsdMayaAdaptor.py @@ -27,6 +27,8 @@ import unittest +import fixturesUtils + class testUsdMayaAdaptor(unittest.TestCase): @classmethod @@ -35,7 +37,7 @@ def setUpClass(cls): # We are testing that the Plug-based lookup mechanism correctly # identifies and loads the necessary libraries when a schema adapter is # requested. - standalone.initialize('usd') + cls.inputPath = fixturesUtils.setUpClass(__file__, loadPlugin=False) @classmethod def tearDownClass(cls): diff --git a/test/lib/usd/translators/testUsdMayaAdaptorGeom.py b/test/lib/usd/translators/testUsdMayaAdaptorGeom.py index 8c08152033..ed0f6fedc4 100644 --- a/test/lib/usd/translators/testUsdMayaAdaptorGeom.py +++ b/test/lib/usd/translators/testUsdMayaAdaptorGeom.py @@ -24,6 +24,8 @@ import os import unittest +import fixturesUtils + class testUsdMayaAdaptorGeom(unittest.TestCase): @@ -33,10 +35,10 @@ def tearDownClass(cls): @classmethod def setUpClass(cls): - standalone.initialize('usd') - cmds.loadPlugin('pxrUsd') + cls.inputPath = fixturesUtils.setUpClass(__file__) - usdFile = os.path.abspath('UsdAttrs.usda') + usdFile = os.path.join(cls.inputPath, 'UsdMayaAdaptorGeomTest', + 'UsdAttrs.usda') cmds.usdImport(file=usdFile, shadingMode='none') def testImportImageable(self): diff --git a/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py b/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py index a140809879..d317664773 100644 --- a/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py +++ b/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py @@ -26,6 +26,8 @@ import os import unittest +import fixturesUtils + class testUsdMayaAdaptorMetadata(unittest.TestCase): @@ -35,8 +37,10 @@ def tearDownClass(cls): @classmethod def setUpClass(cls): - standalone.initialize('usd') - cmds.loadPlugin('pxrUsd') + cls.inputPath = fixturesUtils.setUpClass(__file__) + + cls.inputUsdFile = os.path.join(cls.inputPath, + 'UsdMayaAdaptorMetadataTest', 'UsdAttrs.usda') def testImport_HiddenInstanceableKind(self): """ @@ -44,8 +48,7 @@ def testImport_HiddenInstanceableKind(self): hidden, instanceable, and kind metadata properly. """ cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none') + cmds.usdImport(file=self.inputUsdFile, shadingMode='none') # pCube1 and pCube2 have USD_kind. self.assertEqual(cmds.getAttr('pCube1.USD_kind'), 'potato') @@ -74,8 +77,7 @@ def testImport_HiddenInstanceableKind(self): def testImport_HiddenInstanceable(self): """Tests import with only hidden, instanceable metadata and not kind.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', metadata=['hidden', 'instanceable']) # pCube1 and pCube2 have USD_kind, but that shouldn't be imported. @@ -97,8 +99,7 @@ def testImport_HiddenInstanceable(self): def testImport_TypeName(self): """Tests import with metadata=typeName manually specified.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', metadata=["typeName"]) # typeName metadata should come through. @@ -120,8 +121,7 @@ def testImport_TypeName(self): def testImport_GeomModelAPI(self): """Tests importing UsdGeomModelAPI attributes.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', apiSchema=['GeomModelAPI']) worldProxy = mayaUsdLib.Adaptor('World') @@ -154,8 +154,7 @@ def testExport(self): the correct metadata in the output USD file. """ cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none') + cmds.usdImport(file=self.inputUsdFile, shadingMode='none') newUsdFilePath = os.path.abspath('UsdAttrsNew.usda') cmds.usdExport(file=newUsdFilePath, shadingMode='none') @@ -185,8 +184,7 @@ def testExport(self): def testExport_GeomModelAPI(self): """Tests export with the GeomModelAPI.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', apiSchema=['GeomModelAPI']) newUsdFilePath = os.path.abspath('UsdAttrsNew_GeomModelAPI.usda') @@ -203,8 +201,7 @@ def testExport_GeomModelAPI(self): def testExport_GeomModelAPI_MotionAPI(self): """Tests export with both the GeomModelAPI and MotionAPI.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', apiSchema=['GeomModelAPI', 'MotionAPI']) newUsdFilePath = os.path.abspath('UsdAttrsNew_TwoAPIs.usda') diff --git a/test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py b/test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py index a4ab7c6122..30aaa33d50 100644 --- a/test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py +++ b/test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py @@ -24,16 +24,15 @@ import unittest +import fixturesUtils + class testUsdMayaAdaptorUndoRedo(unittest.TestCase): @classmethod def setUpClass(cls): - standalone.initialize('usd') - - # We load the pxrUsd plugin here to ensure that the usdUndoHelperCmd - # has been registered. See the documentation on UsdMayaAdaptor for more - # detail. - cmds.loadPlugin('pxrUsd') + # We load the plugin here to ensure that the usdUndoHelperCmd has been + # registered. See the documentation on UsdMayaAdaptor for more detail. + cls.inputPath = fixturesUtils.setUpClass(__file__, loadPlugin=True) @classmethod def tearDownClass(cls):