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")
def test_MethodConnectDuplicate(self): """Test that each method connection is unique""" methodSignal = Signal(slot_signature) methodSignal.connect(self.setVal) methodSignal.connect(self.setVal) self.assertEqual(len(methodSignal._islots), 1, "Expected single connected slot") self.assertEqual(len(methodSignal._slots), 0, "Expected single connected slot")
def test_PartialDisconnect(self): """Test disconnecting partial function""" partialSignal = Signal(nopar_signature) part = partial(testFunc, self, 'Partial') partialSignal.connect(part) partialSignal.disconnect(part) self.assertEqual(self.checkval, None, "Slot was not removed from signal")
def test_LambdaDisconnect(self): """Test disconnecting lambda function""" lambdaSignal = Signal(slot_signature) func = lambda value: testFunc(self, value) lambdaSignal.connect(func) lambdaSignal.disconnect(func) self.assertEqual(len(lambdaSignal._slots), 0, "Slot was not removed from signal")
def test_LambdaConnectDuplicate(self): """Tests connecting signals to duplicate lambdas""" lambdaSignal = Signal(slot_signature) func = lambda value: testFunc(self, value) lambdaSignal.connect(func) lambdaSignal.connect(func) self.assertEqual(len(lambdaSignal._slots), 1, "Expected single connected slot")
def test_PartialConnectDuplicate(self): """Tests connecting signals to partials""" partialSignal = Signal(nopar_signature) func = partial(testFunc, self, 'Partial') partialSignal.connect(func) partialSignal.connect(func) self.assertEqual(len(partialSignal._slots), 1, "Expected single connected slot")
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")
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")
def test_ClearSlots(self): """Test clearing all slots""" multiSignal = Signal(slot_signature) func = lambda value: self.setVal(value) multiSignal.connect(partial(testFunc, self)) multiSignal.connect(self.setVal) multiSignal.clear() self.assertEqual(len(multiSignal._slots), 0, "Not all slots were removed from signal")
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")
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)
def test_MethodConnectDifferentInstances(self): """Test connecting the same method from different instances""" methodSignal = Signal(slot_signature) dummy1 = DummySlotClass() dummy2 = DummySlotClass() methodSignal.connect(dummy1.setVal) methodSignal.connect(dummy2.setVal) self.assertEqual(len(methodSignal._islots), 2, "Expected two connected slots") self.assertEqual(len(methodSignal._slots), 0, "Expected single connected slot")
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)
def test_PartialConnectKWDifferOk(self): """Tests connecting signals to partials""" partialSignal = Signal(nopar_signature) partialSignal.connect(partial(testFuncWithKWDeafult, self, 'Partial')) self.assertEqual(len(partialSignal._slots), 1, "Expected single connected slot")
def test_FunctionDisconnect(self): """Test disconnecting function""" funcSignal = Signal(testFunc_signature) funcSignal.connect(testFunc) funcSignal.disconnect(testFunc) self.assertEqual(len(funcSignal._slots), 0, "Slot was not removed from signal")
def test_MethodConnect(self): """Test connecting signals to methods on class instances""" methodSignal = Signal(slot_signature) methodSignal.connect(self.setVal) self.assertEqual(len(methodSignal._islots), 1, "Expected single connected slot") self.assertEqual(len(methodSignal._slots), 0, "Expected single connected slot")
def test_FunctionConnect(self): """Test connecting signals to standalone functions""" funcSignal = Signal(testFunc_signature) funcSignal.connect(testFunc) self.assertEqual(len(funcSignal._slots), 1, "Expected single connected slot")
def test_FunctionConnectDuplicate(self): """Test that each function connection is unique""" funcSignal = Signal(testFunc_signature) funcSignal.connect(testFunc) funcSignal.connect(testFunc) self.assertEqual(len(funcSignal._slots), 1, "Expected single connected slot")
def test_PartialConnectKWDifferBad(self): """Tests connecting signals to partials""" partialSignal = Signal(nopar_signature) with self.assertRaises(ValueError): partialSignal.connect(partial(testFuncWithKW, self, 'Partial')) self.assertEqual(len(partialSignal._slots), 0, "Expected single connected slot")
def test_ConnectNonCallable(self): """Test connecting non-callable object""" nonCallableSignal = Signal(slot_signature) with self.assertRaises(ValueError): nonCallableSignal.connect(self.checkval)