#NEWLINE# def testCustomSerialiser( self ) : #NEWLINE# #INDENT# class CustomSerialiser ( Gaffer . Serialisation . Serialiser ) : #NEWLINE# #INDENT# def moduleDependencies( self , node ) : #NEWLINE# #INDENT# return ( 'GafferTest' , ) #NEWLINE# #UNINDENT# def constructor( self , node , serialisation ) : #NEWLINE# #INDENT# return ( 'GafferTest.SerialisationTest.SerialisationTestNode( "%s", %d )' % ( node . getName ( ) , node . initArgument ) ) #NEWLINE# #UNINDENT# def postConstructor( self , node , identifier , serialisation ) : #NEWLINE# #INDENT# return ( identifier + '.postConstructorWasHere = True\n' ) #NEWLINE# #UNINDENT# def postHierarchy( self , node , identifier , serialisation ) : #NEWLINE# #INDENT# return ( identifier + '.postHierarchyWasHere = True\n' ) #NEWLINE# #UNINDENT# def postScript( self , node , identifier , serialisation ) : #NEWLINE# #INDENT# return ( identifier + '.postScriptWasHere = True\n' ) #NEWLINE# #UNINDENT# def childNeedsSerialisation( self , child ) : #NEWLINE# #INDENT# if isinstance ( child , Gaffer . Node ) : #NEWLINE# #INDENT# return ( child . getName ( ) == 'childNodeNeedingSerialisation' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( child , Gaffer . Plug ) : #NEWLINE# #INDENT# return child . getFlags ( Gaffer . Plug . Flags . Serialisable ) #NEWLINE# #UNINDENT# #UNINDENT# return False #NEWLINE# #UNINDENT# def childNeedsConstruction( self , child ) : #NEWLINE# #INDENT# if isinstance ( child , Gaffer . Node ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( child , Gaffer . Plug ) : #NEWLINE# #INDENT# return child . getFlags ( Gaffer . Plug . Flags . Dynamic ) #NEWLINE# #UNINDENT# #UNINDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# customSerialiser = CustomSerialiser ( ) #NEWLINE# Gaffer . Serialisation . registerSerialiser ( self . SerialisationTestNode , customSerialiser ) #NEWLINE# s = Gaffer . ScriptNode ( ) #NEWLINE# s [ 'n' ] = self . SerialisationTestNode ( 'a' , initArgument = 20 ) #NEWLINE# s [ 'n' ] [ 'childNodeNeedingSerialisation' ] [ 'op1' ] . setValue ( 101 ) #NEWLINE# s [ 'n' ] [ 'childNodeNotNeedingSerialisation' ] [ 'op1' ] . setValue ( 101 ) #NEWLINE# s [ 'n' ] [ 'dynamicPlug' ] = Gaffer . FloatPlug ( defaultValue = 10 , flags = ( Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) ) #NEWLINE# self . assertTrue ( Gaffer . Serialisation . acquireSerialiser ( s [ 'n' ] ) . isSame ( customSerialiser ) ) #NEWLINE# s2 = Gaffer . ScriptNode ( ) #NEWLINE# s2 . execute ( s . serialise ( ) ) #NEWLINE# self . assertTrue ( isinstance ( s2 [ 'n' ] , self . SerialisationTestNode ) ) #NEWLINE# self . assertEqual ( s [ 'n' ] . keys ( ) , s2 [ 'n' ] . keys ( ) ) #NEWLINE# self . assertEqual ( s2 [ 'n' ] . initArgument , 20 ) #NEWLINE# self . assertEqual ( s2 [ 'n' ] [ 'childNodeNeedingSerialisation' ] [ 'op1' ] . getValue ( ) , 101 ) #NEWLINE# self . assertEqual ( s2 [ 'n' ] [ 'childNodeNotNeedingSerialisation' ] [ 'op1' ] . getValue ( ) , 0 ) #NEWLINE# self . assertEqual ( s2 [ 'n' ] [ 'dynamicPlug' ] . getValue ( ) , 10 ) #NEWLINE# self . assertEqual ( s2 [ 'n' ] . postConstructorWasHere , True ) #NEWLINE# self . assertEqual ( s2 [ 'n' ] . postHierarchyWasHere , True ) #NEWLINE# self . assertEqual ( s2 [ 'n' ] . postScriptWasHere , True )