@@ -292,6 +292,73 @@ def test_callback_wrong_disconnect(self, pickle, cls):
292292 # check we still have callbacks registered
293293 self .is_not_empty ()
294294
295+ @pytest .mark .parametrize ('pickle' , [True , False ])
296+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
297+ def test_callback_disconnect_func (self , pickle , cls ):
298+ # ensure we start with an empty registry
299+ self .is_empty ()
300+
301+ # create a class for testing
302+ mini_me = cls ()
303+
304+ # test that we can add a callback
305+ self .connect (self .signal , mini_me .dummy , pickle )
306+ self .is_not_empty ()
307+
308+ # disconnect by function reference
309+ self .callbacks .disconnect_func (self .signal , mini_me .dummy )
310+
311+ # check we now have no callbacks registered
312+ self .is_empty ()
313+
314+ @pytest .mark .parametrize ('pickle' , [True , False ])
315+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
316+ def test_callback_disconnect_func_wrong (self , pickle , cls ):
317+ # ensure we start with an empty registry
318+ self .is_empty ()
319+
320+ # create a class for testing
321+ mini_me = cls ()
322+
323+ # test that we can add a callback
324+ self .connect (self .signal , mini_me .dummy , pickle )
325+ self .is_not_empty ()
326+
327+ # try to disconnect with wrong signal - should do nothing
328+ self .callbacks .disconnect_func ('wrong_signal' , mini_me .dummy )
329+
330+ # check we still have callbacks registered
331+ self .is_not_empty ()
332+
333+ # try to disconnect with wrong function - should do nothing
334+ mini_me2 = cls ()
335+ self .callbacks .disconnect_func (self .signal , mini_me2 .dummy )
336+
337+ # check we still have callbacks registered
338+ self .is_not_empty ()
339+
340+ def test_callback_disconnect_func_redefined (self ):
341+ # Test that redefining a function name doesn't affect disconnect_func.
342+ # When you redefine a function, it creates a new function object,
343+ # so disconnect_func should not disconnect the original.
344+ self .is_empty ()
345+
346+ def func ():
347+ pass
348+
349+ self .callbacks .connect (self .signal , func )
350+ self .is_not_empty ()
351+
352+ # Redefine func - this creates a new function object
353+ def func ():
354+ pass
355+
356+ # Try to disconnect with the redefined function
357+ self .callbacks .disconnect_func (self .signal , func )
358+
359+ # Original callback should still be registered
360+ self .is_not_empty ()
361+
295362 @pytest .mark .parametrize ('pickle' , [True , False ])
296363 @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
297364 def test_registration_on_non_empty_registry (self , pickle , cls ):
0 commit comments