def testBackgroundThreadMonitoring(self): s = Gaffer.ScriptNode() s["n"] = GafferTest.MultiplyNode() s["n"]["op2"].setValue(1) s["e"] = Gaffer.Expression() s["e"].setExpression("""parent["n"]["op1"] = context["op1"]""") def backgroundFunction(): with Gaffer.Context() as c: for i in range(0, 10000): c["op1"] = i self.assertEqual(s["n"]["product"].getValue(), i) with Gaffer.PerformanceMonitor() as m: t = Gaffer.ParallelAlgo.callOnBackgroundThread( s["n"]["product"], backgroundFunction) t.wait() # The monitor was active when we launched the background # process, so we expect it to have been transferred to the # background thread and remained active there for the duration. self.assertEqual( m.plugStatistics(s["n"]["product"]).computeCount, 10000)
def testHash(self): # we want the output of the time warp to have the same hash # as the input at the appropriate point in time. that way we get # to share cache entries between the nodes and use less memory # and do less computation. s = Gaffer.ScriptNode() s["m"] = GafferTest.MultiplyNode() s["m"]["op2"].setValue(1) s["e"] = Gaffer.Expression() s["e"]["engine"].setValue("python") s["e"]["expression"].setValue( "parent[\"m\"][\"op1\"] = int( context[\"frame\"] )") s["w"] = Gaffer.TimeWarpComputeNode() s["w"]["in"] = Gaffer.IntPlug() s["w"]["in"].setInput(s["m"]["product"]) s["w"]["out"] = Gaffer.IntPlug(direction=Gaffer.Plug.Direction.Out) s["w"]["offset"].setValue(2) for i in range(0, 10): c = Gaffer.Context() c.setFrame(i) with c: self.assertEqual(s["m"]["product"].getValue(), i) self.assertEqual(s["w"]["out"].getValue(), i + 2) wh = s["w"]["out"].hash() c.setFrame(i + 2) with c: mh = s["m"]["product"].hash() self.assertEqual(wh, mh)
def test(self): s = Gaffer.ScriptNode() s["m"] = GafferTest.MultiplyNode() s["m"]["op2"].setValue(1) s["e"] = Gaffer.Expression() s["e"]["engine"].setValue("python") s["e"]["expression"].setValue( "parent[\"m\"][\"op1\"] = int( context[\"frame\"] )") s["w"] = Gaffer.TimeWarpComputeNode() s["w"]["in"] = Gaffer.IntPlug() s["w"]["in"].setInput(s["m"]["product"]) s["w"]["out"] = Gaffer.IntPlug(direction=Gaffer.Plug.Direction.Out) s["w"]["offset"].setValue(2) s["w"]["speed"].setValue(2) for i in range(0, 10): c = Gaffer.Context() c.setFrame(i) with c: self.assertEqual(s["m"]["product"].getValue(), i) self.assertEqual(s["w"]["out"].getValue(), i * 2 + 2)
def testExtendedNodeDescription( self ) : multiply = GafferTest.MultiplyNode() self.assertEqual( Gaffer.Metadata.nodeDescription( multiply ), "" ) Gaffer.Metadata.registerNodeDescription( GafferTest.MultiplyNode, "description", "op1", "op1 description", "op2", { "description" : "op2 description", "otherValue" : 100, } ) self.assertEqual( Gaffer.Metadata.nodeDescription( multiply ), "description" ) self.assertEqual( Gaffer.Metadata.plugDescription( multiply["op1"] ), "op1 description" ) self.assertEqual( Gaffer.Metadata.plugDescription( multiply["op2"] ), "op2 description" ) self.assertEqual( Gaffer.Metadata.value( multiply["op2"], "otherValue" ), 100 )
def test( self ) : s = Gaffer.ScriptNode() s["m1"] = GafferTest.MultiplyNode() s["m1"]["op1"].setValue( 10 ) s["m1"]["op2"].setValue( 20 ) s["m2"] = GafferTest.MultiplyNode() s["m2"]["op2"].setValue( 1 ) s["e"] = Gaffer.Expression() s["e"]["engine"].setValue( "python" ) s["e"]["expression"].setValue( "parent[\"m2\"][\"op1\"] = parent[\"m1\"][\"product\"] * 2" ) self.assertEqual( s["m2"]["product"].getValue(), 400 )
def testNameDoesntAffectHeight(self): n = GafferTest.MultiplyNode("a") g = GafferUI.StandardNodeGadget(n) h = g.bound().size().y n.setName("hg") self.assertEqual(g.bound().size().y, h)
def testEdgeGadgets(self): n = GafferTest.MultiplyNode() g = GafferUI.StandardNodeGadget(n) for name, edge in g.Edge.names.items(): eg = GafferUI.TextGadget(name) g.setEdgeGadget(edge, eg) self.assertTrue(g.getEdgeGadget(edge).isSame(eg))
def testEdgeMetadataChange( self ) : n = GafferTest.MultiplyNode() g = GafferUI.StandardNodeGadget( n ) self.assertEqual( g.connectionTangent( g.nodule( n["op2"] ) ), imath.V3f( 0, 1, 0 ) ) Gaffer.Metadata.registerValue( n["op2"], "noduleLayout:section", "left" ) self.assertEqual( g.connectionTangent( g.nodule( n["op2"] ) ), imath.V3f( -1, 0, 0 ) )
def testSetExpressionWithNoEngine( self ) : s = Gaffer.ScriptNode() s["m"] = GafferTest.MultiplyNode() s["e"] = Gaffer.Expression() s["e"]["engine"].setValue( "" ) s["e"]["expression"].setValue( "parent[\"m\"][\"op2\"] = int( context[\"frame\"] * 2 )" )
def testEdgeMetadataChange( self ) : n = GafferTest.MultiplyNode() g = GafferUI.StandardNodeGadget( n ) self.assertEqual( g.noduleTangent( g.nodule( n["op2"] ) ), IECore.V3f( 0, 1, 0 ) ) Gaffer.Metadata.registerValue( n["op2"], "nodeGadget:nodulePosition", "left" ) self.assertEqual( g.noduleTangent( g.nodule( n["op2"] ) ), IECore.V3f( -1, 0, 0 ) )
def testCacheValidation(self): defaultHashCacheMode = Gaffer.ValuePlug.getHashCacheMode() Gaffer.ValuePlug.setHashCacheMode( Gaffer.ValuePlug.HashCacheMode.Checked) try: m = GafferTest.MultiplyNode("test", True) m["op1"].setValue(2) m["op2"].setValue(3) self.assertEqual(m["product"].getValue(), 6) m["op2"].setValue(4) exception = None try: m["product"].getValue() except Exception as e: exception = e self.assertEqual(type(exception), Gaffer.ProcessException) self.assertEqual( str(exception), "test.product : Detected undeclared dependency. Fix DependencyNode::affects() implementation." ) # Make sure the plug with the actual issue is reported, when queried from a downstream network m2 = GafferTest.MultiplyNode("second") m2["op1"].setInput(m["product"]) m2["op2"].setValue(5) exception = None try: m2["product"].getValue() except Exception as e: exception = e self.assertEqual(type(exception), Gaffer.ProcessException) self.assertEqual( str(exception), "test.product : Detected undeclared dependency. Fix DependencyNode::affects() implementation." ) finally: Gaffer.ValuePlug.setHashCacheMode(defaultHashCacheMode)
def testEdgeGadgets( self ) : n = GafferTest.MultiplyNode() g = GafferUI.AuxiliaryNodeGadget( n ) for name, edge in g.Edge.names.items() : self.assertTrue( g.getEdgeGadget( edge ) is None ) eg = GafferUI.TextGadget( name ) g.setEdgeGadget( edge, eg ) self.assertTrue( g.getEdgeGadget( edge ) is None )
def testNodulePositionMetadata( self ) : n = GafferTest.MultiplyNode() g = GafferUI.StandardNodeGadget( n ) self.assertEqual( g.noduleTangent( g.nodule( n["op1"] ) ), IECore.V3f( 0, 1, 0 ) ) Gaffer.Metadata.registerPlugValue( n.typeId(), "op1", "nodeGadget:nodulePosition", "left" ) g = GafferUI.StandardNodeGadget( n ) self.assertEqual( g.noduleTangent( g.nodule( n["op1"] ) ), IECore.V3f( -1, 0, 0 ) )
def testNodulePositionMetadata( self ) : n = GafferTest.MultiplyNode() g = GafferUI.StandardNodeGadget( n ) self.assertEqual( g.connectionTangent( g.nodule( n["op1"] ) ), imath.V3f( 0, 1, 0 ) ) Gaffer.Metadata.registerValue( n.typeId(), "op1", "noduleLayout:section", "left" ) g = GafferUI.StandardNodeGadget( n ) self.assertEqual( g.connectionTangent( g.nodule( n["op1"] ) ), imath.V3f( -1, 0, 0 ) )
def testComponentsWithMetaData( self ) : s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() s["n2"] = GafferTest.AddNode() s["n3"] = GafferTest.AddNode() s["m"] = GafferTest.MultiplyNode() self.assertEqual( Gaffer.Metadata.nodesWithMetadata( s, "nodeData1"), [] ) # register instance node values on n and n2: Gaffer.Metadata.registerValue( s["n"], "nodeData1", "something" ) Gaffer.Metadata.registerValue( s["n2"], "nodeData2", "something" ) Gaffer.Metadata.registerValue( s["m"], "nodeData3", "something" ) Gaffer.Metadata.registerValue( s["n"], "nodeData3", "something" ) # register class value on GafferTest.AddNode: Gaffer.Metadata.registerValue( GafferTest.AddNode, "nodeData3", "something" ) # register some instance plug values: Gaffer.Metadata.registerValue( s["n"]["op1"], "plugData1", "something" ) Gaffer.Metadata.registerValue( s["n2"]["op2"], "plugData2", "something" ) Gaffer.Metadata.registerValue( s["m"]["op2"], "plugData3", "something" ) Gaffer.Metadata.registerValue( s["m"]["op1"], "plugData3", "something" ) # register class value on GafferTest.AddNode: Gaffer.Metadata.registerValue( GafferTest.AddNode, "op1", "plugData3", "somethingElse" ) # test it lists nodes with matching data: self.assertEqual( Gaffer.Metadata.nodesWithMetadata( s, "nodeData1" ), [ s["n"] ] ) self.assertEqual( Gaffer.Metadata.nodesWithMetadata( s, "nodeData2" ), [ s["n2"] ] ) self.assertEqual( Gaffer.Metadata.nodesWithMetadata( s, "nodeData3" ), [ s["n"], s["n2"], s["n3"], s["m"] ] ) self.assertEqual( set(Gaffer.Metadata.nodesWithMetadata( s, "nodeData3", instanceOnly=True )), set([ s["n"], s["m"] ]) ) # telling it to list plugs should make it return an empty list: self.assertEqual( Gaffer.Metadata.plugsWithMetadata( s, "nodeData1" ), [] ) self.assertEqual( Gaffer.Metadata.plugsWithMetadata( s, "nodeData3" ), [] ) # test it lists plugs with matching data: self.assertEqual( Gaffer.Metadata.plugsWithMetadata( s, "plugData1" ), [ s["n"]["op1"] ] ) self.assertEqual( Gaffer.Metadata.plugsWithMetadata( s, "plugData2" ), [ s["n2"]["op2"] ] ) self.assertEqual( Gaffer.Metadata.plugsWithMetadata( s, "plugData3" ), [ s["n"]["op1"], s["n2"]["op1"], s["n3"]["op1"], s["m"]["op1"], s["m"]["op2"] ] ) self.assertEqual( set( Gaffer.Metadata.plugsWithMetadata( s, "plugData3", instanceOnly=True ) ), set( [ s["m"]["op1"], s["m"]["op2"] ] ) ) # telling it to list nodes should make it return an empty list: self.assertEqual( Gaffer.Metadata.nodesWithMetadata( s, "plugData1" ), [] ) self.assertEqual( Gaffer.Metadata.nodesWithMetadata( s, "plugData3" ), [] ) # test child removal: m = s["m"] s.removeChild( m ) self.assertEqual( Gaffer.Metadata.plugsWithMetadata( s, "plugData3", instanceOnly=True ), [] ) self.assertEqual( Gaffer.Metadata.nodesWithMetadata( s, "nodeData3", instanceOnly=True ), [ s["n"] ] )
def testDeleteNodesMaintainsConnections(self): s = Gaffer.ScriptNode() n1 = GafferTest.AddNode() n2 = GafferTest.MultiplyNode() n3 = GafferTest.AddNode() n4 = GafferTest.AddNode() s.addChild(n1) s.addChild(n2) s.addChild(n3) s.addChild(n4) n2["op1"].setInput(n1["sum"]) n2["op2"].setInput(n1["sum"]) n3["op1"].setInput(n1["sum"]) n3["op2"].setInput(n1["sum"]) n4["op1"].setInput(n2["product"]) n4["op2"].setInput(n3["sum"]) self.assert_(n2["op1"].getInput().isSame(n1["sum"])) self.assert_(n2["op2"].getInput().isSame(n1["sum"])) self.assert_(n3["op1"].getInput().isSame(n1["sum"])) self.assert_(n3["op2"].getInput().isSame(n1["sum"])) self.assert_(n4["op1"].getInput().isSame(n2["product"])) self.assert_(n4["op2"].getInput().isSame(n3["sum"])) s.deleteNodes(filter=Gaffer.StandardSet([n2, n3])) self.assertEqual(n2["op1"].getInput(), None) self.assertEqual(n2["op2"].getInput(), None) self.assertEqual(n3["op1"].getInput(), None) self.assertEqual(n3["op2"].getInput(), None) # None because MultiplyOp does not define enabledPlug() self.assertEqual(n4["op1"].getInput(), None) self.assert_(n4["op2"].getInput().isSame(n1["sum"])) n2["op1"].setInput(n1["sum"]) n2["op2"].setInput(n1["sum"]) n3["op1"].setInput(n1["sum"]) n3["op2"].setInput(n1["sum"]) n4["op1"].setInput(n2["product"]) n4["op2"].setInput(n3["sum"]) s.addChild(n2) s.addChild(n3) s.deleteNodes(filter=Gaffer.StandardSet([n2, n3]), reconnect=False) self.assertEqual(n2["op1"].getInput(), None) self.assertEqual(n2["op2"].getInput(), None) self.assertEqual(n3["op1"].getInput(), None) self.assertEqual(n3["op2"].getInput(), None) self.assertEqual(n4["op1"].getInput(), None) self.assertEqual(n4["op2"].getInput(), None)
def testDeleteNodesInInputChanged( self ) : s = Gaffer.ScriptNode() s["n1"] = GafferTest.MultiplyNode() s["n2"] = GafferTest.MultiplyNode() s["n3"] = GafferTest.MultiplyNode() s["n4"] = Gaffer.Node() s["n3"]["op1"].setInput( s["n2"]["product"] ) s["n4"]["user"]["d"] = Gaffer.IntPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) s["n4"]["user"]["d"].setInput( s["n3"]["product"] ) def inputChanged( plug ) : del s["n3"] del s["n4"] c = s["n2"].plugInputChangedSignal().connect( inputChanged ) s["n2"]["op1"].setInput( s["n1"]["product"] )
def testSerialisationCreationOrder( self ) : # Create a script where the expression node is created before the nodes it's targeting, # and make sure it still serialises/loads correctly. s = Gaffer.ScriptNode() s["e"] = Gaffer.Expression() s["m1"] = GafferTest.MultiplyNode() s["m1"]["op1"].setValue( 10 ) s["m1"]["op2"].setValue( 20 ) s["m2"] = GafferTest.MultiplyNode() s["m2"]["op2"].setValue( 1 ) s["e"]["expression"].setValue( "parent[\"m2\"][\"op1\"] = parent[\"m1\"][\"product\"] * 2" ) self.assertEqual( s["m2"]["product"].getValue(), 400 ) s2 = Gaffer.ScriptNode() s2.execute( s.serialise() ) self.assertEqual( s2["m2"]["product"].getValue(), 400 )
def testDeleteExpressionText( self ) : s = Gaffer.ScriptNode() s["m1"] = GafferTest.MultiplyNode() s["m1"]["op1"].setValue( 10 ) s["m1"]["op2"].setValue( 20 ) s["m2"] = GafferTest.MultiplyNode() s["m2"]["op2"].setValue( 1 ) s["e"] = Gaffer.Expression() s["e"]["engine"].setValue( "python" ) s["e"].setExpression( "parent[\"m2\"][\"op1\"] = parent[\"m1\"][\"product\"] * 2" ) self.failUnless( s["m2"]["op1"].getInput().node().isSame( s["e"] ) ) self.assertEqual( s["m2"]["product"].getValue(), 400 ) s["e"].setExpression( "" ) self.failUnless( s["m2"]["op1"].getInput() is None ) self.assertEqual( s["m2"]["product"].getValue(), 0 )
def testConstruction( self ) : m = GafferTest.MultiplyNode() self.failUnless( isinstance( m, GafferTest.MultiplyNode ) ) m = GafferTest.MultiplyNode( "a" ) self.failUnless( isinstance( m, GafferTest.MultiplyNode ) ) self.assertEqual( m.getName(), "a" ) m = GafferTest.MultiplyNode( "a" ) m["op1"].setValue( 1 ) m["op2"].setValue( 2 ) self.failUnless( isinstance( m, GafferTest.MultiplyNode ) ) self.assertEqual( m.getName(), "a" ) self.assertEqual( m["op1"].getValue(), 1 ) self.assertEqual( m["op2"].getValue(), 2 ) m = GafferTest.MultiplyNode( "a" ) m["a"] = Gaffer.IntPlug() self.assertEqual( m.getName(), "a" ) self.failUnless( isinstance( m["a"], Gaffer.IntPlug ) )
def testCreateExpressionWithWatchers(self): s = Gaffer.ScriptNode() def f(plug): plug.getValue() s["m1"] = GafferTest.MultiplyNode() c = s["m1"].plugDirtiedSignal().connect(f) s["e"] = Gaffer.Expression() s["e"]["expression"].setValue("parent[\"m1\"][\"op1\"] = 2")
def testEnableBehaviour(self): n = Gaffer.DependencyNode() self.assertEqual(n.enabledPlug(), None) m = GafferTest.MultiplyNode() self.assertEqual(m.enabledPlug(), None) self.assertEqual(m.correspondingInput(m["product"]), None) class EnableAbleNode(Gaffer.DependencyNode): def __init__(self, name="EnableAbleNode"): Gaffer.DependencyNode.__init__(self, name) self.addChild( Gaffer.BoolPlug("enabled", Gaffer.Plug.Direction.In, True)) self.addChild(Gaffer.IntPlug("aIn")) self.addChild(Gaffer.IntPlug("bIn")) self.addChild(Gaffer.IntPlug("aOut", Gaffer.Plug.Direction.Out)) self.addChild(Gaffer.IntPlug("bOut", Gaffer.Plug.Direction.Out)) self.addChild(Gaffer.IntPlug("cOut", Gaffer.Plug.Direction.Out)) def enabledPlug(self): return self["enabled"] def correspondingInput(self, output): if output.isSame(self["aOut"]): return self["aIn"] elif output.isSame(self["bOut"]): return self["bIn"] return None e = EnableAbleNode() self.assertTrue(e.enabledPlug().isSame(e["enabled"])) self.assertTrue(e.correspondingInput(e["aOut"]).isSame(e["aIn"])) self.assertTrue(e.correspondingInput(e["bOut"]).isSame(e["bIn"])) self.assertEqual(e.correspondingInput(e["enabled"]), None) self.assertEqual(e.correspondingInput(e["aIn"]), None) self.assertEqual(e.correspondingInput(e["bIn"]), None) self.assertEqual(e.correspondingInput(e["cOut"]), None)
def __visitationGraph(self): # L1_1 L1_2 # | |\ # | | \ # | | \ # L2_1 L2_2 L2_3 # |\ | / # | \ | / # | \ | / # | \ |/ # L3_1 L3_2 s = Gaffer.ScriptNode() s["L1_1"] = GafferTest.MultiplyNode() s["L1_2"] = GafferTest.AddNode() s["L2_1"] = GafferTest.AddNode() s["L2_2"] = GafferTest.MultiplyNode() s["L2_3"] = GafferTest.AddNode() s["L3_1"] = GafferTest.AddNode() s["L3_2"] = GafferTest.MultiplyNode() s["L3_2"]["op3"] = Gaffer.IntPlug() s["L2_1"]["op1"].setInput(s["L1_1"]["product"]) s["L2_2"]["op1"].setInput(s["L1_2"]["sum"]) s["L2_3"]["op1"].setInput(s["L1_2"]["sum"]) s["L3_1"]["op1"].setInput(s["L2_1"]["sum"]) s["L3_2"]["op1"].setInput(s["L2_1"]["sum"]) s["L3_2"]["op2"].setInput(s["L2_2"]["product"]) s["L3_2"]["op3"].setInput(s["L2_3"]["sum"]) return s
def testContextAccess(self): s = Gaffer.ScriptNode() s["m"] = GafferTest.MultiplyNode() s["m"]["op1"].setValue(1) s["e"] = Gaffer.Expression() s["e"].setExpression( "parent[\"m\"][\"op2\"] = int( context[\"frame\"] * 2 )", "python") context = Gaffer.Context() context.setFrame(10) with context: self.assertEqual(s["m"]["product"].getValue(), 20)
def testContext( self ) : s = Gaffer.ScriptNode() s["m"] = GafferTest.MultiplyNode() s["e"] = Gaffer.Expression() s["e"].setExpression( "parent[\"m\"][\"op1\"] = int( context[\"frame\"] )" ) w = GafferUI.NumericPlugValueWidget( s["m"]["op1"] ) self.assertTrue( w.getContext().isSame( s.context() ) ) s.context().setFrame( 10 ) self.assertEqual( w.numericWidget().getValue(), 10 ) context = Gaffer.Context() context.setFrame( 20 ) w.setContext( context ) self.assertTrue( w.getContext().isSame( context ) ) self.assertEqual( w.numericWidget().getValue(), 20 )
def testExceptionDuringParallelEval(self): # This only caused a problem when using GAFFER_PYTHONEXPRESSION_CACHEPOLICY=TaskCollaboration # with a TaskMutex without a properly isolated task_group so that exceptions in one thread # can cancel the other. We're adding a more specific test for this to TaskMutex, so we're not # expecting this to catch anything, but it's still a valid test m = GafferTest.MultiplyNode() m["e"] = Gaffer.Expression() m["e"].setExpression( inspect.cleandoc(""" if context["testVar"]%10 == 9: raise BaseException( "Foo" ) parent['op1'] = 1 """)) with six.assertRaisesRegex(self, BaseException, "Foo"): GafferTest.parallelGetValue(m["product"], 10000, "testVar")
def testSetChildDoesntRemoveChildIfNewChildIsntAccepted(self): class AddNodeAcceptor(Gaffer.Node): def __init__(self, name="AddNodeAcceptor"): Gaffer.Node.__init__(self, name) def acceptsChild(self, potentialChild): return isinstance(potentialChild, GafferTest.AddNode) IECore.registerRunTimeTyped(AddNodeAcceptor) g = AddNodeAcceptor() a = GafferTest.AddNode() g["a"] = a self.assertRaises(RuntimeError, g.setChild, "a", GafferTest.MultiplyNode()) self.assertTrue(g["a"].isSame(a))
def testPerformance(self): c = Gaffer.ContextVariables() c.setup(Gaffer.IntPlug()) for i in range(10): c["variables"].addChild( Gaffer.NameValuePlug("a%i" % i, IECore.StringData("A" * 100), flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)) c["variables"].addChild( Gaffer.NameValuePlug("intName", IECore.IntData(100), flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)) # This would be a bit more representative if our source node was actually affected by the context variables, # but without access to OSL in this test we don't have any efficient way to read context variables handy, # and we're mostly just interested in the amount of overhead anyway n = GafferTest.MultiplyNode() c["in"].setInput(n["product"]) GafferTest.parallelGetValue(c["out"], 1000000, "iter")
def testDependencyCyclesDontStopPlugsDirtying(self): nodes = [ GafferTest.MultiplyNode("node{}".format(i)) for i in range(0, 10) ] cs = GafferTest.CapturingSlot(*[n.plugDirtiedSignal() for n in nodes]) with IECore.CapturingMessageHandler() as mh: for i, node in enumerate(nodes): node["op1"].setInput(nodes[i - 1]["product"]) self.assertEqual({x[0] for x in cs}, {n["op1"] for n in nodes} | {n["product"] for n in nodes}) self.assertEqual(len(mh.messages), 1) self.assertEqual(mh.messages[0].level, IECore.Msg.Level.Error) self.assertEqual(mh.messages[0].context, "Plug dirty propagation") six.assertRegex(self, mh.messages[0].message, r"Cycle detected between node.* and node.*") del cs[:] with IECore.CapturingMessageHandler() as mh: nodes[0]["op2"].setValue(10) self.assertEqual({x[0] for x in cs}, {n["op1"] for n in nodes} | {n["product"] for n in nodes} | {nodes[0]["op2"]}) self.assertEqual(len(mh.messages), 1) self.assertEqual(mh.messages[0].level, IECore.Msg.Level.Error) self.assertEqual(mh.messages[0].context, "Plug dirty propagation") six.assertRegex(self, mh.messages[0].message, r"Cycle detected between node.* and node.*")
def testEnabled(self): s = Gaffer.ScriptNode() s["m"] = GafferTest.MultiplyNode() s["m"]["op2"].setValue(1) s["e"] = Gaffer.Expression() s["e"]["engine"].setValue("python") s["e"]["expression"].setValue( "parent[\"m\"][\"op1\"] = int( context[\"frame\"] )") s["w"] = Gaffer.TimeWarpComputeNode() s["w"]["in"] = Gaffer.IntPlug() s["w"]["in"].setInput(s["m"]["product"]) s["w"]["out"] = Gaffer.IntPlug(direction=Gaffer.Plug.Direction.Out) s["w"]["offset"].setValue(2) # test that enabledPlug() and correspondingInput() are implemented self.assertTrue(s["w"].enabledPlug().isSame(s["w"]["enabled"])) self.assertTrue(s["w"].correspondingInput(s["w"]["out"]).isSame( s["w"]["in"])) # test that disabling causes no time warping s["w"]["enabled"].setValue(False) for i in range(0, 10): with Gaffer.Context() as c: c.setFrame(i) self.assertEqual(s["m"]["product"].getValue(), s["w"]["out"].getValue()) self.assertEqual(s["m"]["product"].hash(), s["w"]["out"].hash())