@@ -182,8 +182,11 @@ def setup(self):
182
182
self .signal = 'test'
183
183
self .callbacks = cbook .CallbackRegistry ()
184
184
185
- def connect (self , s , func ):
186
- return self .callbacks .connect (s , func )
185
+ def connect (self , s , func , pickle ):
186
+ cid = self .callbacks .connect (s , func )
187
+ if pickle :
188
+ self .callbacks ._pickled_cids .add (cid )
189
+ return cid
187
190
188
191
def disconnect (self , cid ):
189
192
return self .callbacks .disconnect (cid )
@@ -197,25 +200,27 @@ def count(self):
197
200
def is_empty (self ):
198
201
assert self .callbacks ._func_cid_map == {}
199
202
assert self .callbacks .callbacks == {}
203
+ assert self .callbacks ._pickled_cids == set ()
200
204
201
205
def is_not_empty (self ):
202
206
assert self .callbacks ._func_cid_map != {}
203
207
assert self .callbacks .callbacks != {}
204
208
205
- def test_callback_complete (self ):
209
+ @pytest .mark .parametrize ('pickle' , [True , False ])
210
+ def test_callback_complete (self , pickle ):
206
211
# ensure we start with an empty registry
207
212
self .is_empty ()
208
213
209
214
# create a class for testing
210
215
mini_me = Test_callback_registry ()
211
216
212
217
# test that we can add a callback
213
- cid1 = self .connect (self .signal , mini_me .dummy )
218
+ cid1 = self .connect (self .signal , mini_me .dummy , pickle )
214
219
assert type (cid1 ) == int
215
220
self .is_not_empty ()
216
221
217
222
# test that we don't add a second callback
218
- cid2 = self .connect (self .signal , mini_me .dummy )
223
+ cid2 = self .connect (self .signal , mini_me .dummy , pickle )
219
224
assert cid1 == cid2
220
225
self .is_not_empty ()
221
226
assert len (self .callbacks ._func_cid_map ) == 1
@@ -226,15 +231,16 @@ def test_callback_complete(self):
226
231
# check we now have no callbacks registered
227
232
self .is_empty ()
228
233
229
- def test_callback_disconnect (self ):
234
+ @pytest .mark .parametrize ('pickle' , [True , False ])
235
+ def test_callback_disconnect (self , pickle ):
230
236
# ensure we start with an empty registry
231
237
self .is_empty ()
232
238
233
239
# create a class for testing
234
240
mini_me = Test_callback_registry ()
235
241
236
242
# test that we can add a callback
237
- cid1 = self .connect (self .signal , mini_me .dummy )
243
+ cid1 = self .connect (self .signal , mini_me .dummy , pickle )
238
244
assert type (cid1 ) == int
239
245
self .is_not_empty ()
240
246
@@ -243,15 +249,16 @@ def test_callback_disconnect(self):
243
249
# check we now have no callbacks registered
244
250
self .is_empty ()
245
251
246
- def test_callback_wrong_disconnect (self ):
252
+ @pytest .mark .parametrize ('pickle' , [True , False ])
253
+ def test_callback_wrong_disconnect (self , pickle ):
247
254
# ensure we start with an empty registry
248
255
self .is_empty ()
249
256
250
257
# create a class for testing
251
258
mini_me = Test_callback_registry ()
252
259
253
260
# test that we can add a callback
254
- cid1 = self .connect (self .signal , mini_me .dummy )
261
+ cid1 = self .connect (self .signal , mini_me .dummy , pickle )
255
262
assert type (cid1 ) == int
256
263
self .is_not_empty ()
257
264
@@ -260,21 +267,22 @@ def test_callback_wrong_disconnect(self):
260
267
# check we still have callbacks registered
261
268
self .is_not_empty ()
262
269
263
- def test_registration_on_non_empty_registry (self ):
270
+ @pytest .mark .parametrize ('pickle' , [True , False ])
271
+ def test_registration_on_non_empty_registry (self , pickle ):
264
272
# ensure we start with an empty registry
265
273
self .is_empty ()
266
274
267
275
# setup the registry with a callback
268
276
mini_me = Test_callback_registry ()
269
- self .connect (self .signal , mini_me .dummy )
277
+ self .connect (self .signal , mini_me .dummy , pickle )
270
278
271
279
# Add another callback
272
280
mini_me2 = Test_callback_registry ()
273
- self .connect (self .signal , mini_me2 .dummy )
281
+ self .connect (self .signal , mini_me2 .dummy , pickle )
274
282
275
283
# Remove and add the second callback
276
284
mini_me2 = Test_callback_registry ()
277
- self .connect (self .signal , mini_me2 .dummy )
285
+ self .connect (self .signal , mini_me2 .dummy , pickle )
278
286
279
287
# We still have 2 references
280
288
self .is_not_empty ()
0 commit comments