Skip to content

Commit

Permalink
Refactored test case plugin loading and unloading.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppt-adsk committed Nov 18, 2024
1 parent a8c976a commit 0503daf
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,14 @@ class TestDataProducerExample(mtohUtils.MayaHydraBaseTestCase):
# MayaHydraBaseTestCase.setUpClass requirement.
_file = __file__

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def createScene(self):
self._locator = cmds.createNode('MhFlowViewportAPILocator')
cmds.setAttr(self._locator + '.numCubesX', 3)
cmds.setAttr(self._locator + '.numCubesY', 3)
cmds.setAttr(self._locator + '.numCubesZ', 3)

@classmethod
def setUpClass(cls):
super(TestDataProducerExample, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestDataProducerExample, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)

def setUp(self):
super(TestDataProducerExample, self).setUp()
self.createScene()
Expand Down
20 changes: 1 addition & 19 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelect.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,7 @@ class TestIsolateSelect(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestIsolateSelect, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestIsolateSelect, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def setupScene(self):
proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,7 @@ class TestIsolateSelectMayaSelectionHighlighting(mtohUtils.MayaHydraBaseTestCase

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestIsolateSelectMayaSelectionHighlighting, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestIsolateSelectMayaSelectionHighlighting, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests']

def setupScene(self):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,7 @@ class TestIsolateSelectSwitchToVP2(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestIsolateSelectSwitchToVP2, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestIsolateSelectSwitchToVP2, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests']

def setupScene(self):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,7 @@ class TestUsdNativeInstancingIsolateSelect(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestUsdNativeInstancingIsolateSelect, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestUsdNativeInstancingIsolateSelect, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def setupScene(self):
proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,7 @@ class TestUsdPointInstancingIsolateSelect(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestUsdPointInstancingIsolateSelect, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestUsdPointInstancingIsolateSelect, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def setupScene(self):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,7 @@ class TestUsdPointInstancingIsolateSelectBBox(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestUsdPointInstancingIsolateSelectBBox, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestUsdPointInstancingIsolateSelectBBox, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def setupScene(self):
self.proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
Expand Down
13 changes: 11 additions & 2 deletions test/testUtils/mtohUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MayaHydraBaseTestCase(unittest.TestCase, ImageDiffingTestCase):
# Variables to be set in subclasses
_file = None
_requiredPlugins = []
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -79,11 +80,13 @@ def setUpClass(cls):
if MAYAUSD_PLUGIN_NAME not in cls._requiredPlugins:
cls._requiredPlugins.append(MAYAUSD_PLUGIN_NAME)

for pluginToLoad in cls._requiredPlugins:
for p in cls._requiredPlugins:
# If a plugin fails to load, the entire test suite will be immediately aborted.
# Note that in the case of mtoa, the plugin might load successfully but not
# initialize properly, which means issues will only be caught in the actual tests.
cmds.loadPlugin(pluginToLoad)
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

def setUp(self):
# Maya is not closed/reset between each test of a test suite,
Expand All @@ -94,6 +97,12 @@ def setUp(self):

@classmethod
def tearDownClass(cls):
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)

if platform.system() == "Windows":
# On Windows, ADPClientService can linger around after a test ends and Maya closes,
# keeping a handle open into the temporary test directory that holds preferences,
Expand Down

0 comments on commit 0503daf

Please sign in to comment.