<s> import os <EOL> import unittest <EOL> import IECore <EOL> import Gaffer <EOL> import GafferTest <EOL> import GafferScene <EOL> import GafferSceneTest <EOL> class UnionFilterTest ( GafferSceneTest . SceneTestCase ) : <EOL> def test ( self ) : <EOL> f1 = GafferScene . PathFilter ( ) <EOL> f1 [ "<STR_LIT>" ] . setValue ( IECore . StringVectorData ( [ <EOL> "<STR_LIT>" , <EOL> ] ) ) <EOL> f2 = GafferScene . PathFilter ( ) <EOL> f2 [ "<STR_LIT>" ] . setValue ( IECore . StringVectorData ( [ <EOL> "<STR_LIT>" , <EOL> ] ) ) <EOL> u = GafferScene . UnionFilter ( ) <EOL> self . assertEqual ( u [ "<STR_LIT>" ] . getValue ( ) , GafferScene . Filter . Result . NoMatch ) <EOL> h1 = u [ "<STR_LIT>" ] . hash ( ) <EOL> u [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( f1 [ "<STR_LIT>" ] ) <EOL> h2 = u [ "<STR_LIT>" ] . hash ( ) <EOL> self . assertNotEqual ( h1 , h2 ) <EOL> for path in [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] : <EOL> with Gaffer . Context ( ) as c : <EOL> c [ "<STR_LIT>" ] = IECore . InternedStringVectorData ( path [ <NUM_LIT:1> : ] . split ( "<STR_LIT:/>" ) ) <EOL> self . assertEqual ( u [ "<STR_LIT>" ] . getValue ( ) , f1 [ "<STR_LIT>" ] . getValue ( ) ) <EOL> u [ "<STR_LIT>" ] [ <NUM_LIT:1> ] . setInput ( f2 [ "<STR_LIT>" ] ) <EOL> h3 = u [ "<STR_LIT>" ] . hash ( ) <EOL> self . assertNotEqual ( h2 , h3 ) <EOL> for path , result in [ <EOL> ( "<STR_LIT>" , u . Result . DescendantMatch ) , <EOL> ( "<STR_LIT>" , u . Result . NoMatch ) , <EOL> ( "<STR_LIT>" , u . Result . DescendantMatch ) , <EOL> ( "<STR_LIT>" , u . Result . DescendantMatch | u . Result . ExactMatch ) , <EOL> ( "<STR_LIT>" , u . Result . AncestorMatch ) , <EOL> ( "<STR_LIT>" , u . Result . AncestorMatch | u . Result . DescendantMatch ) , <EOL> ( "<STR_LIT>" , u . Result . AncestorMatch | u . Result . ExactMatch ) , <EOL> ( "<STR_LIT>" , u . Result . AncestorMatch ) , <EOL> ] : <EOL> with Gaffer . Context ( ) as c : <EOL> c [ "<STR_LIT>" ] = IECore . InternedStringVectorData ( path [ <NUM_LIT:1> : ] . split ( "<STR_LIT:/>" ) ) <EOL> self . assertEqual ( u [ "<STR_LIT>" ] . getValue ( ) , int ( result ) ) <EOL> f2 [ "<STR_LIT>" ] . setValue ( IECore . StringVectorData ( [ <EOL> "<STR_LIT>" , <EOL> ] ) ) <EOL> h4 = u [ "<STR_LIT>" ] . hash ( ) <EOL> self . assertNotEqual ( h3 , h4 ) <EOL> def testDirtiedSignal ( self ) : <EOL> u = GafferScene . UnionFilter ( "<STR_LIT:u>" ) <EOL> f1 = GafferScene . PathFilter ( "<STR_LIT:f>" ) <EOL> cs = GafferTest . CapturingSlot ( u . plugDirtiedSignal ( ) ) <EOL> u [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( f1 [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( [ x [ <NUM_LIT:0> ] for x in cs if x [ <NUM_LIT:0> ] . direction ( ) == x [ <NUM_LIT:0> ] . Direction . Out ] , [ u [ "<STR_LIT>" ] ] ) <EOL> del cs [ : ] <EOL> f1 [ "<STR_LIT>" ] . setValue ( IECore . StringVectorData ( [ "<STR_LIT>" ] ) ) <EOL> self . assertEqual ( [ x [ <NUM_LIT:0> ] for x in cs if x [ <NUM_LIT:0> ] . direction ( ) == x [ <NUM_LIT:0> ] . Direction . Out ] , [ u [ "<STR_LIT>" ] ] ) <EOL> def testAcceptsInput ( self ) : <EOL> f = GafferScene . PathFilter ( ) <EOL> n = Gaffer . Node ( ) <EOL> n [ "<STR_LIT>" ] = f [ "<STR_LIT>" ] . createCounterpart ( "<STR_LIT>" , Gaffer . Plug . Direction . Out ) <EOL> u = GafferScene . UnionFilter ( ) <EOL> self . assertFalse ( u [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . acceptsInput ( n [ "<STR_LIT>" ] ) ) <EOL> def testSceneAffects ( self ) : <EOL> p = GafferScene . Plane ( ) <EOL> s = GafferScene . Set ( ) <EOL> s [ "<STR_LIT>" ] . setInput ( p [ "<STR_LIT>" ] ) <EOL> a = GafferScene . StandardAttributes ( ) <EOL> a [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT>" ] ) <EOL> f = GafferScene . UnionFilter ( ) <EOL> a [ "<STR_LIT>" ] . setInput ( f [ "<STR_LIT>" ] ) <EOL> pf = GafferScene . PathFilter ( ) <EOL> f [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( pf [ "<STR_LIT>" ] ) <EOL> cs = GafferTest . CapturingSlot ( a . plugDirtiedSignal ( ) ) <EOL> s [ "<STR_LIT>" ] . setValue ( IECore . StringVectorData ( [ "<STR_LIT>" ] ) ) <EOL> self . assertTrue ( a [ "<STR_LIT>" ] [ "<STR_LIT>" ] in set ( [ c [ <NUM_LIT:0> ] for c in cs ] ) ) <EOL> self . assertTrue ( a [ "<STR_LIT>" ] [ "<STR_LIT>" ] not in set ( [ c [ <NUM_LIT:0> ] for c in cs ] ) ) <EOL> sf = GafferScene . SetFilter ( ) <EOL> f [ "<STR_LIT>" ] [ <NUM_LIT:1> ] . setInput ( sf [ "<STR_LIT>" ] ) <EOL> cs = GafferTest . CapturingSlot ( a . plugDirtiedSignal ( ) ) <EOL> s [ "<STR_LIT>" ] . setValue ( IECore . StringVectorData ( [ "<STR_LIT>" ] ) ) <EOL> self . assertTrue ( a [ "<STR_LIT>" ] [ "<STR_LIT>" ] in set ( [ c [ <NUM_LIT:0> ] for c in cs ] ) ) <EOL> self . assertTrue ( a [ "<STR_LIT>" ] [ "<STR_LIT>" ] in set ( [ c [ <NUM_LIT:0> ] for c in cs ] ) ) <EOL> def testAcceptsDots ( self ) : <EOL> sf = GafferScene . SetFilter ( ) <EOL> dot = Gaffer . Dot ( ) <EOL> dot . setup ( sf [ "<STR_LIT>" ] ) <EOL> dot [ "<STR_LIT>" ] . setInput ( sf [ "<STR_LIT>" ] ) <EOL> uf = GafferScene . UnionFilter ( ) <EOL> self . assertTrue ( uf [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . acceptsInput ( dot [ "<STR_LIT>" ] ) ) <EOL> dot [ "<STR_LIT>" ] . setInput ( None ) <EOL> self . assertTrue ( uf [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . acceptsInput ( dot [ "<STR_LIT>" ] ) ) <EOL> uf [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( dot [ "<STR_LIT>" ] ) <EOL> dot [ "<STR_LIT>" ] . setInput ( sf [ "<STR_LIT>" ] ) <EOL> a = GafferTest . AddNode ( ) <EOL> dot2 = Gaffer . Dot ( ) <EOL> dot2 . setup ( a [ "<STR_LIT>" ] ) <EOL> dot2 [ "<STR_LIT>" ] . setInput ( a [ "<STR_LIT>" ] ) <EOL> self . assertFalse ( uf [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . acceptsInput ( dot2 [ "<STR_LIT>" ] ) ) <EOL> dot2 [ "<STR_LIT>" ] . setInput ( None ) <EOL> self . assertTrue ( uf [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . acceptsInput ( dot2 [ "<STR_LIT>" ] ) ) <EOL> def testReferencePromotedPlug ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT:b>" ] = Gaffer . Box ( ) <EOL> s [ "<STR_LIT:b>" ] [ "<STR_LIT:f>" ] = GafferScene . UnionFilter ( ) <EOL> p = s [ "<STR_LIT:b>" ] . promotePlug ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:f>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] ) <EOL> p . setName ( "<STR_LIT:p>" ) <EOL> s [ "<STR_LIT:b>" ] . exportForReference ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> s [ "<STR_LIT:r>" ] = Gaffer . Reference ( ) <EOL> s [ "<STR_LIT:r>" ] . load ( self . temporaryDirectory ( ) + "<STR_LIT>" ) <EOL> s [ "<STR_LIT:f>" ] = GafferScene . PathFilter ( ) <EOL> s [ "<STR_LIT:r>" ] [ "<STR_LIT:p>" ] . setInput ( s [ "<STR_LIT:f>" ] [ "<STR_LIT>" ] ) <EOL> def testFileCompatibilityWithVersion0_15 ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT>" ] . setValue ( os . path . dirname ( __file__ ) + "<STR_LIT>" ) <EOL> s . load ( ) <EOL> self . assertTrue ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . getInput ( ) . isSame ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) ) <EOL> self . assertTrue ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:1> ] . getInput ( ) . isSame ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) ) <EOL> self . assertTrue ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:2> ] . getInput ( ) . isSame ( s [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) ) <EOL> def testDisabling ( self ) : <EOL> pathFilterA = GafferScene . PathFilter ( ) <EOL> pathFilterB = GafferScene . PathFilter ( ) <EOL> pathFilterA [ "<STR_LIT>" ] . setValue ( IECore . StringVectorData ( [ "<STR_LIT>" ] ) ) <EOL> pathFilterB [ "<STR_LIT>" ] . setValue ( IECore . StringVectorData ( [ "<STR_LIT>" ] ) ) <EOL> unionFilter = GafferScene . UnionFilter ( ) <EOL> unionFilter [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . setInput ( pathFilterA [ "<STR_LIT>" ] ) <EOL> unionFilter [ "<STR_LIT>" ] [ <NUM_LIT:1> ] . setInput ( pathFilterB [ "<STR_LIT>" ] ) <EOL> self . assertTrue ( unionFilter . correspondingInput ( unionFilter [ "<STR_LIT>" ] ) . isSame ( unionFilter [ "<STR_LIT>" ] [ <NUM_LIT:0> ] ) ) <EOL> with Gaffer . Context ( ) as c : <EOL> c [ "<STR_LIT>" ] = IECore . InternedStringVectorData ( [ "<STR_LIT:a>" ] ) <EOL> self . assertEqual ( unionFilter [ "<STR_LIT>" ] . getValue ( ) , unionFilter . Result . ExactMatch ) <EOL> c [ "<STR_LIT>" ] = IECore . InternedStringVectorData ( [ "<STR_LIT:b>" ] ) <EOL> self . assertEqual ( unionFilter [ "<STR_LIT>" ] . getValue ( ) , unionFilter . Result . ExactMatch ) <EOL> unionFilter [ "<STR_LIT>" ] . setValue ( False ) <EOL> with Gaffer . Context ( ) as c : <EOL> c [ "<STR_LIT>" ] = IECore . InternedStringVectorData ( [ "<STR_LIT:a>" ] ) <EOL> self . assertEqual ( unionFilter [ "<STR_LIT>" ] . getValue ( ) , unionFilter . Result . ExactMatch ) <EOL> c [ "<STR_LIT>" ] = IECore . InternedStringVectorData ( [ "<STR_LIT:b>" ] ) <EOL> self . assertEqual ( unionFilter [ "<STR_LIT>" ] . getValue ( ) , unionFilter . Result . NoMatch ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
