def testMakeConnectionAndUndoAndRedo(self): s = Gaffer.ScriptNode() s["a"] = GafferTest.AddNode() s["n"] = GafferTest.ArrayPlugNode() with Gaffer.UndoContext(s): s["n"]["in"][0].setInput(s["a"]["sum"]) self.assertEqual(len(s["n"]["in"]), 2) self.assertTrue(s["n"]["in"][0].isSame(s["n"]["in"]["e1"])) self.assertTrue(s["n"]["in"][1].isSame(s["n"]["in"]["e2"])) s.undo() self.assertEqual(len(s["n"]["in"]), 1) self.assertTrue(s["n"]["in"][0].isSame(s["n"]["in"]["e1"])) s.redo() self.assertEqual(len(s["n"]["in"]), 2) self.assertTrue(s["n"]["in"][0].isSame(s["n"]["in"]["e1"])) self.assertTrue(s["n"]["in"][1].isSame(s["n"]["in"]["e2"])) s.undo() self.assertEqual(len(s["n"]["in"]), 1) self.assertTrue(s["n"]["in"][0].isSame(s["n"]["in"]["e1"])) self.assertTrue("in" in s["n"]) self.assertFalse("in1" in s["n"])
def testInputConnectionMaintainedOnNestedNoduleMove(self): s = Gaffer.ScriptNode() g = GafferUI.GraphGadget(s) s["n1"] = GafferTest.AddNode() s["n2"] = GafferTest.ArrayPlugNode() Gaffer.Metadata.registerValue(s["n2"]["in"], "nodule:type", "GafferUI::CompoundNodule") s["n2"]["in"][0].setInput(s["n1"]["sum"]) self.assertTrue(g.connectionGadget(s["n2"]["in"][0]) is not None) for section in ("top", "bottom", "top", "left", "right", "left", "bottom", "right"): Gaffer.Metadata.registerValue(s["n2"]["in"], "noduleLayout:section", section) connection = g.connectionGadget(s["n2"]["in"][0]) self.assertTrue(connection is not None) self.assertTrue(connection.srcNodule() is not None) self.assertTrue(connection.srcNodule().isSame( g.nodeGadget(s["n1"]).nodule(s["n1"]["sum"]))) self.assertTrue(connection.dstNodule().isSame( g.nodeGadget(s["n2"]).nodule(s["n2"]["in"][0])))
def testSerialisation(self): s = Gaffer.ScriptNode() s["a"] = GafferTest.AddNode() s["n"] = GafferTest.ArrayPlugNode() s["n"]["in"][0].setInput(s["a"]["sum"]) s["n"]["in"][1].setInput(s["a"]["sum"]) s["n"]["in"][2].setInput(s["a"]["sum"]) s["n"]["in"][1].setInput(None) self.assertEqual(len(s["n"]["in"]), 4) self.assertTrue(s["n"]["in"]["e1"].isSame(s["n"]["in"][0])) self.assertTrue(s["n"]["in"]["e2"].isSame(s["n"]["in"][1])) self.assertTrue(s["n"]["in"]["e3"].isSame(s["n"]["in"][2])) self.assertTrue(s["n"]["in"]["e4"].isSame(s["n"]["in"][3])) self.assertTrue(s["n"]["in"]["e1"].getInput(), s["a"]["sum"]) self.assertTrue(s["n"]["in"]["e2"].getInput() is None) self.assertTrue(s["n"]["in"]["e3"].getInput(), s["a"]["sum"]) self.assertTrue(s["n"]["in"]["e4"].getInput() is None) s2 = Gaffer.ScriptNode() s2.execute(s.serialise()) self.assertEqual(len(s2["n"]["in"]), 4) self.assertTrue(s2["n"]["in"]["e1"].isSame(s2["n"]["in"][0])) self.assertTrue(s2["n"]["in"]["e2"].isSame(s2["n"]["in"][1])) self.assertTrue(s2["n"]["in"]["e3"].isSame(s2["n"]["in"][2])) self.assertTrue(s2["n"]["in"]["e4"].isSame(s2["n"]["in"][3])) self.assertTrue(s2["n"]["in"]["e1"].getInput(), s2["a"]["sum"]) self.assertTrue(s2["n"]["in"]["e2"].getInput() is None) self.assertTrue(s2["n"]["in"]["e3"].getInput(), s2["a"]["sum"]) self.assertTrue(s2["n"]["in"]["e4"].getInput() is None)
def testArrayPlugSerialisation(self): s = Gaffer.ScriptNode() s["b"] = Gaffer.Box() s["b"]["n"] = GafferTest.ArrayPlugNode() s["b"]["i"] = Gaffer.BoxIn() s["b"]["i"]["name"].setValue("in") s["b"]["i"].setup(s["b"]["n"]["in"]) s["b"]["n"]["in"].setInput(s["b"]["i"]["out"]) s2 = Gaffer.ScriptNode() s2.execute(s.serialise()) self.assertTrue(s2["b"]["n"]["in"].source().isSame(s2["b"]["in"]))
def test(self): a = GafferTest.AddNode() n = GafferTest.ArrayPlugNode() self.assertTrue("e1" in n["in"]) self.assertTrue("e2" not in n["in"]) self.assertEqual(len(n["in"]), 1) self.assertTrue(n["in"]["e1"].isSame(n["in"][0])) n["in"][0].setInput(a["sum"]) self.assertEqual(len(n["in"]), 2) self.assertTrue("e1" in n["in"]) self.assertTrue("e2" in n["in"]) n["in"][0].setInput(None) self.assertTrue("e1" in n["in"]) self.assertTrue("e2" not in n["in"]) self.assertEqual(len(n["in"]), 1)
def testSerialisationUsesIndices( self ) : s = Gaffer.ScriptNode() s["a"] = GafferTest.AddNode() s["n"] = GafferTest.ArrayPlugNode() s["n"]["in"][0].setInput( s["a"]["sum"] ) s["n"]["in"][1].setInput( s["a"]["sum"] ) ss = s.serialise() self.assertNotIn( "[\"" + s["n"]["in"][0].getName() + "\"]", ss ) self.assertNotIn( "[\"" + s["n"]["in"][1].getName() + "\"]", ss ) self.assertIn( "[0].setInput", ss ) self.assertIn( "[1].setInput", ss ) s2 = Gaffer.ScriptNode() s2.execute( ss ) self.assertEqual( s2["n"]["in"][0].getInput(), s2["a"]["sum"] ) self.assertEqual( s2["n"]["in"][1].getInput(), s2["a"]["sum"] )
def testPromotedArrayPlugRemovalDeletesBoxIn(self): s = Gaffer.ScriptNode() s["b"] = Gaffer.Box() s["b"]["n"] = GafferTest.ArrayPlugNode() s["b"]["i"] = Gaffer.BoxIn() s["b"]["i"]["name"].setValue("in") s["b"]["i"].setup(s["b"]["n"]["in"]) s["b"]["n"]["in"].setInput(s["b"]["i"]["out"]) def assertPreconditions(): self.assertTrue("in" in s["b"]) self.assertTrue("i" in s["b"]) self.assertTrue(len(s["b"]["i"]["out"].outputs()), 1) self.assertTrue(s["b"]["n"]["in"].source().isSame(s["b"]["in"])) assertPreconditions() with Gaffer.UndoScope(s): del s["b"]["in"] def assertPostconditions(): self.assertFalse("in" in s["b"]) self.assertFalse("i" in s["b"]) self.assertTrue(s["b"]["n"]["in"].getInput() is None) assertPostconditions() s.undo() assertPreconditions() s.redo() assertPostconditions()
def testDeleteInputNodeAndUndoAndRedo(self): s = Gaffer.ScriptNode() s["a"] = GafferTest.AddNode() s["n"] = GafferTest.ArrayPlugNode() s["n"]["in"][0].setInput(s["a"]["sum"]) s["n"]["in"][1].setInput(s["a"]["sum"]) s["n"]["in"][2].setInput(s["a"]["sum"]) n = s["n"] self.assertEqual(len(s["n"]["in"]), 4) self.assertTrue(s["n"]["in"][0].getInput().isSame(s["a"]["sum"])) self.assertTrue(s["n"]["in"][1].getInput().isSame(s["a"]["sum"])) self.assertTrue(s["n"]["in"][2].getInput().isSame(s["a"]["sum"])) with Gaffer.UndoContext(s): s.deleteNodes(s, Gaffer.StandardSet([s["a"]])) self.assertFalse("a" in s) s.undo() self.assertEqual(len(s["n"]["in"]), 4) self.assertTrue(s["n"]["in"][0].getInput().isSame(s["a"]["sum"])) self.assertTrue(s["n"]["in"][1].getInput().isSame(s["a"]["sum"])) self.assertTrue(s["n"]["in"][2].getInput().isSame(s["a"]["sum"])) s.redo() self.assertFalse("a" in s) s.undo() self.assertEqual(len(s["n"]["in"]), 4) self.assertTrue(s["n"]["in"][0].getInput().isSame(s["a"]["sum"])) self.assertTrue(s["n"]["in"][1].getInput().isSame(s["a"]["sum"])) self.assertTrue(s["n"]["in"][2].getInput().isSame(s["a"]["sum"]))
def testPromoteArrayPlug( self ) : s = Gaffer.ScriptNode() s["a"] = GafferTest.AddNode() s["b"] = Gaffer.Box() s["b"]["n"] = GafferTest.ArrayPlugNode() p = s["b"].promotePlug( s["b"]["n"]["in"] ) p.setName( "p" ) s["b"]["p"][0].setInput( s["a"]["sum"] ) s["b"]["p"][1].setInput( s["a"]["sum"] ) self.assertEqual( len( s["b"]["n"]["in"] ), 3 ) self.assertTrue( s["b"]["n"]["in"].getInput().isSame( s["b"]["p"] ) ) s2 = Gaffer.ScriptNode() s2.execute( s.serialise() ) self.assertEqual( len( s2["b"]["n"]["in"] ), 3 ) self.assertTrue( s2["b"]["n"]["in"].getInput().isSame( s2["b"]["p"] ) )
def testConnectionGaps(self): a = GafferTest.AddNode() n = GafferTest.ArrayPlugNode() n["in"][0].setInput(a["sum"]) n["in"][1].setInput(a["sum"]) n["in"][2].setInput(a["sum"]) self.assertEqual(len(n["in"]), 4) self.assertTrue(n["in"]["e1"].getInput(), a["sum"]) self.assertTrue(n["in"]["e2"].getInput(), a["sum"]) self.assertTrue(n["in"]["e3"].getInput(), a["sum"]) self.assertTrue(n["in"]["e4"].getInput() is None) n["in"][1].setInput(None) self.assertEqual(len(n["in"]), 4) self.assertTrue(n["in"]["e1"].getInput(), a["sum"]) self.assertTrue(n["in"]["e2"].getInput() is None) self.assertTrue(n["in"]["e3"].getInput(), a["sum"]) self.assertTrue(n["in"]["e4"].getInput() is None)
def testMaximumInputs(self): a = GafferTest.AddNode() n = GafferTest.ArrayPlugNode() # connect all inputs for i in range(0, 6): n["in"][i].setInput(a["sum"]) self.assertEqual(len(n["in"]), 6) for i in range(0, 6): self.assertTrue(n["in"][i].getInput().isSame(a["sum"])) # check that removing the one before the last # leaves the last in place. n["in"][4].setInput(None) self.assertEqual(len(n["in"]), 6) for i in range(0, 6): if i != 4: self.assertTrue(n["in"][i].getInput().isSame(a["sum"])) else: self.assertTrue(n["in"][i].getInput() is None)