<s> import IECore <EOL> import Gaffer <EOL> import GafferTest <EOL> import GafferScene <EOL> import GafferSceneTest <EOL> class DuplicateTest ( GafferSceneTest . SceneTestCase ) : <EOL> def test ( self ) : <EOL> s = GafferScene . Sphere ( ) <EOL> d = GafferScene . Duplicate ( ) <EOL> d [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT>" ] ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" ) <EOL> d [ "<STR_LIT>" ] [ "<STR_LIT>" ] . setValue ( IECore . V3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertSceneValid ( d [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( d [ "<STR_LIT>" ] . childNames ( "<STR_LIT:/>" ) , IECore . InternedStringVectorData ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> self . assertPathHashesEqual ( s [ "<STR_LIT>" ] , "<STR_LIT>" , d [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertPathHashesEqual ( d [ "<STR_LIT>" ] , "<STR_LIT>" , d [ "<STR_LIT>" ] , "<STR_LIT>" , childPlugNamesToIgnore = ( "<STR_LIT>" , ) ) <EOL> self . assertEqual ( d [ "<STR_LIT>" ] . transform ( "<STR_LIT>" ) , IECore . M44f . createTranslated ( IECore . V3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> def testMultipleCopies ( self ) : <EOL> s = GafferScene . Sphere ( ) <EOL> d = GafferScene . Duplicate ( ) <EOL> d [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT>" ] ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" ) <EOL> d [ "<STR_LIT>" ] [ "<STR_LIT>" ] . setValue ( IECore . V3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> d [ "<STR_LIT>" ] . setValue ( <NUM_LIT:10> ) <EOL> self . assertSceneValid ( d [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( <EOL> d [ "<STR_LIT>" ] . childNames ( "<STR_LIT:/>" ) , <EOL> IECore . InternedStringVectorData ( <EOL> [ "<STR_LIT>" ] + [ "<STR_LIT>" % x for x in range ( <NUM_LIT:1> , <NUM_LIT:11> ) ] <EOL> ) <EOL> ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:11> ) : <EOL> path = "<STR_LIT>" % i <EOL> self . assertPathHashesEqual ( d [ "<STR_LIT>" ] , "<STR_LIT>" , d [ "<STR_LIT>" ] , path , childPlugNamesToIgnore = ( "<STR_LIT>" , ) ) <EOL> self . assertEqual ( d [ "<STR_LIT>" ] . transform ( path ) , IECore . M44f . createTranslated ( IECore . V3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) * i ) ) <EOL> def testHierarchy ( self ) : <EOL> s = GafferScene . Sphere ( ) <EOL> g = GafferScene . Group ( ) <EOL> g [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( s [ "<STR_LIT>" ] ) <EOL> d = GafferScene . Duplicate ( ) <EOL> d [ "<STR_LIT>" ] . setInput ( g [ "<STR_LIT>" ] ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" ) <EOL> self . assertSceneValid ( d [ "<STR_LIT>" ] ) <EOL> self . assertPathsEqual ( d [ "<STR_LIT>" ] , "<STR_LIT>" , d [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertPathHashesEqual ( d [ "<STR_LIT>" ] , "<STR_LIT>" , d [ "<STR_LIT>" ] , "<STR_LIT>" , childPlugNamesToIgnore = ( "<STR_LIT>" , ) ) <EOL> self . assertPathsEqual ( d [ "<STR_LIT>" ] , "<STR_LIT>" , d [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertPathHashesEqual ( d [ "<STR_LIT>" ] , "<STR_LIT>" , d [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> def testInvalidTarget ( self ) : <EOL> s = GafferScene . Sphere ( ) <EOL> d = GafferScene . Duplicate ( ) <EOL> d [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT>" ] ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" ) <EOL> self . assertRaises ( RuntimeError , d [ "<STR_LIT>" ] . childNames , "<STR_LIT:/>" ) <EOL> def testNamePlug ( self ) : <EOL> s = GafferScene . Sphere ( ) <EOL> g = GafferScene . Group ( ) <EOL> g [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( s [ "<STR_LIT>" ] ) <EOL> d = GafferScene . Duplicate ( ) <EOL> d [ "<STR_LIT>" ] . setInput ( g [ "<STR_LIT>" ] ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" ) <EOL> for target , name , copies , childNames in [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ] : <EOL> s [ "<STR_LIT:name>" ] . setValue ( target ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" + target ) <EOL> d [ "<STR_LIT:name>" ] . setValue ( name ) <EOL> d [ "<STR_LIT>" ] . setValue ( copies ) <EOL> self . assertSceneValid ( d [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( d [ "<STR_LIT>" ] . childNames ( "<STR_LIT>" ) , IECore . InternedStringVectorData ( childNames ) ) <EOL> def testNamePlugAffects ( self ) : <EOL> d = GafferScene . Duplicate ( ) <EOL> cs = GafferTest . CapturingSlot ( d . plugDirtiedSignal ( ) ) <EOL> d [ "<STR_LIT:name>" ] . setValue ( "<STR_LIT:test>" ) <EOL> self . assertTrue ( d [ "<STR_LIT>" ] [ "<STR_LIT>" ] in [ c [ <NUM_LIT:0> ] for c in cs ] ) <EOL> def testSets ( self ) : <EOL> s = GafferScene . Sphere ( ) <EOL> s [ "<STR_LIT>" ] . setValue ( "<STR_LIT>" ) <EOL> g = GafferScene . Group ( ) <EOL> g [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT>" ] ) <EOL> d = GafferScene . Duplicate ( ) <EOL> d [ "<STR_LIT>" ] . setInput ( g [ "<STR_LIT>" ] ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" ) <EOL> d [ "<STR_LIT>" ] . setValue ( <NUM_LIT:5> ) <EOL> self . assertEqual ( <EOL> set ( d [ "<STR_LIT>" ] . set ( "<STR_LIT>" ) . value . paths ( ) ) , <EOL> set ( <EOL> [ "<STR_LIT>" ] + <EOL> [ "<STR_LIT>" % n for n in range ( <NUM_LIT:1> , <NUM_LIT:6> ) ] <EOL> ) <EOL> ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" ) <EOL> d [ "<STR_LIT>" ] . setValue ( <NUM_LIT> ) <EOL> self . assertEqual ( <EOL> set ( d [ "<STR_LIT>" ] . set ( "<STR_LIT>" ) . value . paths ( ) ) , <EOL> set ( <EOL> [ "<STR_LIT>" ] + <EOL> [ "<STR_LIT>" % n for n in range ( <NUM_LIT:1> , <NUM_LIT> ) ] <EOL> ) <EOL> ) <EOL> def testSetNames ( self ) : <EOL> s = GafferScene . Sphere ( ) <EOL> s [ "<STR_LIT>" ] . setValue ( "<STR_LIT>" ) <EOL> d = GafferScene . Duplicate ( ) <EOL> d [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT>" ] ) <EOL> d [ "<STR_LIT:target>" ] . setValue ( "<STR_LIT>" ) <EOL> d [ "<STR_LIT>" ] [ "<STR_LIT>" ] . setValue ( IECore . V3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> with Gaffer . PerformanceMonitor ( ) as m : <EOL> self . assertEqual ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] . hash ( ) , d [ "<STR_LIT>" ] [ "<STR_LIT>" ] . hash ( ) ) <EOL> self . assertTrue ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( _copy = False ) . isSame ( d [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( _copy = False ) ) ) <EOL> self . assertEqual ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , IECore . InternedStringVectorData ( [ "<STR_LIT>" ] ) ) <EOL> self . assertEqual ( m . plugStatistics ( d [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) . hashCount , <NUM_LIT:0> ) <EOL> self . assertEqual ( m . plugStatistics ( d [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) . computeCount , <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
