Example #1
0
 def test_EmitToFunction(self):
     """Test emitting signal to standalone function"""
     funcSignal = Signal(testFunc_signature)
     funcSignal.connect(testFunc)
     funcSignal.emit(self, 'Function')
     self.assertEqual(self.checkval, 'Function')
     self.assertEqual(self.func_call_count, 1, "Expected function to be called once")
Example #2
0
 def test_EmitToLambda(self):
     """Test emitting signal to lambda"""
     lambdaSignal = Signal(slot_signature)
     lambdaSignal.connect(lambda value: testFunc(self, value))
     lambdaSignal.emit('Lambda')
     self.assertEqual(self.checkval, 'Lambda')
     self.assertEqual(self.func_call_count, 1, "Expected function to be called once")
Example #3
0
 def test_EmitToPartial(self):
     """Test emitting signals to partial"""
     partialSignal = Signal(nopar_signature)
     partialSignal.connect(partial(testFunc, self, 'Partial'))
     partialSignal.emit()
     self.assertEqual(self.checkval, 'Partial')
     self.assertEqual(self.func_call_count, 1, "Expected function to be called once")
Example #4
0
 def test_MethodDisconnect(self):
     """Test disconnecting method"""
     toCall = Signal(slot_signature)
     toCall.connect(self.setVal)
     toCall.disconnect(self.setVal)
     toCall.emit(1)
     self.assertEqual(len(toCall._islots), 0, "Expected 1 connected after disconnect, found %d" % len(toCall._slots))
     self.assertEqual(self.setVal_call_count, 0, "Expected function to be called once")
Example #5
0
 def test_EmitToMethodOnDeletedInstance(self):
     """Test emitting signal to deleted instance method"""
     toDelete = DummySlotClass()
     toCall = Signal(slot_signature)
     toCall.connect(toDelete.setVal)
     toCall.connect(self.setVal)
     del toDelete
     toCall.emit(1)
     self.assertEqual(self.checkval, 1)
Example #6
0
 def test_EmitToDeletedFunction(self):
     """Test emitting signal to deleted instance method"""
     def ToDelete(test, value):
         test.checkVal = value
         test.func_call_count += 1
     funcSignal = Signal(inspect.Signature.from_callable(ToDelete))
     funcSignal.connect(ToDelete)
     del ToDelete
     funcSignal.emit(self, 1)
     self.assertEqual(self.checkval, None)
     self.assertEqual(self.func_call_count, 0)
Example #7
0
class DummySignalClass:
    """A dummy class to check for instance handling of signals"""
    @signal
    def cSignal(self, value):
        "cSignal"
        pass

    @signal
    def cSignal2(self, value):
        "cSignal2"
        pass

    def __init__(self):
        self.signal = Signal(slot_signature)

    def triggerSignal(self):
        self.signal.emit()

    def triggerClassSignal(self):
        self.cSignal.emit(1)