<s> import unittest <EOL> import inspect <EOL> import IECore <EOL> import Gaffer <EOL> import GafferImage <EOL> import GafferImageTest <EOL> class FormatPlugTest ( GafferImageTest . ImageTestCase ) : <EOL> def testConstructor ( self ) : <EOL> p = GafferImage . FormatPlug ( ) <EOL> self . assertEqual ( p . getName ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( p . direction ( ) , Gaffer . Plug . Direction . In ) <EOL> self . assertEqual ( p . defaultValue ( ) , GafferImage . Format ( ) ) <EOL> self . assertEqual ( p . getValue ( ) , GafferImage . Format ( ) ) <EOL> self . assertEqual ( p . getFlags ( ) , Gaffer . Plug . Flags . Default ) <EOL> p = GafferImage . FormatPlug ( <EOL> "<STR_LIT:p>" , <EOL> Gaffer . Plug . Direction . Out , <EOL> GafferImage . Format ( <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT:2> ) , <EOL> Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic <EOL> ) <EOL> self . assertEqual ( p . getName ( ) , "<STR_LIT:p>" ) <EOL> self . assertEqual ( p . direction ( ) , Gaffer . Plug . Direction . Out ) <EOL> self . assertEqual ( p . defaultValue ( ) , GafferImage . Format ( <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( p . getValue ( ) , GafferImage . Format ( <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( p . getFlags ( ) , Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> def testChildren ( self ) : <EOL> p = GafferImage . FormatPlug ( ) <EOL> self . assertEqual ( p . keys ( ) , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertTrue ( isinstance ( p [ "<STR_LIT>" ] , Gaffer . Box2iPlug ) ) <EOL> self . assertTrue ( isinstance ( p [ "<STR_LIT>" ] , Gaffer . FloatPlug ) ) <EOL> self . assertRaises ( RuntimeError , p . addChild , Gaffer . IntPlug ( ) ) <EOL> def testValue ( self ) : <EOL> p = GafferImage . FormatPlug ( ) <EOL> v = GafferImage . Format ( IECore . Box2i ( IECore . V2i ( <NUM_LIT:11> , <NUM_LIT:12> ) , IECore . V2i ( <NUM_LIT:100> , <NUM_LIT:200> ) ) , <NUM_LIT:2> ) <EOL> p . setValue ( v ) <EOL> self . assertEqual ( p . getValue ( ) , v ) <EOL> self . assertEqual ( p [ "<STR_LIT>" ] . getValue ( ) , v . getDisplayWindow ( ) ) <EOL> self . assertEqual ( p [ "<STR_LIT>" ] . getValue ( ) , v . getPixelAspect ( ) ) <EOL> def testDefaultFormatFromContext ( self ) : <EOL> constant = GafferImage . Constant ( ) <EOL> with Gaffer . Context ( ) as context : <EOL> self . assertFalse ( <EOL> GafferImage . empty ( <EOL> constant [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) . getDisplayWindow ( ) <EOL> ) <EOL> ) <EOL> f = GafferImage . Format ( <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT:2> ) <EOL> GafferImage . FormatPlug . setDefaultFormat ( context , f ) <EOL> self . assertEqual ( GafferImage . FormatPlug . getDefaultFormat ( context ) , f ) <EOL> self . assertEqual ( constant [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , f ) <EOL> f = GafferImage . Format ( <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT:1> ) <EOL> GafferImage . FormatPlug . setDefaultFormat ( context , f ) <EOL> self . assertEqual ( GafferImage . FormatPlug . getDefaultFormat ( context ) , f ) <EOL> self . assertEqual ( constant [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , f ) <EOL> def testAcquireDefaultFormatPlug ( self ) : <EOL> s1 = Gaffer . ScriptNode ( ) <EOL> s2 = Gaffer . ScriptNode ( ) <EOL> p1A = GafferImage . FormatPlug . acquireDefaultFormatPlug ( s1 ) <EOL> p1B = GafferImage . FormatPlug . acquireDefaultFormatPlug ( s1 ) <EOL> p2A = GafferImage . FormatPlug . acquireDefaultFormatPlug ( s2 ) <EOL> p2B = GafferImage . FormatPlug . acquireDefaultFormatPlug ( s2 ) <EOL> self . assertTrue ( p1A . isSame ( p1B ) ) <EOL> self . assertTrue ( p2A . isSame ( p2B ) ) <EOL> self . assertFalse ( p1A . isSame ( p2A ) ) <EOL> def testDefaultFormatFromScript ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> self . assertFalse ( "<STR_LIT>" in s ) <EOL> s [ "<STR_LIT:c>" ] = GafferImage . Constant ( ) <EOL> self . assertTrue ( "<STR_LIT>" in s ) <EOL> defaultFormatPlug = GafferImage . FormatPlug . acquireDefaultFormatPlug ( s ) <EOL> self . assertTrue ( defaultFormatPlug . isSame ( s [ "<STR_LIT>" ] ) ) <EOL> with s . context ( ) : <EOL> self . assertFalse ( <EOL> GafferImage . empty ( <EOL> s [ "<STR_LIT:c>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) . getDisplayWindow ( ) <EOL> ) <EOL> ) <EOL> f = GafferImage . Format ( <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT:2> ) <EOL> defaultFormatPlug . setValue ( f ) <EOL> self . assertEqual ( s [ "<STR_LIT:c>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , f ) <EOL> f = GafferImage . Format ( <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT:1> ) <EOL> defaultFormatPlug . setValue ( f ) <EOL> self . assertEqual ( s [ "<STR_LIT:c>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , f ) <EOL> def testDefaultFormatAfterScriptLoad ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT:c>" ] = GafferImage . Constant ( ) <EOL> f = GafferImage . Format ( <NUM_LIT:100> , <NUM_LIT:100> ) <EOL> GafferImage . FormatPlug . acquireDefaultFormatPlug ( s ) . setValue ( f ) <EOL> with s . context ( ) : <EOL> self . assertEqual ( s [ "<STR_LIT:c>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , f ) <EOL> s2 = Gaffer . ScriptNode ( "<STR_LIT>" ) <EOL> s2 . execute ( s . serialise ( ) ) <EOL> with s2 . context ( ) : <EOL> self . assertEqual ( s2 [ "<STR_LIT:c>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , f ) <EOL> def testDefaultFormatFromScriptWithBox ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> self . assertFalse ( "<STR_LIT>" in s ) <EOL> s [ "<STR_LIT:b>" ] = Gaffer . Box ( ) <EOL> s [ "<STR_LIT:b>" ] [ "<STR_LIT:c>" ] = GafferImage . Constant ( ) <EOL> self . assertTrue ( "<STR_LIT>" in s ) <EOL> def testExpressions ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT>" ] = Gaffer . Node ( ) <EOL> s [ "<STR_LIT>" ] = Gaffer . Node ( ) <EOL> s [ "<STR_LIT>" ] [ "<STR_LIT:user>" ] [ "<STR_LIT:f>" ] = GafferImage . FormatPlug ( flags = Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> s [ "<STR_LIT>" ] [ "<STR_LIT:user>" ] [ "<STR_LIT:f>" ] = GafferImage . FormatPlug ( flags = Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> s [ "<STR_LIT:e>" ] = Gaffer . Expression ( ) <EOL> s [ "<STR_LIT:e>" ] . setExpression ( inspect . cleandoc ( <EOL> """<STR_LIT>""" <EOL> ) ) <EOL> s [ "<STR_LIT>" ] [ "<STR_LIT:user>" ] [ "<STR_LIT:f>" ] . setValue ( GafferImage . Format ( IECore . Box2i ( IECore . V2i ( <NUM_LIT:20> , <NUM_LIT:30> ) , IECore . V2i ( <NUM_LIT:100> , <NUM_LIT> ) ) , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( s [ "<STR_LIT>" ] [ "<STR_LIT:user>" ] [ "<STR_LIT:f>" ] . getValue ( ) , GafferImage . Format ( IECore . Box2i ( IECore . V2i ( <NUM_LIT:10> , <NUM_LIT:20> ) , IECore . V2i ( <NUM_LIT> , <NUM_LIT> ) ) , <NUM_LIT:0.5> ) ) <EOL> def testDefaultExpression ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT:n>" ] = Gaffer . Node ( ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT:f>" ] = GafferImage . FormatPlug ( flags = Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> f = GafferImage . Format ( <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT:1> ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT:f>" ] . setValue ( f ) <EOL> s [ "<STR_LIT:e>" ] = Gaffer . Expression ( ) <EOL> s [ "<STR_LIT:e>" ] . setExpression ( s [ "<STR_LIT:e>" ] . defaultExpression ( s [ "<STR_LIT:n>" ] [ "<STR_LIT:f>" ] , "<STR_LIT>" ) ) <EOL> self . assertTrue ( s [ "<STR_LIT:n>" ] [ "<STR_LIT:f>" ] . getInput ( ) . node ( ) . isSame ( s [ "<STR_LIT:e>" ] ) ) <EOL> self . assertEqual ( s [ "<STR_LIT:n>" ] [ "<STR_LIT:f>" ] . getValue ( ) , f ) <EOL> def testDefaultFormatHashRepeatability ( self ) : <EOL> allHashes = set ( ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:1000> ) : <EOL> c = Gaffer . Context ( ) <EOL> GafferImage . FormatPlug . setDefaultFormat ( c , GafferImage . Format ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> allHashes . add ( str ( c . hash ( ) ) ) <EOL> self . assertEqual ( len ( allHashes ) , <NUM_LIT:1> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
