<s> import unittest <EOL> import sys <EOL> import StringIO <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> import GafferUITest <EOL> class EventSignalCombinerTest ( GafferUITest . TestCase ) : <EOL> def trueSlot ( self , gadget , event ) : <EOL> self . trueSlotCalled = True <EOL> return True <EOL> def falseSlot ( self , gadget , event ) : <EOL> self . falseSlotCalled = True <EOL> return False <EOL> def exceptionSlot ( self , gadget , event ) : <EOL> self . exceptionSlotCalled = True <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def setUp ( self ) : <EOL> GafferUITest . TestCase . setUp ( self ) <EOL> self . falseSlotCalled = False <EOL> self . trueSlotCalled = False <EOL> self . exceptionSlotCalled = False <EOL> def testShortCutting ( self ) : <EOL> s = GafferUI . Gadget . ButtonSignal ( ) <EOL> c1 = s . connect ( self . trueSlot ) <EOL> c2 = s . connect ( self . falseSlot ) <EOL> self . assertEqual ( self . trueSlotCalled , False ) <EOL> self . assertEqual ( self . falseSlotCalled , False ) <EOL> self . assertEqual ( s ( None , GafferUI . ButtonEvent ( ) ) , True ) <EOL> self . assertEqual ( self . trueSlotCalled , True ) <EOL> self . assertEqual ( self . falseSlotCalled , False ) <EOL> def testNoShortCutting ( self ) : <EOL> s = GafferUI . Gadget . ButtonSignal ( ) <EOL> c1 = s . connect ( self . falseSlot ) <EOL> c2 = s . connect ( self . trueSlot ) <EOL> self . assertEqual ( self . trueSlotCalled , False ) <EOL> self . assertEqual ( self . falseSlotCalled , False ) <EOL> self . assertEqual ( s ( None , GafferUI . ButtonEvent ( ) ) , True ) <EOL> self . assertEqual ( self . trueSlotCalled , True ) <EOL> self . assertEqual ( self . falseSlotCalled , True ) <EOL> def testExceptionHandling ( self ) : <EOL> s = GafferUI . Gadget . ButtonSignal ( ) <EOL> c1 = s . connect ( self . exceptionSlot ) <EOL> c2 = s . connect ( self . trueSlot ) <EOL> self . assertEqual ( self . exceptionSlotCalled , False ) <EOL> self . assertEqual ( self . trueSlotCalled , False ) <EOL> tmpStdErr = StringIO . StringIO ( ) <EOL> sys . stderr = tmpStdErr <EOL> try : <EOL> self . assertEqual ( s ( None , GafferUI . ButtonEvent ( ) ) , True ) <EOL> finally : <EOL> sys . stderr = sys . __stderr__ <EOL> self . assert_ ( "<STR_LIT>" in tmpStdErr . getvalue ( ) ) <EOL> self . assertEqual ( self . exceptionSlotCalled , True ) <EOL> self . assertEqual ( self . trueSlotCalled , True ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
