From 0503daf505f901e7436f107c6d1e96bcb4b828ae Mon Sep 17 00:00:00 2001 From: Pierre Tremblay Date: Mon, 18 Nov 2024 16:55:42 -0500 Subject: [PATCH] Refactored test case plugin loading and unloading. --- .../cpp/testDataProducerExample.py | 20 +------------------ .../mayaToHydra/cpp/testIsolateSelect.py | 20 +------------------ ...tIsolateSelectMayaSelectionHighlighting.py | 19 +----------------- .../cpp/testIsolateSelectSwitchToVP2.py | 19 +----------------- .../testUsdNativeInstancingIsolateSelect.py | 20 +------------------ .../testUsdPointInstancingIsolateSelect.py | 20 +------------------ ...testUsdPointInstancingIsolateSelectBBox.py | 20 +------------------ test/testUtils/mtohUtils.py | 13 ++++++++++-- 8 files changed, 18 insertions(+), 133 deletions(-) diff --git a/test/lib/mayaUsd/render/mayaToHydra/cpp/testDataProducerExample.py b/test/lib/mayaUsd/render/mayaToHydra/cpp/testDataProducerExample.py index 8670710b7..3e31a0e40 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/cpp/testDataProducerExample.py +++ b/test/lib/mayaUsd/render/mayaToHydra/cpp/testDataProducerExample.py @@ -21,8 +21,7 @@ class TestDataProducerExample(mtohUtils.MayaHydraBaseTestCase): # MayaHydraBaseTestCase.setUpClass requirement. _file = __file__ - _pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator'] - _pluginsToUnload = [] + _requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator'] def createScene(self): self._locator = cmds.createNode('MhFlowViewportAPILocator') @@ -30,23 +29,6 @@ def createScene(self): 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() diff --git a/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelect.py b/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelect.py index 59250d47b..66ce4191e 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelect.py +++ b/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelect.py @@ -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() diff --git a/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelectMayaSelectionHighlighting.py b/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelectMayaSelectionHighlighting.py index 9cf521671..b9b0d7fab 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelectMayaSelectionHighlighting.py +++ b/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelectMayaSelectionHighlighting.py @@ -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): diff --git a/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelectSwitchToVP2.py b/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelectSwitchToVP2.py index c3a48c0c8..9fabf94fe 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelectSwitchToVP2.py +++ b/test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelectSwitchToVP2.py @@ -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): diff --git a/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdNativeInstancingIsolateSelect.py b/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdNativeInstancingIsolateSelect.py index 9b0017714..9c159fd12 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdNativeInstancingIsolateSelect.py +++ b/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdNativeInstancingIsolateSelect.py @@ -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() diff --git a/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdPointInstancingIsolateSelect.py b/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdPointInstancingIsolateSelect.py index cffc75ee6..4df48cdfb 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdPointInstancingIsolateSelect.py +++ b/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdPointInstancingIsolateSelect.py @@ -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): diff --git a/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdPointInstancingIsolateSelectBBox.py b/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdPointInstancingIsolateSelectBBox.py index 3c84bbecc..110e8f4d7 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdPointInstancingIsolateSelectBBox.py +++ b/test/lib/mayaUsd/render/mayaToHydra/cpp/testUsdPointInstancingIsolateSelectBBox.py @@ -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() diff --git a/test/testUtils/mtohUtils.py b/test/testUtils/mtohUtils.py index 6310a8d45..4861787fc 100644 --- a/test/testUtils/mtohUtils.py +++ b/test/testUtils/mtohUtils.py @@ -50,6 +50,7 @@ class MayaHydraBaseTestCase(unittest.TestCase, ImageDiffingTestCase): # Variables to be set in subclasses _file = None _requiredPlugins = [] + _pluginsToUnload = [] @classmethod def setUpClass(cls): @@ -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, @@ -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,