Skip to content

Commit fdb42a7

Browse files
authored
Merge pull request #4661 from Autodesk/bailp/EMSUSD-3304/add-purpose-tests
EMSUSD-3304 add CC purpose tests
2 parents 062aecd + 2fe4465 commit fdb42a7

3 files changed

Lines changed: 206 additions & 0 deletions

File tree

test/lib/componentCreator/testComponentCreatorAddToComponentFromNodes.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ class AddToComponentFromNodesTestCase(_ComponentCreatorTestBase, unittest.TestCa
2020
def setUpClass(cls):
2121
fixturesUtils.readOnlySetUpClass(__file__, initializeStandalone=False)
2222

23+
@classmethod
24+
def tearDownClass(cls):
25+
cls._resetDefaultTemplate()
26+
return super().tearDownClass()
27+
2328
def setUp(self):
2429
self._setUpCC()
2530
# Clear the variant editor state so there is no lingering component from a
2631
# previous test.
2732
#from usd_component_creator_plugin import update_variant_editor_window
2833
#update_variant_editor_window(None, force_update=True)
34+
self._resetDefaultTemplate()
35+
return super().setUp()
2936

3037
def _createInitialComponent(self, node_name='pCube1'):
3138
"""Create a polyCube, build a single-node component, and return (proxy, desc)."""
@@ -181,6 +188,109 @@ def testTargetedVariantUnchangedAfterAdd(self):
181188
AdskUsdComponentCreator.ComponentAPI.IsVariantTarget(
182189
updated_desc, [updated_vs, updated_default_var_desc]))
183190

191+
def testAddWithPurpose(self):
192+
"""add_to_component_from_nodes with purpose specified."""
193+
from usd_component_creator_plugin import add_to_component_from_nodes
194+
proxy, desc = self._createInitialComponent('pCube1')
195+
self.assertIsNotNone(desc, 'Could not get initial ComponentDescription')
196+
first_vs = next(iter(desc.GetVariantSets().values()))
197+
198+
cmds.polyCube(name='pCube2')
199+
path2 = cmds.ls('pCube2', long=True)[0]
200+
201+
before = self._snapshotProxyShapes()
202+
203+
# Add pCube2 to the existing default variant (not a new one)
204+
result = add_to_component_from_nodes(
205+
[path2],
206+
[(first_vs.name, first_vs.default_variant)],
207+
is_replacing=False,
208+
component_desc=desc,
209+
purpose='guide')
210+
self.assertTrue(result, "add_to_component_from_nodes should return True on success")
211+
212+
new_proxy = self._findNewProxyShape(before)
213+
self.assertIsNone(new_proxy, "No new proxy shape should be created when adding to an existing component")
214+
215+
stage = mayaUsd.ufe.getStage(proxy)
216+
217+
cube_path = Sdf.Path('/root/geo/pCube1')
218+
cube_prim = stage.GetPrimAtPath(cube_path)
219+
self.assertTrue(cube_prim.IsValid(), f"{cube_path} should be a valid prim")
220+
221+
purposed_path = Sdf.Path('/root/geo/guide/pCube2')
222+
purposed_prim = stage.GetPrimAtPath(purposed_path)
223+
self.assertTrue(purposed_prim.IsValid(), f"{purposed_path} should be a valid prim after add_to_component_from_nodes with purpose")
224+
225+
def testAddWithPurposeCollidingName(self):
226+
"""add_to_component_from_nodes with purpose specified."""
227+
from usd_component_creator_plugin import add_to_component_from_nodes
228+
proxy, desc = self._createInitialComponent('pCube1')
229+
self.assertIsNotNone(desc, 'Could not get initial ComponentDescription')
230+
first_vs = next(iter(desc.GetVariantSets().values()))
231+
232+
cmds.setAttr('pCube1.translateX', 22.2)
233+
before = self._snapshotProxyShapes()
234+
235+
# Add pCube1 to the existing default variant (not a new one) under a purpose.
236+
# Because it will be placed under the purpose scope, its name will *not* conflict
237+
# with the existing pCube1
238+
result = add_to_component_from_nodes(
239+
['pCube1'],
240+
[(first_vs.name, first_vs.default_variant)],
241+
is_replacing=False,
242+
component_desc=desc,
243+
purpose='guide')
244+
self.assertTrue(result, "add_to_component_from_nodes should return True on success")
245+
new_proxy = self._findNewProxyShape(before)
246+
self.assertIsNone(new_proxy, "No new proxy shape should be created when adding to an existing component")
247+
248+
stage = mayaUsd.ufe.getStage(proxy)
249+
250+
cube_path = Sdf.Path('/root/geo/pCube1')
251+
cube_prim = stage.GetPrimAtPath(cube_path)
252+
self.assertTrue(cube_prim.IsValid(), f"{cube_path} should be a valid prim")
253+
254+
purposed_path = Sdf.Path('/root/geo/guide/pCube1')
255+
purposed_prim = stage.GetPrimAtPath(purposed_path)
256+
self.assertTrue(purposed_prim.IsValid(), f"{purposed_path} should be a valid prim after add_to_component_from_nodes with purpose")
257+
translateAttr = purposed_prim.GetAttribute('xformOp:translate')
258+
self.assertTrue(translateAttr)
259+
self.assertAlmostEqual(translateAttr.Get()[0], 22.2)
260+
261+
def testAddWithCustomPurposeScopeName(self):
262+
"""add_to_component_from_nodes with purpose specified and custom purpose scope names."""
263+
from usd_component_creator_plugin import add_to_component_from_nodes
264+
self._setCustomPurposeTemplate()
265+
proxy, desc = self._createInitialComponent('pCube1')
266+
self.assertIsNotNone(desc, 'Could not get initial ComponentDescription')
267+
first_vs = next(iter(desc.GetVariantSets().values()))
268+
269+
cmds.polyCube(name='pCube2')
270+
path2 = cmds.ls('pCube2', long=True)[0]
271+
272+
before = self._snapshotProxyShapes()
273+
274+
# Add pCube2 to the existing default variant (not a new one)
275+
result = add_to_component_from_nodes(
276+
[path2],
277+
[(first_vs.name, first_vs.default_variant)],
278+
is_replacing=False,
279+
component_desc=desc,
280+
purpose='guide')
281+
self.assertTrue(result, "add_to_component_from_nodes should return True on success")
282+
new_proxy = self._findNewProxyShape(before)
283+
self.assertIsNone(new_proxy, "No new proxy shape should be created when adding to an existing component")
284+
285+
stage = mayaUsd.ufe.getStage(proxy)
286+
287+
cube_path = Sdf.Path('/root/geo/pCube1')
288+
cube_prim = stage.GetPrimAtPath(cube_path)
289+
self.assertTrue(cube_prim.IsValid(), f"{cube_path} should be a valid prim")
290+
291+
purposed_path = Sdf.Path('/root/geo/gui/pCube2')
292+
purposed_prim = stage.GetPrimAtPath(purposed_path)
293+
self.assertTrue(purposed_prim.IsValid(), f"{purposed_path} should be a valid prim after add_to_component_from_nodes with purpose")
184294

