|
| 1 | +# Copyright 2025 Autodesk |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | + |
| 16 | +import maya.cmds as cmds |
| 17 | +import fixturesUtils |
| 18 | +import mtohUtils |
| 19 | +import testUtils |
| 20 | + |
| 21 | +class TestMayaReference(mtohUtils.MayaHydraBaseTestCase): |
| 22 | + # MayaHydraBaseTestCase.setUpClass requirement. |
| 23 | + _file = __file__ |
| 24 | + |
| 25 | + _requiredPlugins = ['mayaHydraCppTests'] |
| 26 | + |
| 27 | + IMAGE_DIFF_FAIL_THRESHOLD = 0.1 |
| 28 | + IMAGE_DIFF_FAIL_PERCENT = 2 |
| 29 | + |
| 30 | + def referenceScene(self): |
| 31 | + |
| 32 | + # Add a non-referenced object in the scene so that the scene |
| 33 | + # with the unloaded reference will still contain an object. |
| 34 | + cmds.polySphere() |
| 35 | + cmds.move(0, 0, -2) |
| 36 | + |
| 37 | + # Move the camera in closer |
| 38 | + self.setBasicCam(5) |
| 39 | + |
| 40 | + testFile = testUtils.getTestScene("testMayaReference", "aCube.ma") |
| 41 | + return cmds.file(testFile, reference=True, namespace='aCube') |
| 42 | + |
| 43 | + def test_LoadMayaReference(self): |
| 44 | + |
| 45 | + file = self.referenceScene() |
| 46 | + refNode = cmds.file(file, query=True, referenceNode=True) |
| 47 | + |
| 48 | + cmds.refresh() |
| 49 | + |
| 50 | + self.assertSnapshotClose('loadMayaReference.png', self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) |
| 51 | + |
| 52 | + # Unload the reference |
| 53 | + cmds.file(unloadReference=refNode) |
| 54 | + |
| 55 | + cmds.refresh() |
| 56 | + |
| 57 | + self.assertSnapshotClose('unloadMayaReference.png', self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) |
| 58 | + |
| 59 | + def test_EditMayaReference(self): |
| 60 | + |
| 61 | + self.referenceScene() |
| 62 | + |
| 63 | + cmds.move(0, 0, 2, '|aCube:pCube1') |
| 64 | + |
| 65 | + cmds.refresh() |
| 66 | + |
| 67 | + self.assertSnapshotClose('editMayaReference.png', self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) |
| 68 | + |
| 69 | + def test_RemoveMayaReference(self): |
| 70 | + |
| 71 | + file = self.referenceScene() |
| 72 | + |
| 73 | + cmds.refresh() |
| 74 | + |
| 75 | + # Remove the reference |
| 76 | + cmds.file(file, removeReference=True) |
| 77 | + |
| 78 | + cmds.refresh() |
| 79 | + |
| 80 | + # Same snapshot as unloaded reference. |
| 81 | + self.assertSnapshotClose('unloadMayaReference.png', self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) |
| 82 | + |
| 83 | +if __name__ == '__main__': |
| 84 | + fixturesUtils.runTests(globals()) |
0 commit comments