<s> import glob <EOL> import unittest <EOL> import Gaffer <EOL> import GafferTest <EOL> import GafferDispatch <EOL> import GafferDispatchTest <EOL> class TaskContextVariablesTest ( GafferTest . TestCase ) : <EOL> def __dispatcher ( self , frameRange = None ) : <EOL> result = GafferDispatch . LocalDispatcher ( jobPool = GafferDispatch . LocalDispatcher . JobPool ( ) ) <EOL> result [ "<STR_LIT>" ] . setValue ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> return result <EOL> def test ( self ) : <EOL> script = Gaffer . ScriptNode ( ) <EOL> script [ "<STR_LIT>" ] = GafferDispatchTest . TextWriter ( ) <EOL> script [ "<STR_LIT>" ] [ "<STR_LIT>" ] . setValue ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> script [ "<STR_LIT>" ] = GafferDispatch . TaskContextVariables ( ) <EOL> script [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( script [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> script [ "<STR_LIT>" ] [ "<STR_LIT>" ] . addMember ( "<STR_LIT:name>" , "<STR_LIT>" ) <EOL> self . __dispatcher ( ) . dispatch ( [ script [ "<STR_LIT>" ] ] ) <EOL> self . assertEqual ( <EOL> set ( glob . glob ( self . temporaryDirectory ( ) + "<STR_LIT>" ) ) , <EOL> { <EOL> self . temporaryDirectory ( ) + "<STR_LIT>" , <EOL> } <EOL> ) <EOL> def testDisabledVariable ( self ) : <EOL> script = Gaffer . ScriptNode ( ) <EOL> script [ "<STR_LIT>" ] = GafferDispatchTest . TextWriter ( ) <EOL> script [ "<STR_LIT>" ] [ "<STR_LIT>" ] . setValue ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> script [ "<STR_LIT>" ] = GafferDispatch . TaskContextVariables ( ) <EOL> script [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( script [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> jim = script [ "<STR_LIT>" ] [ "<STR_LIT>" ] . addOptionalMember ( "<STR_LIT>" , "<STR_LIT>" , enabled = False ) <EOL> bob = script [ "<STR_LIT>" ] [ "<STR_LIT>" ] . addOptionalMember ( "<STR_LIT>" , "<STR_LIT>" , enabled = True ) <EOL> self . __dispatcher ( ) . dispatch ( [ script [ "<STR_LIT>" ] ] ) <EOL> self . assertEqual ( <EOL> set ( glob . glob ( self . temporaryDirectory ( ) + "<STR_LIT>" ) ) , <EOL> { <EOL> self . temporaryDirectory ( ) + "<STR_LIT>" , <EOL> } <EOL> ) <EOL> def testBackgroundDispatch ( self ) : <EOL> script = Gaffer . ScriptNode ( ) <EOL> script [ "<STR_LIT>" ] = GafferDispatchTest . TextWriter ( ) <EOL> script [ "<STR_LIT>" ] [ "<STR_LIT>" ] . setValue ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> script [ "<STR_LIT>" ] = GafferDispatch . TaskContextVariables ( ) <EOL> script [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( script [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> script [ "<STR_LIT>" ] [ "<STR_LIT>" ] . addMember ( "<STR_LIT:name>" , "<STR_LIT>" ) <EOL> dispatcher = self . __dispatcher ( ) <EOL> dispatcher [ "<STR_LIT>" ] . setValue ( True ) <EOL> dispatcher . dispatch ( [ script [ "<STR_LIT>" ] ] ) <EOL> dispatcher . jobPool ( ) . waitForAll ( ) <EOL> self . assertEqual ( len ( dispatcher . jobPool ( ) . failedJobs ( ) ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( <EOL> set ( glob . glob ( self . temporaryDirectory ( ) + "<STR_LIT>" ) ) , <EOL> { <EOL> self . temporaryDirectory ( ) + "<STR_LIT>" , <EOL> } <EOL> ) <EOL> def testDirectCycles ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT>" ] = GafferDispatch . TaskContextVariables ( ) <EOL> s [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> d = self . __dispatcher ( ) <EOL> self . assertRaisesRegexp ( RuntimeError , "<STR_LIT>" , d . dispatch , [ s [ "<STR_LIT>" ] ] ) <EOL> def testStringSubstitutions ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT:l>" ] = GafferDispatchTest . LoggingExecutableNode ( ) <EOL> s [ "<STR_LIT:v>" ] = GafferDispatch . TaskContextVariables ( ) <EOL> s [ "<STR_LIT:v>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( s [ "<STR_LIT:l>" ] [ "<STR_LIT>" ] ) <EOL> s [ "<STR_LIT:v>" ] [ "<STR_LIT>" ] . addMember ( "<STR_LIT:test>" , "<STR_LIT>" ) <EOL> with Gaffer . Context ( ) as c : <EOL> c . setFrame ( <NUM_LIT:100> ) <EOL> self . __dispatcher ( ) . dispatch ( [ s [ "<STR_LIT:v>" ] ] ) <EOL> self . assertEqual ( s [ "<STR_LIT:l>" ] . log [ <NUM_LIT:0> ] . context [ "<STR_LIT:test>" ] , "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