185295

186296
if __name__ == '__main__':

test/lib/componentCreator/testComponentCreatorAddToComponentFromUsdPrims.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ class AddToComponentFromUsdPrimsTestCase(_ComponentCreatorTestBase, unittest.Tes
2020
def setUpClass(cls):
2121
fixturesUtils.readOnlySetUpClass(__file__, initializeStandalone=False)
2222

23+
@classmethod
24+
def tearDownClass(cls):
25+
cls._resetDefaultTemplate()
26+
return super().tearDownClass()
27+
2328
def setUp(self):
2429
self._setUpCC()
2530
# Clear the variant editor state so there is no lingering component from a
2631
# previous test.
2732
#from usd_component_creator_plugin import update_variant_editor_window
2833
#update_variant_editor_window(None, force_update=True)
34+
self._resetDefaultTemplate()
35+
return super().setUp()
2936

3037
def _createInitialComponent(self, node_name='pCube1'):
3138
"""Create a polyCube, build a single-node component, and return (proxy, desc)."""
@@ -108,6 +115,75 @@ def testAddWithPurpose(self):
108115
purposed_prim = stage.GetPrimAtPath(purposed_path)
109116
self.assertTrue(purposed_prim.IsValid(), f"{purposed_path} should be a valid prim after add_to_component_from_usd_prims with purpose")
110117

118+
def testAddWithPurposeCollidingName(self):
119+
"""add_to_component_from_usd_prims with purpose specified."""
120+
from usd_component_creator_plugin import add_to_component_from_usd_prims
121+
proxy, desc, proxyShape = self._createInitialComponent('pCube1')
122+
self.assertIsNotNone(desc, 'Could not get initial ComponentDescription')
123+
first_vs = next(iter(desc.GetVariantSets().values()))
124+
125+
path2 = Sdf.Path('/pCube1')
126+
prim2 = self._input_stage.DefinePrim(path2, 'Cube')
127+
prim2.GetAttribute('size').Set(22.2)
128+
before = self._snapshotProxyShapes()
129+
130+
# Add pCube1 to the existing default variant (not a new one) under a purpose.
131+
# Because it will be placed under the purpose scope, its name will *not* conflict
132+
# with the existing pCube1
133+
result = add_to_component_from_usd_prims(
134+
[f'{proxyShape},{path2}'],
135+
[(first_vs.name, first_vs.default_variant)],
136+
is_replacing=False,
137+
component_desc=desc,
138+
purpose='guide')
139+
self.assertTrue(result, "add_to_component_from_usd_prims should return True on success")
140+
new_proxy = self._findNewProxyShape(before)
141+
self.assertIsNone(new_proxy, "No new proxy shape should be created when adding to an existing component")
142+
143+
stage = mayaUsd.ufe.getStage(proxy)
144+
145+
cube_path = Sdf.Path('/root/geo/pCube1')
146+
cube_prim = stage.GetPrimAtPath(cube_path)
147+
self.assertTrue(cube_prim.IsValid(), f"{cube_path} should be a valid prim")
148+
149+
purposed_path = Sdf.Path('/root/geo/guide/pCube1')
150+
purposed_prim = stage.GetPrimAtPath(purposed_path)
151+
self.assertTrue(purposed_prim.IsValid(), f"{purposed_path} should be a valid prim after add_to_component_from_usd_prims with purpose")
152+
self.assertAlmostEqual(purposed_prim.GetAttribute('size').Get(), 22.2)
153+
154+
def testAddWithCustomPurposeScopeName(self):
155+
"""add_to_component_from_usd_prims with purpose specified and custom purpose scope names."""
156+
from usd_component_creator_plugin import add_to_component_from_usd_prims
157+
self._setCustomPurposeTemplate()
158+
proxy, desc, proxyShape = self._createInitialComponent('pCube1')
159+
self.assertIsNotNone(desc, 'Could not get initial ComponentDescription')
160+
first_vs = next(iter(desc.GetVariantSets().values()))
161+
162+
path2 = Sdf.Path('/pCube2')
163+
self._input_stage.DefinePrim(path2, 'Cube')
164+
before = self._snapshotProxyShapes()
165+
166+
# Add pCube2 to the existing default variant (not a new one)
167+
result = add_to_component_from_usd_prims(
168+
[f'{proxyShape},{path2}'],
169+
[(first_vs.name, first_vs.default_variant)],
170+
is_replacing=False,
171+
component_desc=desc,
172+
purpose='guide')
173+
self.assertTrue(result, "add_to_component_from_usd_prims should return True on success")
174+
new_proxy = self._findNewProxyShape(before)
175+
self.assertIsNone(new_proxy, "No new proxy shape should be created when adding to an existing component")
176+
177+
stage = mayaUsd.ufe.getStage(proxy)
178+
179+
cube_path = Sdf.Path('/root/geo/pCube1')
180+
cube_prim = stage.GetPrimAtPath(cube_path)
181+
self.assertTrue(cube_prim.IsValid(), f"{cube_path} should be a valid prim")
182+
183+
purposed_path = Sdf.Path('/root/geo/gui/pCube2')
184+
purposed_prim = stage.GetPrimAtPath(purposed_path)
185+
self.assertTrue(purposed_prim.IsValid(), f"{purposed_path} should be a valid prim after add_to_component_from_usd_prims with purpose")
186+
111187
def testDefaultVariantUnchanged(self):
112188
"""Adding a node to an existing variant must not change the default_variant name."""
113189
from usd_component_creator_plugin import add_to_component_from_usd_prims

test/lib/componentCreator/testComponentCreatorBase.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ def _getDescFromStage(self, stage):
3939
import AdskUsdComponentCreator
4040
return AdskUsdComponentCreator.ComponentDescription.CreateFromStageMetadata(stage)
4141

42+
@classmethod
43+
def _setCustomPurposeTemplate(cls):
44+
import AdskUsdComponentCreator
45+
options = AdskUsdComponentCreator.GetKnownOptions('ASWF Standard (default)')
46+
options = options.Clone()
47+
options.purpose_scope_names = {
48+
'guide' : 'gui',
49+
'proxy' : 'prox',
50+
'render': 'rend',
51+
}
52+
options_name = 'test_options'
53+
AdskUsdComponentCreator.AddKnownOptions(options_name, options)
54+
from usd_component_creator_plugin import save_selected_component_options_name
55+
save_selected_component_options_name(options_name)
56+
57+
@classmethod
58+
def _resetDefaultTemplate(cls):
59+
from usd_component_creator_plugin import save_selected_component_options_name
60+
save_selected_component_options_name('ASWF Standard (default)')
61+
4262
def _createComponent(self):
4363
"""Create a new Adsk USD Component with a `model/default` variant and a
4464
proxy shape pointing to its root layer.

0 commit comments

Comments
 (0)