<s> import unittest <EOL> import Gaffer <EOL> import GafferTest <EOL> class LoopTest ( GafferTest . TestCase ) : <EOL> def intLoop ( self ) : <EOL> result = Gaffer . LoopComputeNode ( ) <EOL> result [ "<STR_LIT>" ] = Gaffer . IntPlug ( direction = Gaffer . Plug . Direction . Out , flags = Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> result [ "<STR_LIT>" ] = Gaffer . IntPlug ( flags = Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> return result <EOL> def test ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT:n>" ] = self . intLoop ( ) <EOL> s [ "<STR_LIT:a>" ] = GafferTest . AddNode ( ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:0> ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT:a>" ] [ "<STR_LIT>" ] ) <EOL> s [ "<STR_LIT:a>" ] [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> s [ "<STR_LIT:a>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:1> ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:1> ) <EOL> self . assertEqual ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:1> ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:10> ) <EOL> self . assertEqual ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:10> ) <EOL> s2 = Gaffer . ScriptNode ( ) <EOL> s2 . execute ( s . serialise ( ) ) <EOL> self . assertEqual ( s2 [ "<STR_LIT:n>" ] . keys ( ) , s [ "<STR_LIT:n>" ] . keys ( ) ) <EOL> self . assertEqual ( s2 [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:10> ) <EOL> def testLoopIndex ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT:n>" ] = self . intLoop ( ) <EOL> s [ "<STR_LIT:a>" ] = GafferTest . AddNode ( ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:0> ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT:a>" ] [ "<STR_LIT>" ] ) <EOL> s [ "<STR_LIT:a>" ] [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> s [ "<STR_LIT:e>" ] = Gaffer . Expression ( ) <EOL> s [ "<STR_LIT:e>" ] . setExpression ( '<STR_LIT>' ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:4> ) <EOL> self . assertEqual ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:1> + <NUM_LIT:2> + <NUM_LIT:3> ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:5> ) <EOL> self . assertEqual ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:1> + <NUM_LIT:2> + <NUM_LIT:3> + <NUM_LIT:4> ) <EOL> def testChangeLoopNetwork ( self ) : <EOL> n = self . intLoop ( ) <EOL> a1 = GafferTest . AddNode ( ) <EOL> a2 = GafferTest . AddNode ( ) <EOL> n [ "<STR_LIT>" ] . setValue ( <NUM_LIT:0> ) <EOL> n [ "<STR_LIT>" ] . setInput ( a2 [ "<STR_LIT>" ] ) <EOL> a2 [ "<STR_LIT>" ] . setInput ( a1 [ "<STR_LIT>" ] ) <EOL> a2 [ "<STR_LIT>" ] . setValue ( <NUM_LIT:1> ) <EOL> a1 [ "<STR_LIT>" ] . setInput ( n [ "<STR_LIT>" ] ) <EOL> a1 [ "<STR_LIT>" ] . setValue ( <NUM_LIT:1> ) <EOL> n [ "<STR_LIT>" ] . setValue ( <NUM_LIT:2> ) <EOL> self . assertEqual ( n [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:4> ) <EOL> a2 [ "<STR_LIT>" ] . setValue ( <NUM_LIT:2> ) <EOL> self . assertEqual ( n [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:6> ) <EOL> def testDirtyPropagation ( self ) : <EOL> n = self . intLoop ( ) <EOL> a = GafferTest . AddNode ( ) <EOL> n [ "<STR_LIT>" ] . setValue ( <NUM_LIT:0> ) <EOL> n [ "<STR_LIT>" ] . setInput ( a [ "<STR_LIT>" ] ) <EOL> a [ "<STR_LIT>" ] . setInput ( n [ "<STR_LIT>" ] ) <EOL> a [ "<STR_LIT>" ] . setValue ( <NUM_LIT:1> ) <EOL> cs = GafferTest . CapturingSlot ( n . plugDirtiedSignal ( ) ) <EOL> a [ "<STR_LIT>" ] . setValue ( <NUM_LIT:2> ) <EOL> self . assertEqual ( set ( [ s [ <NUM_LIT:0> ] for s in cs ] ) , { n [ "<STR_LIT>" ] , n [ "<STR_LIT>" ] , n [ "<STR_LIT>" ] } ) <EOL> del cs [ : ] <EOL> n [ "<STR_LIT>" ] . setValue ( <NUM_LIT:100> ) <EOL> self . assertEqual ( set ( [ s [ <NUM_LIT:0> ] for s in cs ] ) , { n [ "<STR_LIT>" ] , n [ "<STR_LIT>" ] } ) <EOL> del cs [ : ] <EOL> n [ "<STR_LIT>" ] . setValue ( "<STR_LIT>" ) <EOL> self . assertEqual ( set ( [ s [ <NUM_LIT:0> ] for s in cs ] ) , { n [ "<STR_LIT>" ] , n [ "<STR_LIT>" ] , n [ "<STR_LIT>" ] , n [ "<STR_LIT>" ] } ) <EOL> def testCustomLoopIndex ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT:n>" ] = self . intLoop ( ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( "<STR_LIT>" ) <EOL> s [ "<STR_LIT:a>" ] = GafferTest . AddNode ( ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:0> ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT:a>" ] [ "<STR_LIT>" ] ) <EOL> s [ "<STR_LIT:a>" ] [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> s [ "<STR_LIT:e>" ] = Gaffer . Expression ( ) <EOL> s [ "<STR_LIT:e>" ] . setExpression ( '<STR_LIT>' ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:4> ) <EOL> self . assertEqual ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:1> + <NUM_LIT:2> + <NUM_LIT:3> ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setValue ( <NUM_LIT:5> ) <EOL> self . assertEqual ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:1> + <NUM_LIT:2> + <NUM_LIT:3> + <NUM_LIT:4> ) <EOL> def testEnabled ( self ) : <EOL> n = self . intLoop ( ) <EOL> a = GafferTest . AddNode ( ) <EOL> n [ "<STR_LIT>" ] . setValue ( <NUM_LIT:0> ) <EOL> n [ "<STR_LIT>" ] . setInput ( a [ "<STR_LIT>" ] ) <EOL> a [ "<STR_LIT>" ] . setInput ( n [ "<STR_LIT>" ] ) <EOL> a [ "<STR_LIT>" ] . setValue ( <NUM_LIT:1> ) <EOL> n [ "<STR_LIT>" ] . setValue ( <NUM_LIT:4> ) <EOL> self . assertEqual ( n [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:4> ) <EOL> n [ "<STR_LIT>" ] . setValue ( False ) <EOL> self . assertEqual ( n [ "<STR_LIT>" ] . getValue ( ) , <NUM_LIT:0> ) <EOL> self . assertTrue ( n . correspondingInput ( n [ "<STR_LIT>" ] ) . isSame ( n [ "<STR_LIT>" ] ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
