<s> import unittest <EOL> import IECore <EOL> import Gaffer <EOL> import GafferTest <EOL> import GafferScene <EOL> import GafferSceneTest <EOL> class CustomOptionsTest ( GafferSceneTest . SceneTestCase ) : <EOL> def test ( self ) : <EOL> p = GafferScene . Plane ( ) <EOL> options = GafferScene . CustomOptions ( ) <EOL> options [ "<STR_LIT>" ] . setInput ( p [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( options [ "<STR_LIT>" ] . object ( "<STR_LIT:/>" ) , IECore . NullObject ( ) ) <EOL> self . assertEqual ( options [ "<STR_LIT>" ] . transform ( "<STR_LIT:/>" ) , IECore . M44f ( ) ) <EOL> self . assertEqual ( options [ "<STR_LIT>" ] . bound ( "<STR_LIT:/>" ) , IECore . Box3f ( IECore . V3f ( - <NUM_LIT:0.5> , - <NUM_LIT:0.5> , <NUM_LIT:0> ) , IECore . V3f ( <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:0> ) ) ) <EOL> self . assertEqual ( options [ "<STR_LIT>" ] . childNames ( "<STR_LIT:/>" ) , IECore . InternedStringVectorData ( [ "<STR_LIT>" ] ) ) <EOL> self . assertEqual ( options [ "<STR_LIT>" ] . object ( "<STR_LIT>" ) , IECore . MeshPrimitive . createPlane ( IECore . Box2f ( IECore . V2f ( - <NUM_LIT:0.5> ) , IECore . V2f ( <NUM_LIT:0.5> ) ) ) ) <EOL> self . assertEqual ( options [ "<STR_LIT>" ] . transform ( "<STR_LIT>" ) , IECore . M44f ( ) ) <EOL> self . assertEqual ( options [ "<STR_LIT>" ] . bound ( "<STR_LIT>" ) , IECore . Box3f ( IECore . V3f ( - <NUM_LIT:0.5> , - <NUM_LIT:0.5> , <NUM_LIT:0> ) , IECore . V3f ( <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:0> ) ) ) <EOL> self . assertEqual ( options [ "<STR_LIT>" ] . childNames ( "<STR_LIT>" ) , IECore . InternedStringVectorData ( ) ) <EOL> options [ "<STR_LIT>" ] . addMember ( "<STR_LIT:test>" , IECore . IntData ( <NUM_LIT:10> ) ) <EOL> options [ "<STR_LIT>" ] . addMember ( "<STR_LIT>" , IECore . StringData ( "<STR_LIT>" ) ) <EOL> g = options [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) <EOL> self . assertEqual ( len ( g ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( g [ "<STR_LIT>" ] , IECore . IntData ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( g [ "<STR_LIT>" ] , IECore . StringData ( "<STR_LIT>" ) ) <EOL> def testSerialisation ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT>" ] = GafferScene . CustomOptions ( ) <EOL> s [ "<STR_LIT>" ] [ "<STR_LIT>" ] . addMember ( "<STR_LIT:test>" , IECore . IntData ( <NUM_LIT:10> ) ) <EOL> s [ "<STR_LIT>" ] [ "<STR_LIT>" ] . addMember ( "<STR_LIT>" , IECore . StringData ( "<STR_LIT>" ) ) <EOL> ss = s . serialise ( ) <EOL> s2 = Gaffer . ScriptNode ( ) <EOL> s2 . execute ( ss ) <EOL> g = s2 [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) <EOL> self . assertEqual ( len ( g ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( g [ "<STR_LIT>" ] , IECore . IntData ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( g [ "<STR_LIT>" ] , IECore . StringData ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( "<STR_LIT>" not in s2 [ "<STR_LIT>" ] ) <EOL> def testHashPassThrough ( self ) : <EOL> p = GafferScene . Plane ( ) <EOL> options = GafferScene . CustomOptions ( ) <EOL> options [ "<STR_LIT>" ] . setInput ( p [ "<STR_LIT>" ] ) <EOL> options [ "<STR_LIT>" ] . addMember ( "<STR_LIT:test>" , IECore . IntData ( <NUM_LIT:10> ) ) <EOL> self . assertSceneHashesEqual ( p [ "<STR_LIT>" ] , options [ "<STR_LIT>" ] , childPlugNames = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:object>" , "<STR_LIT>" ) ) <EOL> def testDisabled ( self ) : <EOL> p = GafferScene . Plane ( ) <EOL> options = GafferScene . CustomOptions ( ) <EOL> options [ "<STR_LIT>" ] . setInput ( p [ "<STR_LIT>" ] ) <EOL> options [ "<STR_LIT>" ] . addMember ( "<STR_LIT:test>" , IECore . IntData ( <NUM_LIT:10> ) ) <EOL> self . assertSceneHashesEqual ( p [ "<STR_LIT>" ] , options [ "<STR_LIT>" ] , childPlugNames = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:object>" , "<STR_LIT>" ) ) <EOL> self . assertNotEqual ( options [ "<STR_LIT>" ] [ "<STR_LIT>" ] . hash ( ) , p [ "<STR_LIT>" ] [ "<STR_LIT>" ] . hash ( ) ) <EOL> options [ "<STR_LIT>" ] . setValue ( False ) <EOL> self . assertSceneHashesEqual ( p [ "<STR_LIT>" ] , options [ "<STR_LIT>" ] ) <EOL> self . assertScenesEqual ( p [ "<STR_LIT>" ] , options [ "<STR_LIT>" ] ) <EOL> def testDirtyPropagation ( self ) : <EOL> p = GafferScene . Plane ( ) <EOL> o = GafferScene . CustomOptions ( ) <EOL> o [ "<STR_LIT>" ] . setInput ( p [ "<STR_LIT>" ] ) <EOL> cs = GafferTest . CapturingSlot ( o . plugDirtiedSignal ( ) ) <EOL> p [ "<STR_LIT>" ] [ "<STR_LIT:x>" ] . setValue ( <NUM_LIT> ) <EOL> dirtiedPlugs = set ( [ x [ <NUM_LIT:0> ] . relativeName ( x [ <NUM_LIT:0> ] . node ( ) ) for x in cs ] ) <EOL> self . assertEqual ( len ( dirtiedPlugs ) , <NUM_LIT:6> ) <EOL> self . assertTrue ( "<STR_LIT>" in dirtiedPlugs ) <EOL> self . assertTrue ( "<STR_LIT>" in dirtiedPlugs ) <EOL> self . assertTrue ( "<STR_LIT>" in dirtiedPlugs ) <EOL> self . assertTrue ( "<STR_LIT>" in dirtiedPlugs ) <EOL> self . assertTrue ( "<STR_LIT>" in dirtiedPlugs ) <EOL> self . assertTrue ( "<STR_LIT>" in dirtiedPlugs ) <EOL> def testSubstitution ( self ) : <EOL> o = GafferScene . CustomOptions ( ) <EOL> o [ "<STR_LIT>" ] . addMember ( "<STR_LIT:test>" , "<STR_LIT>" ) <EOL> self . assertEqual ( o [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) [ "<STR_LIT>" ] , IECore . StringData ( "<STR_LIT>" ) ) <EOL> h = o [ "<STR_LIT>" ] [ "<STR_LIT>" ] . hash ( ) <EOL> c = Gaffer . Context ( ) <EOL> c [ "<STR_LIT:foo>" ] = "<STR_LIT:foo>" <EOL> with c : <EOL> self . assertNotEqual ( o [ "<STR_LIT>" ] [ "<STR_LIT>" ] . hash ( ) , h ) <EOL> self . assertEqual ( o [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) [ "<STR_LIT>" ] , IECore . StringData ( "<STR_LIT:foo>" ) ) <EOL> def testDirtyPropagationOnMemberAdditionAndRemoval ( self ) : <EOL> o = GafferScene . CustomOptions ( ) <EOL> cs = GafferTest . CapturingSlot ( o . plugDirtiedSignal ( ) ) <EOL> p = o [ "<STR_LIT>" ] . addMember ( "<STR_LIT:test>" , IECore . IntData ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( o [ "<STR_LIT>" ] [ "<STR_LIT>" ] in [ c [ <NUM_LIT:0> ] for c in cs ] ) <EOL> del cs [ : ] <EOL> o [ "<STR_LIT>" ] . removeChild ( p ) <EOL> self . assertTrue ( o [ "<STR_LIT>" ] [ "<STR_LIT>" ] in [ c [ <NUM_LIT:0> ] for c in cs ] ) <EOL> def testSetsPassThrough ( self ) : <EOL> p = GafferScene . Plane ( ) <EOL> p [ "<STR_LIT>" ] . setValue ( "<STR_LIT>" ) <EOL> o = GafferScene . CustomOptions ( ) <EOL> o [ "<STR_LIT>" ] . setInput ( p [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( p [ "<STR_LIT>" ] [ "<STR_LIT>" ] . hash ( ) , o [ "<STR_LIT>" ] [ "<STR_LIT>" ] . hash ( ) ) <EOL> self . assertTrue ( p [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( _copy = False ) . isSame ( o [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( _copy = False ) ) ) <EOL> self . assertEqual ( p [ "<STR_LIT>" ] . setHash ( "<STR_LIT:a>" ) , o [ "<STR_LIT>" ] . setHash ( "<STR_LIT:b>" ) ) <EOL> self . assertTrue ( p [ "<STR_LIT>" ] . set ( "<STR_LIT:a>" , _copy = False ) . isSame ( o [ "<STR_LIT>" ] . set ( "<STR_LIT:b>" , _copy = False ) ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
