コード例 #1
0
ファイル: TaskSwitchTest.py プロジェクト: mikepkes/gaffer
    def test(self):

        s = Gaffer.ScriptNode()

        s["c1"] = GafferTest.CountingExecutableNode()
        s["c2"] = GafferTest.CountingExecutableNode()

        s["s"] = Gaffer.TaskSwitch()
        self.assertEqual(s["s"]["index"].getValue(), 0)

        s["s"]["requirements"][0].setInput(s["c1"]["requirement"])
        s["s"]["requirements"][1].setInput(s["c2"]["requirement"])

        d = self.__dispatcher()
        d.dispatch([s["s"]])

        self.assertEqual(s["c1"].executionCount, 1)
        self.assertEqual(s["c2"].executionCount, 0)

        s["s"]["index"].setValue(1)
        d.dispatch([s["s"]])

        self.assertEqual(s["c1"].executionCount, 1)
        self.assertEqual(s["c2"].executionCount, 1)

        s["s"]["index"].setValue(2)
        d.dispatch([s["s"]])

        self.assertEqual(s["c1"].executionCount, 2)
        self.assertEqual(s["c2"].executionCount, 1)
コード例 #2
0
    def testTaskSet(self):

        # an empty ExecutableOpHolder doesn't actually compute anything, so all tasks are the same
        c = Gaffer.Context()
        n = Gaffer.ExecutableOpHolder()
        t1 = Gaffer.ExecutableNode.Task(n, c)
        t2 = Gaffer.ExecutableNode.Task(n, c)
        self.assertEqual(t1, t2)
        c2 = Gaffer.Context()
        c2["a"] = 2
        t3 = Gaffer.ExecutableNode.Task(n, c2)
        self.assertEqual(t1, t3)
        n2 = Gaffer.ExecutableOpHolder()
        t4 = Gaffer.ExecutableNode.Task(n2, c2)
        self.assertEqual(t1, t4)
        t5 = Gaffer.ExecutableNode.Task(n2, c)
        self.assertEqual(t1, t5)

        s = set([t1, t2, t3, t4, t4, t4, t1, t2, t4, t3, t2])
        # there should only be 1 task because they all have identical results
        self.assertEqual(len(s), 1)
        self.assertEqual(s, set([t1]))
        self.assertTrue(t1 in s)
        self.assertTrue(t2 in s)
        self.assertTrue(t3 in s)
        self.assertTrue(t4 in s)
        # even t5 is in there, because it's really the same task
        self.assertTrue(t5 in s)

        # MyNode.hash() depends on the context time, so tasks will vary
        my = GafferTest.CountingExecutableNode()
        c.setFrame(1)
        t1 = Gaffer.ExecutableNode.Task(my, c)
        t2 = Gaffer.ExecutableNode.Task(my, c)
        self.assertEqual(t1, t2)
        c2 = Gaffer.Context()
        c2.setFrame(2)
        t3 = Gaffer.ExecutableNode.Task(my, c2)
        self.assertNotEqual(t1, t3)
        my2 = GafferTest.CountingExecutableNode()
        t4 = Gaffer.ExecutableNode.Task(my2, c2)
        self.assertNotEqual(t1, t4)
        self.assertEqual(t3, t4)
        t5 = Gaffer.ExecutableNode.Task(my2, c)
        self.assertEqual(t1, t5)
        self.assertNotEqual(t3, t5)

        s = set([t1, t2, t3, t4, t4, t4, t1, t2, t4, t3, t2])
        # t1 and t3 are the only distinct tasks
        self.assertEqual(len(s), 2)
        self.assertEqual(s, set([t1, t3]))
        # but they still all have equivalent tasks in the set
        self.assertTrue(t1 in s)
        self.assertTrue(t2 in s)
        self.assertTrue(t3 in s)
        self.assertTrue(t4 in s)
        self.assertTrue(t5 in s)
コード例 #3
0
    def testUpstreamConstant(self):

        script = Gaffer.ScriptNode()

        script["constant"] = GafferTest.CountingExecutableNode()

        script["writer"] = GafferTest.TextWriter()
        script["writer"]["requirements"][0].setInput(
            script["constant"]["requirement"])
        script["writer"]["fileName"].setValue(self.temporaryDirectory() +
                                              "/${name}.txt")

        script["wedge"] = Gaffer.Wedge()
        script["wedge"]["requirements"][0].setInput(
            script["writer"]["requirement"])
        script["wedge"]["variable"].setValue("name")
        script["wedge"]["mode"].setValue(int(Gaffer.Wedge.Mode.StringList))
        script["wedge"]["strings"].setValue(
            IECore.StringVectorData(["tom", "dick", "harry"]))

        self.__dispatcher().dispatch([script["wedge"]])

        self.assertEqual(
            set(glob.glob(self.temporaryDirectory() + "/*.txt")), {
                self.temporaryDirectory() + "/tom.txt",
                self.temporaryDirectory() + "/dick.txt",
                self.temporaryDirectory() + "/harry.txt",
            })

        # Even though the constant node is upstream from the wedge,
        # it should only execute once because it doesn't reference
        # the wedge variable at all.
        self.assertEqual(script["constant"].executionCount, 1)
コード例 #4
0
    def testIsExecutable(self):

        self.assertTrue(
            issubclass(GafferTest.CountingExecutableNode,
                       Gaffer.ExecutableNode))
        self.assertTrue(
            isinstance(GafferTest.CountingExecutableNode(),
                       Gaffer.ExecutableNode))
