<s> import unittest <EOL> import itertools <EOL> import Gaffer <EOL> import GafferTest <EOL> class CompoundPathFilterTest ( GafferTest . TestCase ) : <EOL> def assertFilterListsEqual ( self , a , b ) : <EOL> self . assertEqual ( len ( a ) , len ( b ) ) <EOL> for ae , be in zip ( a , b ) : <EOL> self . assertTrue ( ae . isSame ( be ) ) <EOL> def test ( self ) : <EOL> f1 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> f2 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> c = Gaffer . CompoundPathFilter ( ) <EOL> self . assertFilterListsEqual ( c . getFilters ( ) , [ ] ) <EOL> c . addFilter ( f1 ) <EOL> self . assertFilterListsEqual ( c . getFilters ( ) , [ f1 ] ) <EOL> c . addFilter ( f2 ) <EOL> self . assertFilterListsEqual ( c . getFilters ( ) , [ f1 , f2 ] ) <EOL> c . removeFilter ( f1 ) <EOL> self . assertFilterListsEqual ( c . getFilters ( ) , [ f2 ] ) <EOL> c . setFilters ( [ f1 , f2 ] ) <EOL> self . assertFilterListsEqual ( c . getFilters ( ) , [ f1 , f2 ] ) <EOL> def testChangedSignal ( self ) : <EOL> cf = Gaffer . CompoundPathFilter ( ) <EOL> self . __numChanges = <NUM_LIT:0> <EOL> def f ( filter ) : <EOL> self . failUnless ( filter . isSame ( cf ) ) <EOL> self . __numChanges += <NUM_LIT:1> <EOL> f1 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> f2 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> c = cf . changedSignal ( ) . connect ( f ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:0> ) <EOL> cf . addFilter ( f1 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:1> ) <EOL> cf . setFilters ( [ f1 ] ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:1> ) <EOL> cf . setFilters ( [ f1 , f2 ] ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:2> ) <EOL> cf . removeFilter ( f1 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:3> ) <EOL> cf . setEnabled ( False ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:4> ) <EOL> cf . setFilters ( [ ] ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:4> ) <EOL> cf . setFilters ( [ f1 , f2 ] ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:4> ) <EOL> def testChangedSignalPropagation ( self ) : <EOL> cf = Gaffer . CompoundPathFilter ( ) <EOL> self . __numChanges = <NUM_LIT:0> <EOL> def f ( filter ) : <EOL> self . failUnless ( filter . isSame ( cf ) ) <EOL> self . __numChanges += <NUM_LIT:1> <EOL> f1 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> f2 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> c = cf . changedSignal ( ) . connect ( f ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:0> ) <EOL> cf . setFilters ( [ f1 , f2 ] ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:1> ) <EOL> f1 . changedSignal ( ) ( f1 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:2> ) <EOL> f2 . changedSignal ( ) ( f2 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:3> ) <EOL> cf . removeFilter ( f1 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:4> ) <EOL> f1 . changedSignal ( ) ( f1 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:4> ) <EOL> cf . removeFilter ( f2 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:5> ) <EOL> f2 . changedSignal ( ) ( f2 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:5> ) <EOL> cf . addFilter ( f1 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:6> ) <EOL> f1 . changedSignal ( ) ( f1 ) <EOL> self . assertEqual ( self . __numChanges , <NUM_LIT:7> ) <EOL> def testFiltering ( self ) : <EOL> p = Gaffer . DictPath ( <EOL> { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> } , <EOL> "<STR_LIT:/>" <EOL> ) <EOL> self . assertEqual ( len ( p . children ( ) ) , <NUM_LIT:3> ) <EOL> f = Gaffer . CompoundPathFilter ( ) <EOL> p . setFilter ( f ) <EOL> self . assertEqual ( len ( p . children ( ) ) , <NUM_LIT:3> ) <EOL> f . addFilter ( Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) ) <EOL> self . assertEqual ( len ( p . children ( ) ) , <NUM_LIT:2> ) <EOL> f . addFilter ( Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) ) <EOL> self . assertEqual ( len ( p . children ( ) ) , <NUM_LIT:1> ) <EOL> def testConstructFromList ( self ) : <EOL> f1 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> f2 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> f = Gaffer . CompoundPathFilter ( [ f1 , f2 ] ) <EOL> self . assertFilterListsEqual ( f . getFilters ( ) , [ f1 , f2 ] ) <EOL> def testConstructFromIterable ( self ) : <EOL> f1 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> f2 = Gaffer . FileNamePathFilter ( [ "<STR_LIT>" ] ) <EOL> f = Gaffer . CompoundPathFilter ( itertools . chain ( [ f1 ] , [ f2 ] ) ) <EOL> self . assertFilterListsEqual ( f . getFilters ( ) , [ f1 , f2 ] ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
