1#!/pxrpythonsubst
2#
3# Copyright 2017 Pixar
4#
5# Licensed under the Apache License, Version 2.0 (the "Apache License")
6# with the following modification; you may not use this file except in
7# compliance with the Apache License and the following modification to it:
8# Section 6. Trademarks. is deleted and replaced with:
9#
10# 6. Trademarks. This License does not grant permission to use the trade
11#    names, trademarks, service marks, or product names of the Licensor
12#    and its affiliates, except as required to comply with Section 4(c) of
13#    the License and to reproduce the content of the NOTICE file.
14#
15# You may obtain a copy of the Apache License at
16#
17#     http://www.apache.org/licenses/LICENSE-2.0
18#
19# Unless required by applicable law or agreed to in writing, software
20# distributed under the Apache License with the above modification is
21# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22# KIND, either express or implied. See the Apache License for the specific
23# language governing permissions and limitations under the Apache License.
24
25# Regression test case for bug 70951. Adding inert prim specs was not
26# properly updating the 'hasSpecs' field on the associated node in the
27# prim index.
28
29from pxr import Sdf, Pcp
30import unittest
31
32class TestPcpRegressionBugs_bug70951(unittest.TestCase):
33    def test_Basic(self):
34        rootLayer = Sdf.Layer.FindOrOpen('bug70951/root.sdf')
35        refLayer = Sdf.Layer.FindOrOpen('bug70951/JoyGroup.sdf')
36
37        pcpCache = Pcp.Cache(Pcp.LayerStackIdentifier(rootLayer))
38
39        # Compute the prim index for the Sim scope under JoyGroup. This index
40        # should consist of two nodes: the direct node and the reference node.
41        # Since there is no spec for the Sim scope in the root layer, the root node
42        # should be marked as such.
43        (primIndex, errors) = \
44            pcpCache.ComputePrimIndex('/World/anim/chars/JoyGroup/Sim')
45        self.assertEqual(len(errors), 0)
46        self.assertEqual(primIndex.primStack, [refLayer.GetPrimAtPath('/JoyGroup/Sim')])
47        self.assertFalse(primIndex.rootNode.hasSpecs)
48
49        # Now create an empty over for the Sim scope in the root layer and verify
50        # that the prim index sees this new spec after change processing.
51        with Pcp._TestChangeProcessor(pcpCache):
52            emptyOver = \
53                Sdf.CreatePrimInLayer(rootLayer, '/World/anim/chars/JoyGroup/Sim')
54            self.assertTrue(emptyOver.IsInert())
55
56        (primIndex, errors) = \
57            pcpCache.ComputePrimIndex('/World/anim/chars/JoyGroup/Sim')
58        self.assertEqual(len(errors), 0)
59        self.assertEqual(primIndex.primStack,
60                    [rootLayer.GetPrimAtPath('/World/anim/chars/JoyGroup/Sim'),
61                     refLayer.GetPrimAtPath('/JoyGroup/Sim')])
62        self.assertTrue(primIndex.rootNode.hasSpecs)
63
64if __name__ == "__main__":
65    unittest.main()
66