コード例 #5
0
	def testRequirements( self ) :
		"""Test the function requirements and Executable::defaultRequirements """

		c1 = Gaffer.Context()
		c1.setFrame( 1 )
		c2 = Gaffer.Context()
		c2.setFrame( 2 )

		n = GafferTest.CountingExecutableNode()
		n2 = GafferTest.CountingExecutableNode()

		# make n2 require n
		n2["requirements"][0].setInput( n['requirement'] )

		self.assertEqual( n.requirements(c1), [] )
		self.assertEqual( n2.requirements(c1), [ Gaffer.ExecutableNode.Task( n, c1 ) ] )
		self.assertEqual( n2.requirements(c2), [ Gaffer.ExecutableNode.Task( n, c2 ) ] )
コード例 #6
0
ファイル: TaskSwitchTest.py プロジェクト: mikepkes/gaffer
    def testIndexExpression(self):

        s = Gaffer.ScriptNode()

        s["c1"] = GafferTest.CountingExecutableNode()
        s["c2"] = GafferTest.CountingExecutableNode()
        s["c3"] = GafferTest.CountingExecutableNode()

        s["s"] = Gaffer.TaskSwitch()
        s["s"]["requirements"][0].setInput(s["c1"]["requirement"])
        s["s"]["requirements"][1].setInput(s["c2"]["requirement"])
        s["s"]["requirements"][2].setInput(s["c3"]["requirement"])

        s["e"] = Gaffer.Expression()
        s["e"].setExpression("parent['s']['index'] = context.getFrame()")

        d = self.__dispatcher()
        with Gaffer.Context() as c:

            c.setFrame(0)
            d.dispatch([s["s"]])

            self.assertEqual(s["c1"].executionCount, 1)
            self.assertEqual(s["c2"].executionCount, 0)
            self.assertEqual(s["c3"].executionCount, 0)

            c.setFrame(1)
            d.dispatch([s["s"]])

            self.assertEqual(s["c1"].executionCount, 1)
            self.assertEqual(s["c2"].executionCount, 1)
            self.assertEqual(s["c3"].executionCount, 0)

            c.setFrame(2)
            d.dispatch([s["s"]])

            self.assertEqual(s["c1"].executionCount, 1)
            self.assertEqual(s["c2"].executionCount, 1)
            self.assertEqual(s["c3"].executionCount, 1)

            c.setFrame(3)
            d.dispatch([s["s"]])

            self.assertEqual(s["c1"].executionCount, 2)
            self.assertEqual(s["c2"].executionCount, 1)
            self.assertEqual(s["c3"].executionCount, 1)
コード例 #7
0
    def testExecuteSequence(self):

        n = GafferTest.CountingExecutableNode()
        self.assertEqual(n.executionCount, 0)

        n.executeSequence([1, 2, 3])
        self.assertEqual(n.executionCount, 3)

        n.executeSequence([1, 5, 10])
        self.assertEqual(n.executionCount, 6)

        # requiring execution doesn't tally the count per frame
        n2 = GafferTest.CountingExecutableNode(requiresSequenceExecution=True)
        self.assertEqual(n2.executionCount, 0)

        n2.executeSequence([1, 2, 3])
        self.assertEqual(n2.executionCount, 1)

        n2.executeSequence([1, 5, 10])
        self.assertEqual(n2.executionCount, 2)
コード例 #8
0
    def testHash(self):

        c1 = Gaffer.Context()
        c1.setFrame(1)
        c2 = Gaffer.Context()
        c2.setFrame(2)
        c3 = Gaffer.Context()
        c3.setFrame(3.0)

        # hashes that don't use the context are equivalent
        n = GafferTest.CountingExecutableNode(withHash=False)
        self.assertEqual(n.hash(c1), n.hash(c1))
        self.assertEqual(n.hash(c1), n.hash(c2))
        self.assertEqual(n.hash(c1), n.hash(c3))

        # hashes that do use the context differ
        n2 = GafferTest.CountingExecutableNode(withHash=True)
        self.assertEqual(n2.hash(c1), n2.hash(c1))
        self.assertNotEqual(n2.hash(c1), n2.hash(c2))
        self.assertNotEqual(n2.hash(c1), n2.hash(c3))

        # hashes match across the same node type
        n3 = GafferTest.CountingExecutableNode(withHash=True)
        self.assertEqual(n2.hash(c1), n3.hash(c1))
        self.assertEqual(n2.hash(c2), n3.hash(c2))
        self.assertEqual(n2.hash(c3), n3.hash(c3))

        # hashes differ across different node types
        class MyNode(GafferTest.CountingExecutableNode):
            def __init__(self):
                GafferTest.CountingExecutableNode.__init__(self)

        IECore.registerRunTimeTyped(MyNode)

        n4 = MyNode()

        self.assertNotEqual(n4.hash(c1), n3.hash(c1))
        self.assertNotEqual(n4.hash(c2), n3.hash(c2))
        self.assertNotEqual(n4.hash(c3), n3.hash(c3))
コード例 #9
0
    def testExecute(self):

        n = GafferTest.CountingExecutableNode()
        self.assertEqual(n.executionCount, 0)

        n.execute()
        self.assertEqual(n.executionCount, 1)

        n.execute()
        self.assertEqual(n.executionCount, 2)

        c = Gaffer.Context()
        c.setFrame(Gaffer.Context.current().getFrame() + 1)
        with c:
            n.execute()
        self.assertEqual(n.executionCount, 3)
コード例 #10
0
    def testRequiresSequenceExecution(self):

        n = GafferTest.CountingExecutableNode()
        self.assertEqual(n.requiresSequenceExecution(), False)