

def testUndo(self):
    s = Gaffer.ScriptNode()
    s['b'] = Gaffer.Box()
    s['b']['p'] = Gaffer.Plug(flags=(Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic))
    s['b'].exportForReference('/tmp/test.grf')
    s['r'] = Gaffer.Reference()
    self.assertEqual(s['r'].fileName(), '')
    self.assertTrue(('p' not in s['r']))
    State = collections.namedtuple('State', ['keys', 'fileName'])
    states = []

    def referenceLoaded(node):
        states.append(State(keys=node.keys(), fileName=node.fileName()))
    c = s['r'].referenceLoadedSignal().connect(referenceLoaded)
    with Gaffer.UndoContext(s):
        s['r'].load('/tmp/test.grf')
    self.assertTrue(('p' in s['r']))
    self.assertEqual(s['r'].fileName(), '/tmp/test.grf')
    self.assertTrue(len(states), 1)
    self.assertEqual(states[0], State(['user', 'p'], '/tmp/test.grf'))
    s.undo()
    self.assertEqual(s['r'].fileName(), '')
    self.assertTrue(('p' not in s['r']))
    self.assertTrue(len(states), 2)
    self.assertEqual(states[1], State(['user'], ''))
    s.redo()
    self.assertTrue(('p' in s['r']))
    self.assertEqual(s['r'].fileName(), '/tmp/test.grf')
    self.assertTrue(len(states), 3)
    self.assertEqual(states[2], State(['user', 'p'], '/tmp/test.grf'))

dataset/ETHPy150Open ImageEngine/gaffer/python/GafferTest/ReferenceTest.py ReferenceTest.testUndo/original