diff --git a/lib/mayaUsd/fileio/utils/readUtil.cpp b/lib/mayaUsd/fileio/utils/readUtil.cpp index b2d2e12e9b..71489ed595 100644 --- a/lib/mayaUsd/fileio/utils/readUtil.cpp +++ b/lib/mayaUsd/fileio/utils/readUtil.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -150,6 +151,16 @@ _FindOrCreateMayaNumericAttr( attr.setUsedAsColor(true); } + const unsigned int numChildren = MFnCompoundAttribute(attrObj).numChildren(); + if(numChildren < 5u) { + static MString suffix[4] = {" X", " Y", " Z", " W"}; + for(unsigned int i = 0; i < numChildren; i++) { + MFnAttribute(attr.child(i)).setNiceNameOverride(niceName+suffix[i]); + } + } else { + TF_CODING_ERROR("Unexpected number of children on numeric attribute"); + } + modifier.addAttribute(depNode.object(), attrObj); modifier.doIt(); return attrObj; diff --git a/lib/mayaUsd/nodes/proxyAccessor.cpp b/lib/mayaUsd/nodes/proxyAccessor.cpp index f8c422e74e..c1c2e8f6c1 100644 --- a/lib/mayaUsd/nodes/proxyAccessor.cpp +++ b/lib/mayaUsd/nodes/proxyAccessor.cpp @@ -63,13 +63,13 @@ MAYAUSD_NS_DEF ); //! \brief Test if given plug name is matching the convention used by accessor plugs - bool isAccessorValuePlugName(const char* plugName) + bool isAccessorPlugName(const char* plugName) { - return (strncmp(plugName, "AccessValue_", 12) == 0); + return (strncmp(plugName, "AP_", 3) == 0); } //! \brief Returns True is given plug is categorized as input plug, or False if output plug - bool isAccessorValueInputPlug(const MPlug& plug) + bool isAccessorInputPlug(const MPlug& plug) { if (plug.isDestination()) return true; @@ -117,7 +117,7 @@ MAYAUSD_NS_DEF object, [](MNodeMessage::AttributeMessage msg, MPlug& plug, void* clientData) { if (clientData) { - if (isAccessorValuePlugName(plug.partialName().asChar())) { + if (isAccessorPlugName(plug.partialName().asChar())) { static_cast(clientData)->invalidateAccessorItems(); } } @@ -135,7 +135,7 @@ MAYAUSD_NS_DEF == 0) return; - if (isAccessorValuePlugName(plug.partialName().asChar())) { + if (isAccessorPlugName(plug.partialName().asChar())) { auto* accessor = static_cast(clientData); accessor->invalidateAccessorItems(); @@ -218,7 +218,7 @@ MAYAUSD_NS_DEF continue; MString name = attr.name(); - if (!isAccessorValuePlugName(name.asChar())) + if (!isAccessorPlugName(name.asChar())) continue; MPlug valuePlug(node, attr.object()); @@ -268,7 +268,7 @@ MAYAUSD_NS_DEF continue; } - if (isAccessorValueInputPlug(valuePlug)) { + if (isAccessorInputPlug(valuePlug)) { TF_DEBUG(USDMAYA_PROXYACCESSOR).Msg("Added INPUT '%s'\n", path.GetText()); _accessorInputItems.emplace_back(valuePlug, path, converter); } else { @@ -293,10 +293,10 @@ MAYAUSD_NS_DEF if (_accessorInputItems.size() == 0 && _accessorOutputItems.size() == 0) return MS::kUnknownParameter; - const bool accessorValuePlug = isAccessorValuePlugName(plug.partialName().asChar()); - const bool isInputValuePlug = accessorValuePlug && isAccessorValueInputPlug(plug); + const bool accessorPlug = isAccessorPlugName(plug.partialName().asChar()); + const bool isInputPlug = accessorPlug && isAccessorInputPlug(plug); - if (isInputValuePlug || !plug.isDynamic() || plug == _forceCompute) { + if (isInputPlug || !plug.isDynamic() || plug == _forceCompute) { TF_DEBUG(USDMAYA_PROXYACCESSOR) .Msg("Dirty all outputs from '%s'\n", plug.name().asChar()); diff --git a/lib/mayaUsd/nodes/proxyAccessor.py b/lib/mayaUsd/nodes/proxyAccessor.py index 3ae02cd11a..d8f6890a38 100644 --- a/lib/mayaUsd/nodes/proxyAccessor.py +++ b/lib/mayaUsd/nodes/proxyAccessor.py @@ -29,6 +29,7 @@ import maya.cmds as cmds import maya.OpenMaya as om import ufe +import re def getUfeSelection(): try: @@ -57,7 +58,7 @@ def getSelectedDagAndPrim(): return getDagAndPrimFromUfe(getUfeSelection()) def getAccessPlugName(sdfPath): - plugNameValueAttr = 'AccessValue_' + str(sdfPath.__hash__()) + plugNameValueAttr = 'AP_' + re.sub(r'[^a-zA-Z0-9_]',r'_',str(sdfPath)) return plugNameValueAttr diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5e8ca03f5c..823b2b9ce5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(lib) +add_subdirectory(testSamples) add_subdirectory(testUtils) diff --git a/test/lib/testMayaUsdProxyAccessor.py b/test/lib/testMayaUsdProxyAccessor.py index 7a7ddd15b3..f774959e9c 100644 --- a/test/lib/testMayaUsdProxyAccessor.py +++ b/test/lib/testMayaUsdProxyAccessor.py @@ -23,290 +23,18 @@ import maya.cmds as cmds +import usdUtils, mayaUtils, testUtils + +from cachingUtils import NonCachingScope, CachingScope +from ufeUtils import createUfeSceneItem, selectUfeItems +from mayaUtils import createProxyAndStage, createProxyFromFile, createAnimatedHierarchy + from mayaUsd import lib as mayaUsdLib from mayaUsd.lib import GetPrim from mayaUsd.lib import proxyAccessor as pa from pxr import Usd, UsdGeom, Sdf, Tf, Vt -from maya.debug.emModeManager import emModeManager -from maya.plugin.evaluator.CacheEvaluatorManager import CacheEvaluatorManager, CACHE_STANDARD_MODE_EVAL - -class NonCachingScope(object): - ''' - Scope object responsible for setting up non cached mode and restoring default settings after - ''' - def __enter__(self): - '''Enter the scope, setting up the evaluator managers and initial states''' - self.em_mgr = emModeManager() - self.em_mgr.setMode('emp') - self.em_mgr.setMode('-cache') - - return self - - def __init__(self, unit_test): - '''Initialize everything to be empty - only use the "with" syntax with this object''' - self.em_mgr = None - self.unit_test = unit_test - - def __exit__(self,exit_type,value,traceback): - '''Exit the scope, restoring all of the state information''' - if self.em_mgr: - self.em_mgr.restore_state() - self.em_mgr = None - - def verifyScopeSetup(self): - ''' - Meta-test to check that the scope was defined correctly - :param unit_test: The test object from which this method was called - ''' - self.unit_test.assertTrue( cmds.evaluationManager( mode=True, query=True )[0] == 'parallel' ) - if cmds.pluginInfo('cacheEvaluator', loaded=True, query=True): - self.unit_test.assertFalse( cmds.evaluator( query=True, en=True, name='cache' ) ) - - def checkValidFrames(self, expected_valid_frames, layers_mask = 0b01): - return True - - def waitForCache(self, wait_time=5): - return - - @staticmethod - def is_caching_scope(): - ''' - Method to determine whether caching is on or off in this object's scope - :return: False, since this is the non-caching scope - ''' - return False - -class CachingScope(object): - ''' - Scope object responsible for setting up caching and restoring original setup after - ''' - def __enter__(self): - '''Enter the scope, setting up the evaluator managers and initial states''' - self.em_mgr = emModeManager() - self.em_mgr.setMode('emp') - self.em_mgr.setMode('+cache') - # Enable idle build to make sure we can rebuild the graph when waiting. - self.em_mgr.idle_action = emModeManager.idle_action_build - - # Setup caching options - self.cache_mgr = CacheEvaluatorManager() - self.cache_mgr.save_state() - self.cache_mgr.plugin_loaded = True - self.cache_mgr.enabled = True - self.cache_mgr.cache_mode = CACHE_STANDARD_MODE_EVAL - self.cache_mgr.resource_guard = False - self.cache_mgr.fill_mode = 'syncAsync' - - # Setup autokey options - self.auto_key_state = cmds.autoKeyframe(q=True, state=True) - self.auto_key_chars = cmds.autoKeyframe(q=True, characterOption=True) - cmds.autoKeyframe(e=True, state=False) - - self.waitForCache() - - return self - - def __init__(self, unit_test): - '''Initialize everything to be empty - only use the "with" syntax with this object''' - self.em_mgr = None - self.cache_mgr = None - self.auto_key_state = None - self.auto_key_chars = None - self.unit_test = unit_test - - def __exit__(self,exit_type,value,traceback): - '''Exit the scope, restoring all of the state information''' - if self.cache_mgr: - self.cache_mgr.restore_state() - if self.em_mgr: - self.em_mgr.restore_state() - cmds.autoKeyframe(e=True, state=self.auto_key_state, characterOption=self.auto_key_chars) - - def verifyScopeSetup(self): - ''' - Meta-test to check that the scope was defined correctly - :param unit_test: The test object from which this method was called - ''' - self.unit_test.assertTrue( cmds.evaluationManager( mode=True, query=True )[0] == 'parallel' ) - self.unit_test.assertTrue( cmds.pluginInfo('cacheEvaluator', loaded=True, query=True) ) - self.unit_test.assertTrue( cmds.evaluator( query=True, en=True, name='cache' ) ) - - def checkValidFrames(self, expected_valid_frames, layers_mask = 0b01): - ''' - :param unit_test: The test object from which this method was called - :param expected_valid_frames: The list of frames the text expected to be cached - :return: True if the cached frame list matches the expected frame list - ''' - current_valid_frames = list(self.cache_mgr.get_valid_frames(layers_mask)) - if len(expected_valid_frames) == len(current_valid_frames): - for current, expected in zip(current_valid_frames,expected_valid_frames): - if current[0] != expected[0] or current[1] != expected[1]: - self.unit_test.fail( "{} != {} (current,expected)".format( current_valid_frames, expected_valid_frames) ) - return False - - return True - self.unit_test.fail( "{} != {} (current,expected)".format( current_valid_frames, expected_valid_frames) ) - return False - - def waitForCache(self, wait_time=5): - ''' - Fill the cache in the background, waiting for a maximum time - :param unit_test: The test object from which this method was called - :param wait_time: Time the test is willing to wait for cache completion (in seconds) - ''' - cmds.currentTime( cmds.currentTime(q=True) ) - cmds.currentTime( cmds.currentTime(q=True) ) - cache_is_ready = cmds.cacheEvaluator( waitForCache=wait_time ) - self.unit_test.assertTrue( cache_is_ready ) - - @staticmethod - def is_caching_scope(): - ''' - Method to determine whether caching is on or off in this object's scope - :return: True, since this is the caching scope - ''' - return True - -def isPluginLoaded(pluginName): - """ - Verifies that the given plugin is loaded - Args: - pluginName (str): The plugin name to verify - Returns: - True if the plugin is loaded. False if a plugin failed to load - """ - return cmds.pluginInfo( pluginName, loaded=True, query=True) - -def loadPlugin(pluginName): - """ - Load all given plugins created or needed by maya-ufe-plugin - Args: - pluginName (str): The plugin name to load - Returns: - True if all plugins are loaded. False if a plugin failed to load - """ - try: - if not isPluginLoaded(pluginName): - cmds.loadPlugin( pluginName, quiet = True ) - return True - except: - print(sys.exc_info()[1]) - print("Unable to load %s" % pluginName) - return False - -def isMayaUsdPluginLoaded(): - """ - Load plugins needed by tests. - Returns: - True if plugins loaded successfully. False if a plugin failed to load - """ - # Load the mayaUsdPlugin first. - if not loadPlugin("mayaUsdPlugin"): - return False - - # Load the UFE support plugin, for ufeSelectCmd support. If this plugin - # isn't included in the distribution of Maya (e.g. Maya 2019 or 2020), use - # fallback test plugin. - if not (loadPlugin("ufeSupport") or loadPlugin("ufeTestCmdsPlugin")): - return False - - # The renderSetup Python plugin registers a file new callback to Maya. On - # test application exit (in TbaseApp::cleanUp()), a file new is done and - # thus the file new callback is invoked. Unfortunately, this occurs after - # the Python interpreter has been finalized, which causes a crash. Since - # renderSetup is not needed for mayaUsd tests, unload it. - rs = 'renderSetup' - if cmds.pluginInfo(rs, q=True, loaded=True): - unloaded = cmds.unloadPlugin(rs) - return (unloaded[0] == rs) - - return True - -def makeUfePath(dagPath, sdfPath=None): - """ - Make ufe item out of dag path and sdfpath - """ - ufePath = ufe.PathString.path('{},{}'.format(dagPath,sdfPath) if sdfPath != None else '{}'.format(dagPath)) - ufeItem = ufe.Hierarchy.createItem(ufePath) - return ufeItem - -def selectUfeItems(selectItems): - """ - Add given UFE item or list of items to a UFE global selection list - """ - ufeSelectionList = ufe.Selection() - - realListToSelect = selectItems if type(selectItems) is list else [selectItems] - for item in realListToSelect: - ufeSelectionList.append(item) - - ufe.GlobalSelection.get().replaceWith(ufeSelectionList) - -def createProxyAndStage(): - """ - Create in-memory stage - """ - cmds.createNode('mayaUsdProxyShape', name='stageShape') - - shapeNode = cmds.ls(sl=True,l=True)[0] - shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage() - - cmds.select( clear=True ) - cmds.connectAttr('time1.outTime','{}.time'.format(shapeNode)) - - return shapeNode,shapeStage - -def createProxyFromFile(filePath): - """ - Load stage from file - """ - cmds.createNode('mayaUsdProxyShape', name='stageShape') - - shapeNode = cmds.ls(sl=True,l=True)[0] - cmds.setAttr('{}.filePath'.format(shapeNode), filePath, type='string') - - shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage() - - cmds.select( clear=True ) - cmds.connectAttr('time1.outTime','{}.time'.format(shapeNode)) - - return shapeNode,shapeStage - -def createAnimatedHierarchy(stage): - """ - Create simple hierarchy in the stage: - /ParentA - /Sphere - /Cube - /ParenB - - Entire ParentA hierarchy will receive time samples on translate for time 1 and 100 - """ - parentA = "/ParentA" - parentB = "/ParentB" - childSphere = "/ParentA/Sphere" - childCube = "/ParentA/Cube" - - parentPrimA = stage.DefinePrim(parentA, 'Xform') - parentPrimB = stage.DefinePrim(parentB, 'Xform') - childPrimSphere = stage.DefinePrim(childSphere, 'Sphere') - childPrimCube = stage.DefinePrim(childCube, 'Cube') - - UsdGeom.XformCommonAPI(parentPrimA).SetRotate((0,0,0)) - UsdGeom.XformCommonAPI(parentPrimB).SetTranslate((1,10,0)) - - time1 = Usd.TimeCode(1.) - UsdGeom.XformCommonAPI(parentPrimA).SetTranslate((0,0,0),time1) - UsdGeom.XformCommonAPI(childPrimSphere).SetTranslate((5,0,0),time1) - UsdGeom.XformCommonAPI(childPrimCube).SetTranslate((0,0,5),time1) - - time2 = Usd.TimeCode(100.) - UsdGeom.XformCommonAPI(parentPrimA).SetTranslate((0,5,0),time2) - UsdGeom.XformCommonAPI(childPrimSphere).SetTranslate((-5,0,0),time2) - UsdGeom.XformCommonAPI(childPrimCube).SetTranslate((0,0,-5),time2) - class MayaUsdProxyAccessorTestCase(unittest.TestCase): """ Verify mayaUsd ProxyAccessor. @@ -324,7 +52,7 @@ def setUpClass(cls): Load mayaUsdPlugin on class initialization (before any test is executed) """ if not cls.pluginsLoaded: - cls.pluginsLoaded = isMayaUsdPluginLoaded() + cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded() # Useful for debugging accessor #Tf.Debug.SetDebugSymbolsByName("USDMAYA_PROXYACCESSOR", 1) @@ -381,8 +109,8 @@ def validateOutput(self,cachingScope): nodeDagPath, stage = createProxyFromFile(self.testAnimatedHierarchyUsdFile) # Get UFE items - ufeParentItemA = makeUfePath(nodeDagPath,'/ParentA') - ufeChildItemSphere = makeUfePath(nodeDagPath,'/ParentA/Sphere') + ufeParentItemA = createUfeSceneItem(nodeDagPath,'/ParentA') + ufeChildItemSphere = createUfeSceneItem(nodeDagPath,'/ParentA/Sphere') # Create accessor plugs worldMatrixPlugA = pa.getOrCreateAccessPlug(ufeParentItemA, '', Sdf.ValueTypeNames.Matrix4d ) @@ -418,7 +146,7 @@ def validateOutputForInMemoryRootLayer(self,cachingScope): createAnimatedHierarchy(stage) # Get UFE items - ufeParentItemA = makeUfePath(nodeDagPath,'/ParentA') + ufeParentItemA = createUfeSceneItem(nodeDagPath,'/ParentA') # Create accessor plugs worldMatrixPlugA = pa.getOrCreateAccessPlug(ufeParentItemA, '', Sdf.ValueTypeNames.Matrix4d ) @@ -447,7 +175,7 @@ def validateTransformedOutput(self,cachingScope): cmds.setKeyframe( '{}.ry'.format(transform), time=100.0, value=90 ) # Get UFE items - ufeItemSphere = makeUfePath(nodeDagPath,'/ParentA/Sphere') + ufeItemSphere = createUfeSceneItem(nodeDagPath,'/ParentA/Sphere') worldMatrixPlugSphere = pa.getOrCreateAccessPlug(ufeItemSphere, '', Sdf.ValueTypeNames.Matrix4d ) cachingScope.waitForCache() @@ -471,9 +199,9 @@ def validateInput(self, cachingScope): nodeDagPath, stage = createProxyFromFile(self.testAnimatedHierarchyUsdFile) # Get UFE items - ufeItemParent = makeUfePath(nodeDagPath,'/ParentA') - ufeItemSphere = makeUfePath(nodeDagPath,'/ParentA/Sphere') - ufeItemCube = makeUfePath(nodeDagPath,'/ParentA/Cube') + ufeItemParent = createUfeSceneItem(nodeDagPath,'/ParentA') + ufeItemSphere = createUfeSceneItem(nodeDagPath,'/ParentA/Sphere') + ufeItemCube = createUfeSceneItem(nodeDagPath,'/ParentA/Cube') # Create accessor plugs translatePlugParent = pa.getOrCreateAccessPlug(ufeItemParent, usdAttrName='xformOp:translate') @@ -527,8 +255,8 @@ def validateParentingDagObjectUnderUsdPrim(self, cachingScope): cmds.setAttr('{}.ty'.format(childNodeDagPath), 3) # Get UFE items - ufeItemSphere = makeUfePath(nodeDagPath,'/ParentA/Sphere') - ufeItemChild = makeUfePath(childNodeDagPath) + ufeItemSphere = createUfeSceneItem(nodeDagPath,'/ParentA/Sphere') + ufeItemChild = createUfeSceneItem(childNodeDagPath) # Parent pa.parentItems([ufeItemChild],ufeItemSphere) @@ -560,10 +288,10 @@ def validateSerialization(self,fileName, fileType): cmds.setAttr('{}.ty'.format(locatorNodeDagPath), 3) # Get UFE items - ufeItemParent = makeUfePath(nodeDagPath,'/ParentA') - ufeItemSphere = makeUfePath(nodeDagPath,'/ParentA/Sphere') - ufeItemCube = makeUfePath(nodeDagPath,'/ParentA/Cube') - ufeItemLocator = makeUfePath(locatorNodeDagPath) + ufeItemParent = createUfeSceneItem(nodeDagPath,'/ParentA') + ufeItemSphere = createUfeSceneItem(nodeDagPath,'/ParentA/Sphere') + ufeItemCube = createUfeSceneItem(nodeDagPath,'/ParentA/Cube') + ufeItemLocator = createUfeSceneItem(locatorNodeDagPath) translatePlugParent = pa.getOrCreateAccessPlug(ufeItemParent, usdAttrName='xformOp:translate') rotatePlugParent = pa.getOrCreateAccessPlug(ufeItemParent, usdAttrName='xformOp:rotateXYZ') @@ -624,7 +352,7 @@ def validatePassivelyAffectedReset(self, cachingScope): nodeDagPath, stage = createProxyFromFile(self.testAnimatedHierarchyUsdFile) # Get UFE item and select it - ufeItemParent = makeUfePath(nodeDagPath,'/ParentA') + ufeItemParent = createUfeSceneItem(nodeDagPath,'/ParentA') selectUfeItems(ufeItemParent) # We are going to manipulate animated prim. Let's make sure this opinion can be authored @@ -697,7 +425,7 @@ def validateDagManipulation(self,cachingScope): transform = cmds.listRelatives(nodeDagPath,parent=True)[0] # Get UFE items - ufeItemSphere = makeUfePath(nodeDagPath,'/ParentA/Sphere') + ufeItemSphere = createUfeSceneItem(nodeDagPath,'/ParentA/Sphere') worldMatrixPlugSphere = pa.getOrCreateAccessPlug(ufeItemSphere, '', Sdf.ValueTypeNames.Matrix4d ) cachingScope.waitForCache() @@ -742,7 +470,7 @@ def validateKeyframeWithCommands(self, cachingScope): nodeDagPath, stage = createProxyFromFile(self.testAnimatedHierarchyUsdFile) # Get UFE item and select it - ufeItemParent = makeUfePath(nodeDagPath,'/ParentA') + ufeItemParent = createUfeSceneItem(nodeDagPath,'/ParentA') selectUfeItems(ufeItemParent) # We are going to manipulate animated prim. Let's make sure this opinion can be authored @@ -827,7 +555,7 @@ def validateKeyframeWithUFE(self, cachingScope): nodeDagPath, stage = createProxyFromFile(self.testAnimatedHierarchyUsdFile) # Get UFE item and select it - ufeItemParent = makeUfePath(nodeDagPath,'/ParentA') + ufeItemParent = createUfeSceneItem(nodeDagPath,'/ParentA') # Current limitation requires access plugs to be created before we start manipulating and keying translatePlug = pa.getOrCreateAccessPlug(ufeItemParent, usdAttrName='xformOp:translate') @@ -913,7 +641,7 @@ def validateKeyframeWithUSD(self, cachingScope): nodeDagPath, stage = createProxyFromFile(self.testAnimatedHierarchyUsdFile) # Get UFE item and select it - ufeItemParent = makeUfePath(nodeDagPath,'/ParentA') + ufeItemParent = createUfeSceneItem(nodeDagPath,'/ParentA') path = Sdf.Path('/ParentA') usdPrim = stage.GetPrimAtPath(path) @@ -1005,9 +733,9 @@ def validateDisconnect(self, cachingScope): cmds.setKeyframe( '{}.tz'.format(srcLocatorDagPath), time=100.0, value=10.0) # Get UFE items - ufeItemParent = makeUfePath(nodeDagPath,'/ParentA') - ufeItemSphere = makeUfePath(nodeDagPath,'/ParentA/Sphere') - ufeItemSrcLocator = makeUfePath(srcLocatorDagPath) + ufeItemParent = createUfeSceneItem(nodeDagPath,'/ParentA') + ufeItemSphere = createUfeSceneItem(nodeDagPath,'/ParentA/Sphere') + ufeItemSrcLocator = createUfeSceneItem(srcLocatorDagPath) # Create accessor plugs translatePlugParent = pa.getOrCreateAccessPlug(ufeItemParent, usdAttrName='xformOp:translate') @@ -1064,7 +792,7 @@ def Cube "pCube1" ( ''') # Get UFE items - ufeItem = makeUfePath(nodeDagPath,'/pCube1') + ufeItem = createUfeSceneItem(nodeDagPath,'/pCube1') # Create accessor plugs matrixPlug = pa.getOrCreateAccessPlug(ufeItem, usdAttrName='xformOp:transform:offset') diff --git a/test/lib/ufe/testAttribute.py b/test/lib/ufe/testAttribute.py index b3e345eaf3..512dbdca71 100644 --- a/test/lib/ufe/testAttribute.py +++ b/test/lib/ufe/testAttribute.py @@ -16,8 +16,7 @@ # limitations under the License. # -from ufeTestUtils import usdUtils, mayaUtils -import ufeTestUtils.testUtils +import usdUtils, mayaUtils, testUtils import ufe from pxr import UsdGeom import random @@ -51,7 +50,7 @@ def setUpClass(cls): if not cls.pluginsLoaded: cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded() - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() random.seed() @@ -66,7 +65,7 @@ def setUp(self): self.assertTrue(self.pluginsLoaded) def assertVectorAlmostEqual(self, ufeVector, usdVector): - ufeTestUtils.testUtils.assertVectorAlmostEqual( + testUtils.assertVectorAlmostEqual( self, ufeVector.vector, usdVector) def assertColorAlmostEqual(self, ufeColor, usdColor): diff --git a/test/lib/ufe/testAttributes.py b/test/lib/ufe/testAttributes.py index a9b4c3be07..81269cd3c5 100644 --- a/test/lib/ufe/testAttributes.py +++ b/test/lib/ufe/testAttributes.py @@ -16,7 +16,7 @@ # limitations under the License. # -from ufeTestUtils import usdUtils, mayaUtils +import usdUtils, mayaUtils import ufe from pxr import UsdGeom @@ -37,7 +37,7 @@ def setUp(self): ''' Called initially to set up the maya test environment ''' self.assertTrue(self.pluginsLoaded) - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() def testAttributes(self): diff --git a/test/lib/ufe/testChildFilter.py b/test/lib/ufe/testChildFilter.py index 2c22d932ba..ffdc73e770 100644 --- a/test/lib/ufe/testChildFilter.py +++ b/test/lib/ufe/testChildFilter.py @@ -20,7 +20,7 @@ import maya.cmds as cmds -from ufeTestUtils import mayaUtils +import mayaUtils import ufe import unittest @@ -43,7 +43,7 @@ def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) - # Open ballset.ma scene in test-samples + # Open ballset.ma scene in testSamples mayaUtils.openGroupBallsScene() # Clear selection to start off diff --git a/test/lib/ufe/testComboCmd.py b/test/lib/ufe/testComboCmd.py index 6faee57205..44a0badeaf 100644 --- a/test/lib/ufe/testComboCmd.py +++ b/test/lib/ufe/testComboCmd.py @@ -20,8 +20,8 @@ import maya.cmds as cmds from math import radians, degrees -from ufeTestUtils import usdUtils, mayaUtils, ufeUtils -from ufeTestUtils.testUtils import assertVectorAlmostEqual +import usdUtils, mayaUtils, ufeUtils +from testUtils import assertVectorAlmostEqual import testTRSBase import ufe @@ -120,7 +120,7 @@ def setUp(self): self.noSpace = None self.spaces = [om.MSpace.kObject, om.MSpace.kWorld] - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes diff --git a/test/lib/ufe/testContextOps.py b/test/lib/ufe/testContextOps.py index c775c009de..5959f01100 100644 --- a/test/lib/ufe/testContextOps.py +++ b/test/lib/ufe/testContextOps.py @@ -21,7 +21,7 @@ from pxr import UsdGeom -from ufeTestUtils import usdUtils, mayaUtils +import usdUtils, mayaUtils import ufe import unittest @@ -68,7 +68,7 @@ def setUp(self): if self._testMethodName in ['testAddNewPrim', 'testAddNewPrimWithDelete']: return - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Clear selection to start off. diff --git a/test/lib/ufe/testDeleteCmd.py b/test/lib/ufe/testDeleteCmd.py index 9657633228..a8c8f673d7 100644 --- a/test/lib/ufe/testDeleteCmd.py +++ b/test/lib/ufe/testDeleteCmd.py @@ -18,7 +18,7 @@ import maya.cmds as cmds -from ufeTestUtils import ufeUtils, usdUtils, mayaUtils +import ufeUtils, usdUtils, mayaUtils import ufe import unittest @@ -77,7 +77,7 @@ def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes diff --git a/test/lib/ufe/testDuplicateCmd.py b/test/lib/ufe/testDuplicateCmd.py index bb76fe9fb8..ecf2dce95c 100644 --- a/test/lib/ufe/testDuplicateCmd.py +++ b/test/lib/ufe/testDuplicateCmd.py @@ -18,7 +18,7 @@ import maya.cmds as cmds -from ufeTestUtils import usdUtils, mayaUtils +import usdUtils, mayaUtils import ufe import unittest @@ -51,7 +51,7 @@ def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index 529f885268..73a5b6a33d 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -20,7 +20,7 @@ import maya.cmds as cmds -from ufeTestUtils import usdUtils, mayaUtils, ufeUtils +import usdUtils, mayaUtils, ufeUtils import ufe import mayaUsd.ufe @@ -45,7 +45,7 @@ def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) - # Open ballset.ma scene in test-samples + # Open ballset.ma scene in testSamples mayaUtils.openGroupBallsScene() # Clear selection to start off diff --git a/test/lib/ufe/testMatrices.py b/test/lib/ufe/testMatrices.py index cc405b8d8e..08fa83d34e 100644 --- a/test/lib/ufe/testMatrices.py +++ b/test/lib/ufe/testMatrices.py @@ -16,7 +16,7 @@ # limitations under the License. # -from ufeTestUtils import usdUtils, mayaUtils +import usdUtils, mayaUtils import ufe @@ -62,7 +62,7 @@ def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) - # Open usdCylinder.ma scene in test-samples + # Open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() def assertMatrixAlmostEqual(self, ma, mb): diff --git a/test/lib/ufe/testMayaPickwalk.py b/test/lib/ufe/testMayaPickwalk.py index 4caf37acad..654e337451 100644 --- a/test/lib/ufe/testMayaPickwalk.py +++ b/test/lib/ufe/testMayaPickwalk.py @@ -21,7 +21,7 @@ import maya.cmds as cmds import sys, os -from ufeTestUtils import usdUtils, mayaUtils, ufeUtils +import usdUtils, mayaUtils, ufeUtils import ufe class MayaUFEPickWalkTesting(unittest.TestCase): @@ -70,7 +70,7 @@ def setUp(self): # Set up memento - [[mayaSelection, ufeSelection], ...] self.memento = [] - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes diff --git a/test/lib/ufe/testMoveCmd.py b/test/lib/ufe/testMoveCmd.py index 94fad27953..2f45ce2569 100644 --- a/test/lib/ufe/testMoveCmd.py +++ b/test/lib/ufe/testMoveCmd.py @@ -19,8 +19,8 @@ import maya.api.OpenMaya as om import maya.cmds as cmds -from ufeTestUtils import usdUtils, mayaUtils, ufeUtils -from ufeTestUtils.testUtils import assertVectorAlmostEqual +import usdUtils, mayaUtils, ufeUtils +from testUtils import assertVectorAlmostEqual import testTRSBase import ufe @@ -85,7 +85,7 @@ def setUp(self): self.runTimeTranslation = None self.ufeTranslation = None - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes diff --git a/test/lib/ufe/testObject3d.py b/test/lib/ufe/testObject3d.py index 5a781f6db3..d33702e2de 100644 --- a/test/lib/ufe/testObject3d.py +++ b/test/lib/ufe/testObject3d.py @@ -16,9 +16,8 @@ # limitations under the License. # -from ufeTestUtils import mayaUtils -from ufeTestUtils import usdUtils -from ufeTestUtils.testUtils import assertVectorAlmostEqual, assertVectorEqual +import mayaUtils, usdUtils +from testUtils import assertVectorAlmostEqual, assertVectorEqual import ufe @@ -140,7 +139,7 @@ def testBoundingBox(self): def testAnimatedBoundingBox(self): '''Test the Object3d bounding box interface for animated geometry.''' - # Open sphereAnimatedRadiusProxyShape.ma scene in test-samples + # Open sphereAnimatedRadiusProxyShape.ma scene in testSamples mayaUtils.openSphereAnimatedRadiusScene() # The extents of the sphere are copied from the .usda file. @@ -182,7 +181,7 @@ def testAnimatedBoundingBox(self): def testVisibility(self): '''Test the Object3d visibility methods.''' - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Get a scene item for Ball_35. diff --git a/test/lib/ufe/testParentCmd.py b/test/lib/ufe/testParentCmd.py index bfcac3d453..c0bbc60e60 100644 --- a/test/lib/ufe/testParentCmd.py +++ b/test/lib/ufe/testParentCmd.py @@ -16,8 +16,8 @@ # limitations under the License. # -from ufeTestUtils import mayaUtils, usdUtils -from ufeTestUtils.testUtils import assertVectorAlmostEqual +import mayaUtils, usdUtils +from testUtils import assertVectorAlmostEqual import ufe import mayaUsd.ufe @@ -40,7 +40,7 @@ def __init__(self, fileName): self._fileName = fileName def __enter__(self): - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test-samples", "parentCmd", self._fileName) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../..", "testSamples", "parentCmd", self._fileName) cmds.file(filePath, force=True, open=True) def __exit__(self, type, value, traceback): @@ -67,7 +67,7 @@ def setUp(self): # Load a file that has the same scene in both the Maya Dag # hierarchy and the USD hierarchy. - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test-samples", "parentCmd", "simpleSceneMayaPlusUSD_TRS.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../..", "testSamples", "parentCmd", "simpleSceneMayaPlusUSD_TRS.ma" ) cmds.file(filePath, force=True, open=True) # Clear selection to start off @@ -423,7 +423,7 @@ def testUnparentMultiStage(self): # opened file. Layers are then shared between the stages, because # they come from the same USD file, causing changes done below one # proxy shape to be seen in the other. Import from another file. - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test-samples", "parentCmd", "simpleSceneUSD_TRS.ma") + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../..", "testSamples", "parentCmd", "simpleSceneUSD_TRS.ma") cmds.file(filePath, i=True) # Unparent a USD node in each stage. Unparenting Lambert node is diff --git a/test/lib/ufe/testRename.py b/test/lib/ufe/testRename.py index ba58b7ca4f..8111cc4db9 100644 --- a/test/lib/ufe/testRename.py +++ b/test/lib/ufe/testRename.py @@ -18,7 +18,7 @@ import maya.cmds as cmds -from ufeTestUtils import usdUtils, mayaUtils +import usdUtils, mayaUtils import ufe import mayaUsd.ufe @@ -66,7 +66,7 @@ def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Clear selection to start off @@ -116,7 +116,7 @@ def assertStageAndPrimAccess( assertStageAndPrimAccess(mayaSegment, ball35PathStr, usdSegment) def testRename(self): - # open tree.ma scene in test-samples + # open tree.ma scene in testSamples mayaUtils.openTreeScene() # clear selection to start off @@ -176,7 +176,7 @@ def testRename(self): def testRenameUndo(self): '''Rename USD node.''' - # open usdCylinder.ma scene in test-samples + # open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() # clear selection to start off @@ -273,7 +273,7 @@ def testRenameRestrictionSameLayerDef(self): def testRenameRestrictionHasSpecs(self): '''Restrict renaming USD node. Cannot rename a node that doesn't contribute to the final composed prim''' - # open appleBite.ma scene in test-samples + # open appleBite.ma scene in testSamples mayaUtils.openAppleBiteScene() # clear selection to start off @@ -296,7 +296,7 @@ def testRenameRestrictionHasSpecs(self): cmds.rename("geo_renamed") def testRenameUniqueName(self): - # open tree.ma scene in test-samples + # open tree.ma scene in testSamples mayaUtils.openTreeScene() # clear selection to start off @@ -331,7 +331,7 @@ def testRenameUniqueName(self): stage.GetPrimAtPath("/TreeBase/leavesXform1"),]) def testRenameSpecialCharacter(self): - # open twoSpheres.ma scene in test-samples + # open twoSpheres.ma scene in testSamples mayaUtils.openTwoSpheresScene() # clear selection to start off @@ -373,7 +373,7 @@ def testRenameSpecialCharacter(self): def testRenameNotifications(self): '''Rename a USD node and test for the UFE notifications.''' - # open usdCylinder.ma scene in test-samples + # open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() # clear selection to start off diff --git a/test/lib/ufe/testRotateCmd.py b/test/lib/ufe/testRotateCmd.py index 2f9c2a7745..948cdd0d86 100644 --- a/test/lib/ufe/testRotateCmd.py +++ b/test/lib/ufe/testRotateCmd.py @@ -20,8 +20,8 @@ import maya.cmds as cmds from math import radians -from ufeTestUtils import usdUtils, mayaUtils, ufeUtils -from ufeTestUtils.testUtils import assertVectorAlmostEqual +import usdUtils, mayaUtils, ufeUtils +from testUtils import assertVectorAlmostEqual import testTRSBase import ufe @@ -85,7 +85,7 @@ def setUp(self): self.runTimeRotation = None self.ufeRotation = None - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes diff --git a/test/lib/ufe/testRotatePivot.py b/test/lib/ufe/testRotatePivot.py index ae4690781f..8cec33c696 100644 --- a/test/lib/ufe/testRotatePivot.py +++ b/test/lib/ufe/testRotatePivot.py @@ -16,7 +16,7 @@ # limitations under the License. # -from ufeTestUtils import usdUtils, mayaUtils +import usdUtils, mayaUtils import ufe @@ -66,7 +66,7 @@ def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) - # Open twoSpheres.ma scene in test-samples + # Open twoSpheres.ma scene in testSamples mayaUtils.openTwoSpheresScene() def checkPos(self, m, p): diff --git a/test/lib/ufe/testScaleCmd.py b/test/lib/ufe/testScaleCmd.py index ce8e703b91..8550cc3ca3 100644 --- a/test/lib/ufe/testScaleCmd.py +++ b/test/lib/ufe/testScaleCmd.py @@ -18,8 +18,8 @@ import maya.api.OpenMaya as om import maya.cmds as cmds -from ufeTestUtils import usdUtils, mayaUtils, ufeUtils -from ufeTestUtils.testUtils import assertVectorAlmostEqual +import usdUtils, mayaUtils, ufeUtils +from testUtils import assertVectorAlmostEqual import testTRSBase import ufe @@ -81,7 +81,7 @@ def setUp(self): self.runTimeScale = None self.ufeScale = None - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes diff --git a/test/lib/ufe/testSceneItem.py b/test/lib/ufe/testSceneItem.py index d434936199..8325914757 100644 --- a/test/lib/ufe/testSceneItem.py +++ b/test/lib/ufe/testSceneItem.py @@ -18,7 +18,7 @@ import maya.cmds as cmds -from ufeTestUtils import usdUtils, mayaUtils +import usdUtils, mayaUtils import ufe import unittest @@ -39,7 +39,7 @@ def setUp(self): ''' Called initially to set up the maya test environment ''' self.assertTrue(self.pluginsLoaded) - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '2020', 'testNodeTypes only available in UFE preview version 0.2.20 and greater') diff --git a/test/lib/ufe/testSelection.py b/test/lib/ufe/testSelection.py index d0129a2c63..f304845c8b 100644 --- a/test/lib/ufe/testSelection.py +++ b/test/lib/ufe/testSelection.py @@ -16,7 +16,7 @@ # limitations under the License. # -from ufeTestUtils import mayaUtils, usdUtils, ufeUtils +import mayaUtils, usdUtils, ufeUtils import ufe @@ -51,7 +51,7 @@ def setUp(self): # Load a file that has the same scene in both the Maya Dag # hierarchy and the USD hierarchy. - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test-samples", "parentCmd", "simpleSceneMayaPlusUSD_TRS.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../..", "testSamples", "parentCmd", "simpleSceneMayaPlusUSD_TRS.ma" ) cmds.file(filePath, force=True, open=True) # Clear selection to start off diff --git a/test/lib/ufe/testTRSBase.py b/test/lib/ufe/testTRSBase.py index fa38671241..d3eb4e092a 100644 --- a/test/lib/ufe/testTRSBase.py +++ b/test/lib/ufe/testTRSBase.py @@ -20,7 +20,7 @@ import maya.cmds as cmds -from ufeTestUtils.testUtils import assertVectorAlmostEqual +from testUtils import assertVectorAlmostEqual class TRSTestCaseBase(unittest.TestCase): '''Base class for translate (move), rotate, scale command tests.''' diff --git a/test/lib/ufe/testTransform3dTranslate.py b/test/lib/ufe/testTransform3dTranslate.py index 08c92dad34..f693b0a229 100644 --- a/test/lib/ufe/testTransform3dTranslate.py +++ b/test/lib/ufe/testTransform3dTranslate.py @@ -19,8 +19,8 @@ import maya.api.OpenMaya as om import maya.cmds as cmds -from ufeTestUtils import usdUtils, mayaUtils, ufeUtils -from ufeTestUtils.testUtils import assertVectorAlmostEqual +import usdUtils, mayaUtils, ufeUtils +from testUtils import assertVectorAlmostEqual import ufe import unittest @@ -97,7 +97,7 @@ def setUp(self): # interface. self.setRunTimeTranslation = None - # Open top_layer.ma scene in test-samples + # Open top_layer.ma scene in testSamples mayaUtils.openTopLayerScene() # Create some extra Maya nodes diff --git a/test/lib/ufe/testUIInfoHandler.py b/test/lib/ufe/testUIInfoHandler.py index 4405210878..a010aca11e 100644 --- a/test/lib/ufe/testUIInfoHandler.py +++ b/test/lib/ufe/testUIInfoHandler.py @@ -20,7 +20,7 @@ import maya.cmds as cmds -from ufeTestUtils import mayaUtils +import mayaUtils import ufe import unittest @@ -42,7 +42,7 @@ def setUp(self): # Load plugins self.assertTrue(self.pluginsLoaded) - # Open ballset.ma scene in test-samples + # Open ballset.ma scene in testSamples mayaUtils.openGroupBallsScene() # Clear selection to start off diff --git a/test/lib/ufe/ufeTestUtils/__init__.py b/test/lib/ufe/ufeTestUtils/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/testSamples/CMakeLists.txt b/test/testSamples/CMakeLists.txt new file mode 100644 index 0000000000..b4682d36d1 --- /dev/null +++ b/test/testSamples/CMakeLists.txt @@ -0,0 +1,11 @@ +set(TARGET_NAME PYTHON_TEST_SAMPLES) + +add_custom_target(${TARGET_NAME} ALL) + +# Copy all of the resources in this directory to a +# "test/testSamples" subdirectory under the top-level build directory. +mayaUsd_copyDirectory(${TARGET_NAME} + SOURCE ${CMAKE_CURRENT_SOURCE_DIR} + DESTINATION ${CMAKE_BINARY_DIR}/test/testSamples + EXCLUDE "*.txt" +) diff --git a/test/lib/ufe/test-samples/appleBite/appleBite.ma b/test/testSamples/appleBite/appleBite.ma similarity index 100% rename from test/lib/ufe/test-samples/appleBite/appleBite.ma rename to test/testSamples/appleBite/appleBite.ma diff --git a/test/lib/ufe/test-samples/appleBite/asset_flattened_instancing_and_class_removed.usda b/test/testSamples/appleBite/asset_flattened_instancing_and_class_removed.usda similarity index 100% rename from test/lib/ufe/test-samples/appleBite/asset_flattened_instancing_and_class_removed.usda rename to test/testSamples/appleBite/asset_flattened_instancing_and_class_removed.usda diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/Assembly_room_set.usda b/test/testSamples/ballset/StandaloneScene/Assembly_room_set.usda similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/Assembly_room_set.usda rename to test/testSamples/ballset/StandaloneScene/Assembly_room_set.usda diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/Ball.maya.usd b/test/testSamples/ballset/StandaloneScene/Ball.maya.usd similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/Ball.maya.usd rename to test/testSamples/ballset/StandaloneScene/Ball.maya.usd diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/Ball.shadingVariants.usda b/test/testSamples/ballset/StandaloneScene/Ball.shadingVariants.usda similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/Ball.shadingVariants.usda rename to test/testSamples/ballset/StandaloneScene/Ball.shadingVariants.usda diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/Ball.usd b/test/testSamples/ballset/StandaloneScene/Ball.usd similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/Ball.usd rename to test/testSamples/ballset/StandaloneScene/Ball.usd diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/Ball_payload.usd b/test/testSamples/ballset/StandaloneScene/Ball_payload.usd similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/Ball_payload.usd rename to test/testSamples/ballset/StandaloneScene/Ball_payload.usd diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/Room_set.usd b/test/testSamples/ballset/StandaloneScene/Room_set.usd similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/Room_set.usd rename to test/testSamples/ballset/StandaloneScene/Room_set.usd diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/edits.usda b/test/testSamples/ballset/StandaloneScene/edits.usda similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/edits.usda rename to test/testSamples/ballset/StandaloneScene/edits.usda diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball1.jpg b/test/testSamples/ballset/StandaloneScene/tex/ball1.jpg similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball1.jpg rename to test/testSamples/ballset/StandaloneScene/tex/ball1.jpg diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball1.tex b/test/testSamples/ballset/StandaloneScene/tex/ball1.tex similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball1.tex rename to test/testSamples/ballset/StandaloneScene/tex/ball1.tex diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball4.jpg b/test/testSamples/ballset/StandaloneScene/tex/ball4.jpg similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball4.jpg rename to test/testSamples/ballset/StandaloneScene/tex/ball4.jpg diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball4.tex b/test/testSamples/ballset/StandaloneScene/tex/ball4.tex similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball4.tex rename to test/testSamples/ballset/StandaloneScene/tex/ball4.tex diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball8.jpg b/test/testSamples/ballset/StandaloneScene/tex/ball8.jpg similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball8.jpg rename to test/testSamples/ballset/StandaloneScene/tex/ball8.jpg diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball8.tex b/test/testSamples/ballset/StandaloneScene/tex/ball8.tex similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball8.tex rename to test/testSamples/ballset/StandaloneScene/tex/ball8.tex diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball9.jpg b/test/testSamples/ballset/StandaloneScene/tex/ball9.jpg similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball9.jpg rename to test/testSamples/ballset/StandaloneScene/tex/ball9.jpg diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball9.tex b/test/testSamples/ballset/StandaloneScene/tex/ball9.tex similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ball9.tex rename to test/testSamples/ballset/StandaloneScene/tex/ball9.tex diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ballCue.jpg b/test/testSamples/ballset/StandaloneScene/tex/ballCue.jpg similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ballCue.jpg rename to test/testSamples/ballset/StandaloneScene/tex/ballCue.jpg diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ballCue.tex b/test/testSamples/ballset/StandaloneScene/tex/ballCue.tex similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/ballCue.tex rename to test/testSamples/ballset/StandaloneScene/tex/ballCue.tex diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/tex/makeTex b/test/testSamples/ballset/StandaloneScene/tex/makeTex similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/tex/makeTex rename to test/testSamples/ballset/StandaloneScene/tex/makeTex diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/top_layer.ma b/test/testSamples/ballset/StandaloneScene/top_layer.ma similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/top_layer.ma rename to test/testSamples/ballset/StandaloneScene/top_layer.ma diff --git a/test/lib/ufe/test-samples/ballset/StandaloneScene/top_layer.usda b/test/testSamples/ballset/StandaloneScene/top_layer.usda similarity index 100% rename from test/lib/ufe/test-samples/ballset/StandaloneScene/top_layer.usda rename to test/testSamples/ballset/StandaloneScene/top_layer.usda diff --git a/test/lib/ufe/test-samples/cylinder/cylinder.usda b/test/testSamples/cylinder/cylinder.usda similarity index 100% rename from test/lib/ufe/test-samples/cylinder/cylinder.usda rename to test/testSamples/cylinder/cylinder.usda diff --git a/test/lib/ufe/test-samples/cylinder/usdCylinder.ma b/test/testSamples/cylinder/usdCylinder.ma similarity index 100% rename from test/lib/ufe/test-samples/cylinder/usdCylinder.ma rename to test/testSamples/cylinder/usdCylinder.ma diff --git a/test/lib/ufe/test-samples/groupBalls/ballset.ma b/test/testSamples/groupBalls/ballset.ma similarity index 100% rename from test/lib/ufe/test-samples/groupBalls/ballset.ma rename to test/testSamples/groupBalls/ballset.ma diff --git a/test/lib/ufe/test-samples/groupBalls/ballset.usda b/test/testSamples/groupBalls/ballset.usda similarity index 100% rename from test/lib/ufe/test-samples/groupBalls/ballset.usda rename to test/testSamples/groupBalls/ballset.usda diff --git a/test/lib/ufe/test-samples/parentCmd/simpleHierarchy.ma b/test/testSamples/parentCmd/simpleHierarchy.ma similarity index 100% rename from test/lib/ufe/test-samples/parentCmd/simpleHierarchy.ma rename to test/testSamples/parentCmd/simpleHierarchy.ma diff --git a/test/lib/ufe/test-samples/parentCmd/simpleHierarchy.usda b/test/testSamples/parentCmd/simpleHierarchy.usda similarity index 100% rename from test/lib/ufe/test-samples/parentCmd/simpleHierarchy.usda rename to test/testSamples/parentCmd/simpleHierarchy.usda diff --git a/test/lib/ufe/test-samples/parentCmd/simpleSceneMayaPlusUSD_TRS.ma b/test/testSamples/parentCmd/simpleSceneMayaPlusUSD_TRS.ma similarity index 100% rename from test/lib/ufe/test-samples/parentCmd/simpleSceneMayaPlusUSD_TRS.ma rename to test/testSamples/parentCmd/simpleSceneMayaPlusUSD_TRS.ma diff --git a/test/lib/ufe/test-samples/parentCmd/simpleSceneTRS.usda b/test/testSamples/parentCmd/simpleSceneTRS.usda similarity index 100% rename from test/lib/ufe/test-samples/parentCmd/simpleSceneTRS.usda rename to test/testSamples/parentCmd/simpleSceneTRS.usda diff --git a/test/lib/ufe/test-samples/parentCmd/simpleSceneUSD_TRS.ma b/test/testSamples/parentCmd/simpleSceneUSD_TRS.ma similarity index 100% rename from test/lib/ufe/test-samples/parentCmd/simpleSceneUSD_TRS.ma rename to test/testSamples/parentCmd/simpleSceneUSD_TRS.ma diff --git a/test/lib/ufe/test-samples/sphereAnimatedRadius/sphereAnimatedRadius.usda b/test/testSamples/sphereAnimatedRadius/sphereAnimatedRadius.usda similarity index 100% rename from test/lib/ufe/test-samples/sphereAnimatedRadius/sphereAnimatedRadius.usda rename to test/testSamples/sphereAnimatedRadius/sphereAnimatedRadius.usda diff --git a/test/lib/ufe/test-samples/sphereAnimatedRadius/sphereAnimatedRadiusProxyShape.ma b/test/testSamples/sphereAnimatedRadius/sphereAnimatedRadiusProxyShape.ma similarity index 100% rename from test/lib/ufe/test-samples/sphereAnimatedRadius/sphereAnimatedRadiusProxyShape.ma rename to test/testSamples/sphereAnimatedRadius/sphereAnimatedRadiusProxyShape.ma diff --git a/test/lib/ufe/test-samples/tree/tree.ma b/test/testSamples/tree/tree.ma similarity index 100% rename from test/lib/ufe/test-samples/tree/tree.ma rename to test/testSamples/tree/tree.ma diff --git a/test/lib/ufe/test-samples/tree/tree.usda b/test/testSamples/tree/tree.usda similarity index 100% rename from test/lib/ufe/test-samples/tree/tree.usda rename to test/testSamples/tree/tree.usda diff --git a/test/lib/ufe/test-samples/tree/treeRef.ma b/test/testSamples/tree/treeRef.ma similarity index 100% rename from test/lib/ufe/test-samples/tree/treeRef.ma rename to test/testSamples/tree/treeRef.ma diff --git a/test/lib/ufe/test-samples/tree/treeRef.usda b/test/testSamples/tree/treeRef.usda similarity index 100% rename from test/lib/ufe/test-samples/tree/treeRef.usda rename to test/testSamples/tree/treeRef.usda diff --git a/test/lib/ufe/test-samples/twoSpheres/sphere.usda b/test/testSamples/twoSpheres/sphere.usda similarity index 100% rename from test/lib/ufe/test-samples/twoSpheres/sphere.usda rename to test/testSamples/twoSpheres/sphere.usda diff --git a/test/lib/ufe/test-samples/twoSpheres/twoSpheres.ma b/test/testSamples/twoSpheres/twoSpheres.ma similarity index 100% rename from test/lib/ufe/test-samples/twoSpheres/twoSpheres.ma rename to test/testSamples/twoSpheres/twoSpheres.ma diff --git a/test/testUtils/cachingUtils.py b/test/testUtils/cachingUtils.py new file mode 100644 index 0000000000..7684966a4a --- /dev/null +++ b/test/testUtils/cachingUtils.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python + +# +# Copyright 2020 Autodesk +# +# 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. +# + +""" + Helper functions regarding Cached Playback. +""" +import maya.cmds as cmds + +from maya.debug.emModeManager import emModeManager +from maya.plugin.evaluator.CacheEvaluatorManager import CacheEvaluatorManager, CACHE_STANDARD_MODE_EVAL + +class NonCachingScope(object): + ''' + Scope object responsible for setting up non cached mode and restoring default settings after + ''' + def __enter__(self): + '''Enter the scope, setting up the evaluator managers and initial states''' + self.em_mgr = emModeManager() + self.em_mgr.setMode('emp') + self.em_mgr.setMode('-cache') + + return self + + def __init__(self, unit_test): + '''Initialize everything to be empty - only use the "with" syntax with this object''' + self.em_mgr = None + self.unit_test = unit_test + + def __exit__(self,exit_type,value,traceback): + '''Exit the scope, restoring all of the state information''' + if self.em_mgr: + self.em_mgr.restore_state() + self.em_mgr = None + + def verifyScopeSetup(self): + ''' + Meta-test to check that the scope was defined correctly + :param unit_test: The test object from which this method was called + ''' + self.unit_test.assertTrue( cmds.evaluationManager( mode=True, query=True )[0] == 'parallel' ) + if cmds.pluginInfo('cacheEvaluator', loaded=True, query=True): + self.unit_test.assertFalse( cmds.evaluator( query=True, en=True, name='cache' ) ) + + def checkValidFrames(self, expected_valid_frames, layers_mask = 0b01): + return True + + def waitForCache(self, wait_time=5): + return + + @staticmethod + def is_caching_scope(): + ''' + Method to determine whether caching is on or off in this object's scope + :return: False, since this is the non-caching scope + ''' + return False + +class CachingScope(object): + ''' + Scope object responsible for setting up caching and restoring original setup after + ''' + def __enter__(self): + '''Enter the scope, setting up the evaluator managers and initial states''' + self.em_mgr = emModeManager() + self.em_mgr.setMode('emp') + self.em_mgr.setMode('+cache') + # Enable idle build to make sure we can rebuild the graph when waiting. + self.em_mgr.idle_action = emModeManager.idle_action_build + + # Setup caching options + self.cache_mgr = CacheEvaluatorManager() + self.cache_mgr.save_state() + self.cache_mgr.plugin_loaded = True + self.cache_mgr.enabled = True + self.cache_mgr.cache_mode = CACHE_STANDARD_MODE_EVAL + self.cache_mgr.resource_guard = False + self.cache_mgr.fill_mode = 'syncAsync' + + # Setup autokey options + self.auto_key_state = cmds.autoKeyframe(q=True, state=True) + self.auto_key_chars = cmds.autoKeyframe(q=True, characterOption=True) + cmds.autoKeyframe(e=True, state=False) + + self.waitForCache() + + return self + + def __init__(self, unit_test): + '''Initialize everything to be empty - only use the "with" syntax with this object''' + self.em_mgr = None + self.cache_mgr = None + self.auto_key_state = None + self.auto_key_chars = None + self.unit_test = unit_test + + def __exit__(self,exit_type,value,traceback): + '''Exit the scope, restoring all of the state information''' + if self.cache_mgr: + self.cache_mgr.restore_state() + if self.em_mgr: + self.em_mgr.restore_state() + cmds.autoKeyframe(e=True, state=self.auto_key_state, characterOption=self.auto_key_chars) + + def verifyScopeSetup(self): + ''' + Meta-test to check that the scope was defined correctly + :param unit_test: The test object from which this method was called + ''' + self.unit_test.assertTrue( cmds.evaluationManager( mode=True, query=True )[0] == 'parallel' ) + self.unit_test.assertTrue( cmds.pluginInfo('cacheEvaluator', loaded=True, query=True) ) + self.unit_test.assertTrue( cmds.evaluator( query=True, en=True, name='cache' ) ) + + def checkValidFrames(self, expected_valid_frames, layers_mask = 0b01): + ''' + :param unit_test: The test object from which this method was called + :param expected_valid_frames: The list of frames the text expected to be cached + :return: True if the cached frame list matches the expected frame list + ''' + current_valid_frames = list(self.cache_mgr.get_valid_frames(layers_mask)) + if len(expected_valid_frames) == len(current_valid_frames): + for current, expected in zip(current_valid_frames,expected_valid_frames): + if current[0] != expected[0] or current[1] != expected[1]: + self.unit_test.fail( "{} != {} (current,expected)".format( current_valid_frames, expected_valid_frames) ) + return False + + return True + self.unit_test.fail( "{} != {} (current,expected)".format( current_valid_frames, expected_valid_frames) ) + return False + + def waitForCache(self, wait_time=5): + ''' + Fill the cache in the background, waiting for a maximum time + :param unit_test: The test object from which this method was called + :param wait_time: Time the test is willing to wait for cache completion (in seconds) + ''' + cmds.currentTime( cmds.currentTime(q=True) ) + cmds.currentTime( cmds.currentTime(q=True) ) + cache_is_ready = cmds.cacheEvaluator( waitForCache=wait_time ) + self.unit_test.assertTrue( cache_is_ready ) + + @staticmethod + def is_caching_scope(): + ''' + Method to determine whether caching is on or off in this object's scope + :return: True, since this is the caching scope + ''' + return True diff --git a/test/lib/ufe/ufeTestUtils/mayaUtils.py b/test/testUtils/mayaUtils.py similarity index 70% rename from test/lib/ufe/ufeTestUtils/mayaUtils.py rename to test/testUtils/mayaUtils.py index 5c8379bee9..7d27773758 100644 --- a/test/lib/ufe/ufeTestUtils/mayaUtils.py +++ b/test/testUtils/mayaUtils.py @@ -25,6 +25,9 @@ import ufe +from mayaUsd import lib as mayaUsdLib +from pxr import Usd, UsdGeom + mayaRuntimeID = 1 mayaSeparator = "|" @@ -130,37 +133,100 @@ def openTopLayerScene(): /Ball_35 ''' # Open top_layer file which contains the USD scene - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "test-samples", "ballset", "StandaloneScene", "top_layer.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "ballset", "StandaloneScene", "top_layer.ma" ) cmds.file(filePath, force=True, open=True) def openCylinderScene(): - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "test-samples", "cylinder", "usdCylinder.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "cylinder", "usdCylinder.ma" ) cmds.file(filePath, force=True, open=True) def openTwoSpheresScene(): - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "test-samples", "twoSpheres", "twoSpheres.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "twoSpheres", "twoSpheres.ma" ) cmds.file(filePath, force=True, open=True) def openSphereAnimatedRadiusScene(): - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "test-samples", "sphereAnimatedRadius", "sphereAnimatedRadiusProxyShape.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "sphereAnimatedRadius", "sphereAnimatedRadiusProxyShape.ma" ) cmds.file(filePath, force=True, open=True) def openTreeScene(): - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "test-samples", "tree", "tree.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "tree", "tree.ma" ) cmds.file(filePath, force=True, open=True) def openTreeRefScene(): - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "test-samples", "tree", "treeRef.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "tree", "treeRef.ma" ) cmds.file(filePath, force=True, open=True) def openAppleBiteScene(): - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "test-samples", "appleBite", "appleBite.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "appleBite", "appleBite.ma" ) cmds.file(filePath, force=True, open=True) def openGroupBallsScene(): - filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "test-samples", "groupBalls", "ballset.ma" ) + filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "groupBalls", "ballset.ma" ) cmds.file(filePath, force=True, open=True) +def createProxyAndStage(): + """ + Create in-memory stage + """ + cmds.createNode('mayaUsdProxyShape', name='stageShape') + + shapeNode = cmds.ls(sl=True,l=True)[0] + shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage() + + cmds.select( clear=True ) + cmds.connectAttr('time1.outTime','{}.time'.format(shapeNode)) + + return shapeNode,shapeStage + +def createProxyFromFile(filePath): + """ + Load stage from file + """ + cmds.createNode('mayaUsdProxyShape', name='stageShape') + + shapeNode = cmds.ls(sl=True,l=True)[0] + cmds.setAttr('{}.filePath'.format(shapeNode), filePath, type='string') + + shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage() + + cmds.select( clear=True ) + cmds.connectAttr('time1.outTime','{}.time'.format(shapeNode)) + + return shapeNode,shapeStage + +def createAnimatedHierarchy(stage): + """ + Create simple hierarchy in the stage: + /ParentA + /Sphere + /Cube + /ParenB + + Entire ParentA hierarchy will receive time samples on translate for time 1 and 100 + """ + parentA = "/ParentA" + parentB = "/ParentB" + childSphere = "/ParentA/Sphere" + childCube = "/ParentA/Cube" + + parentPrimA = stage.DefinePrim(parentA, 'Xform') + parentPrimB = stage.DefinePrim(parentB, 'Xform') + childPrimSphere = stage.DefinePrim(childSphere, 'Sphere') + childPrimCube = stage.DefinePrim(childCube, 'Cube') + + UsdGeom.XformCommonAPI(parentPrimA).SetRotate((0,0,0)) + UsdGeom.XformCommonAPI(parentPrimB).SetTranslate((1,10,0)) + + time1 = Usd.TimeCode(1.) + UsdGeom.XformCommonAPI(parentPrimA).SetTranslate((0,0,0),time1) + UsdGeom.XformCommonAPI(childPrimSphere).SetTranslate((5,0,0),time1) + UsdGeom.XformCommonAPI(childPrimCube).SetTranslate((0,0,5),time1) + + time2 = Usd.TimeCode(100.) + UsdGeom.XformCommonAPI(parentPrimA).SetTranslate((0,5,0),time2) + UsdGeom.XformCommonAPI(childPrimSphere).SetTranslate((-5,0,0),time2) + UsdGeom.XformCommonAPI(childPrimCube).SetTranslate((0,0,-5),time2) + def previewReleaseVersion(): '''Return the Maya Preview Release version. diff --git a/test/lib/ufe/ufeTestUtils/testUtils.py b/test/testUtils/testUtils.py similarity index 100% rename from test/lib/ufe/ufeTestUtils/testUtils.py rename to test/testUtils/testUtils.py diff --git a/test/lib/ufe/ufeTestUtils/ufeUtils.py b/test/testUtils/ufeUtils.py similarity index 77% rename from test/lib/ufe/ufeTestUtils/ufeUtils.py rename to test/testUtils/ufeUtils.py index 5e3ddd1f21..167ca25727 100644 --- a/test/lib/ufe/ufeTestUtils/ufeUtils.py +++ b/test/testUtils/ufeUtils.py @@ -55,6 +55,26 @@ def selectPath(path, replace=False): else: ufeSelectCmd.append(sceneItem) +def createUfeSceneItem(dagPath, sdfPath=None): + """ + Make ufe item out of dag path and sdfpath + """ + ufePath = ufe.PathString.path('{},{}'.format(dagPath,sdfPath) if sdfPath != None else '{}'.format(dagPath)) + ufeItem = ufe.Hierarchy.createItem(ufePath) + return ufeItem + +def selectUfeItems(selectItems): + """ + Add given UFE item or list of items to a UFE global selection list + """ + ufeSelectionList = ufe.Selection() + + realListToSelect = selectItems if type(selectItems) is list else [selectItems] + for item in realListToSelect: + ufeSelectionList.append(item) + + ufe.GlobalSelection.get().replaceWith(ufeSelectionList) + def ufeFeatureSetVersion(): '''Return the UFE feature set version taking into account rollback to using 0 for unreleased version after we ship a UFE. diff --git a/test/lib/ufe/ufeTestUtils/usdUtils.py b/test/testUtils/usdUtils.py similarity index 100% rename from test/lib/ufe/ufeTestUtils/usdUtils.py rename to test/testUtils/usdUtils.py