Skip to content

Commit

Permalink
Merge pull request #3802 from Autodesk/donnels/fix_tests_modifying_so…
Browse files Browse the repository at this point in the history
…urce_folder

Fix tests that are modifying source folder.
  • Loading branch information
seando-adsk authored Jun 4, 2024
2 parents 3c91522 + adb4ee6 commit 8cc2b12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 14 additions & 6 deletions test/lib/mayaUsd/nodes/testProxyShapeBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ def testCachedStage(self):
stageCache = UsdUtils.StageCache.Get()
with Usd.StageCacheContext(stageCache):
cachedStage = Usd.Stage.Open(self.usdFilePath)

stageId = stageCache.GetId(cachedStage).ToLongInt()
shapeNode = cmds.createNode('mayaUsdProxyShape')
cmds.setAttr('{}.stageCacheId'.format(shapeNode), stageId)
Expand All @@ -994,16 +994,20 @@ def testCachedStage(self):
cmds.move(0, 0, 2, r=True)

# Make sure shareStage is ON
assert cmds.getAttr('{}.{}'.format(shapeNode,"shareStage"))
self.assertTrue(cmds.getAttr('{}.{}'.format(shapeNode,"shareStage")))

# Make sure there is no connection to inStageData
assert not cmds.listConnections('{}.inStageData'.format(shapeNode), s=True, d=False)
self.assertIsNone(cmds.listConnections('{}.inStageData'.format(shapeNode), s=True, d=False))

cmds.select(cmds.listRelatives(fullPath, p=True)[0], r=True)

with testUtils.TemporaryDirectory(prefix='ProxyShapeBase') as testDir:
pathToSave = "{}/CubeModel.ma".format(testDir)

# Make sure to save USD back to Maya file, so that the USD test
# file we loaded (from source folder) isn't modified.
cmds.optionVar(intValue=('mayaUsd_SerializedUsdEditsLocation', 2))

cmds.file(rename=pathToSave)
cmds.file(save=True, force=True, type='mayaAscii')

Expand All @@ -1012,12 +1016,12 @@ def testCachedStage(self):

stage = mayaUsd.lib.GetPrim(fullPath).GetStage()
prim = stage.GetPrimAtPath('/CubeModel')
assert prim.IsValid()
self.assertTrue(prim.IsValid())

# Verify we get the saved changes we did
xform = UsdGeom.Xformable(prim)
translate = xform.GetOrderedXformOps()[0].Get()
assert translate[2] == 2
self.assertEqual(translate[2], 2)

def testRegisterFilePathEditor(self):
'''
Expand Down Expand Up @@ -1101,6 +1105,10 @@ def _verifyVariantFallbacks(primPath, stage, shapeNode, overrides):
with testUtils.TemporaryDirectory(prefix='ProxyShapeBase') as testDir:
pathToSave = "{}/testSavingVariantFallbacks.ma".format(testDir)

# Make sure to save USD back to Maya file, so that the USD test
# file we loaded (from source folder) isn't modified.
cmds.optionVar(intValue=('mayaUsd_SerializedUsdEditsLocation', 2))

cmds.file(rename=pathToSave)
cmds.file(save=True, force=True, type='mayaAscii')

Expand Down
9 changes: 5 additions & 4 deletions test/lib/usd/translators/testUsdExportTexture.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ def getUsdFilePath(self):
return os.path.join(outputFolder, 'TextureTest.usda')

def tearDown(self):
usdFilePath = self.getUsdFilePath()
try:
if os.path.exists(usdFilePath):
os.remove(usdFilePath)
# Cleanup the output folder added for the test. We don't want
# to leave extra files around in the test source directory.
outputFolder = os.path.dirname(self.getUsdFilePath())
import shutil
shutil.rmtree(outputFolder)
except Exception:
# Don't let cleanup errors fail the test.
# We're removing the output file only to be nice, it is not mandatory.
pass

def runTextureTest(self, relativeMode, withEnvVar):
Expand Down

0 comments on commit 8cc2b12

Please sign in to comment.