@@ -185,6 +185,15 @@ def setup(self):
185185 def connect (self , s , func ):
186186 return self .callbacks .connect (s , func )
187187
188+ def disconnect (self , cid ):
189+ return self .callbacks .disconnect (cid )
190+
191+ def count (self ):
192+ count1 = len (self .callbacks ._func_cid_map .get (self .signal , []))
193+ count2 = len (self .callbacks .callbacks .get (self .signal ))
194+ assert count1 == count2
195+ return count1
196+
188197 def is_empty (self ):
189198 assert self .callbacks ._func_cid_map == {}
190199 assert self .callbacks .callbacks == {}
@@ -217,6 +226,41 @@ def test_callback_complete(self):
217226 # check we now have no callbacks registered
218227 self .is_empty ()
219228
229+ @pytest .mark .xfail (reason = "must be fixed" )
230+ def test_callback_disconnect (self ):
231+ # ensure we start with an empty registry
232+ self .is_empty ()
233+
234+ # create a class for testing
235+ mini_me = Test_callback_registry ()
236+
237+ # test that we can add a callback
238+ cid1 = self .connect (self .signal , mini_me .dummy )
239+ assert type (cid1 ) == int
240+ self .is_not_empty ()
241+
242+ self .disconnect (cid1 )
243+
244+ # check we now have no callbacks registered
245+ self .is_empty ()
246+
247+ def test_callback_wrong_disconnect (self ):
248+ # ensure we start with an empty registry
249+ self .is_empty ()
250+
251+ # create a class for testing
252+ mini_me = Test_callback_registry ()
253+
254+ # test that we can add a callback
255+ cid1 = self .connect (self .signal , mini_me .dummy )
256+ assert type (cid1 ) == int
257+ self .is_not_empty ()
258+
259+ self .disconnect ("foo" )
260+
261+ # check we still have callbacks registered
262+ self .is_not_empty ()
263+
220264 def dummy (self ):
221265 pass
222266
0 commit comments