@@ -178,6 +178,15 @@ def test_boxplot_stats_autorange_false(self):
178
178
assert_array_almost_equal (bstats_true [0 ]['fliers' ], [])
179
179
180
180
181
+ class Hashable :
182
+ def dummy (self ): pass
183
+
184
+
185
+ class Unhashable :
186
+ __hash__ = None # type: ignore
187
+ def dummy (self ): pass
188
+
189
+
181
190
class Test_callback_registry :
182
191
def setup_method (self ):
183
192
self .signal = 'test'
@@ -200,13 +209,13 @@ def count(self):
200
209
201
210
def is_empty (self ):
202
211
np .testing .break_cycles ()
203
- assert self .callbacks ._func_cid_map == {}
212
+ assert [ * self .callbacks ._func_cid_map ] == []
204
213
assert self .callbacks .callbacks == {}
205
214
assert self .callbacks ._pickled_cids == set ()
206
215
207
216
def is_not_empty (self ):
208
217
np .testing .break_cycles ()
209
- assert self .callbacks ._func_cid_map != {}
218
+ assert [ * self .callbacks ._func_cid_map ] != []
210
219
assert self .callbacks .callbacks != {}
211
220
212
221
def test_cid_restore (self ):
@@ -217,12 +226,13 @@ def test_cid_restore(self):
217
226
assert cid == 1
218
227
219
228
@pytest .mark .parametrize ('pickle' , [True , False ])
220
- def test_callback_complete (self , pickle ):
229
+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
230
+ def test_callback_complete (self , pickle , cls ):
221
231
# ensure we start with an empty registry
222
232
self .is_empty ()
223
233
224
234
# create a class for testing
225
- mini_me = Test_callback_registry ()
235
+ mini_me = cls ()
226
236
227
237
# test that we can add a callback
228
238
cid1 = self .connect (self .signal , mini_me .dummy , pickle )
@@ -233,7 +243,7 @@ def test_callback_complete(self, pickle):
233
243
cid2 = self .connect (self .signal , mini_me .dummy , pickle )
234
244
assert cid1 == cid2
235
245
self .is_not_empty ()
236
- assert len (self .callbacks ._func_cid_map ) == 1
246
+ assert len ([ * self .callbacks ._func_cid_map ] ) == 1
237
247
assert len (self .callbacks .callbacks ) == 1
238
248
239
249
del mini_me
@@ -242,12 +252,13 @@ def test_callback_complete(self, pickle):
242
252
self .is_empty ()
243
253
244
254
@pytest .mark .parametrize ('pickle' , [True , False ])
245
- def test_callback_disconnect (self , pickle ):
255
+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
256
+ def test_callback_disconnect (self , pickle , cls ):
246
257
# ensure we start with an empty registry
247
258
self .is_empty ()
248
259
249
260
# create a class for testing
250
- mini_me = Test_callback_registry ()
261
+ mini_me = cls ()
251
262
252
263
# test that we can add a callback
253
264
cid1 = self .connect (self .signal , mini_me .dummy , pickle )
@@ -260,12 +271,13 @@ def test_callback_disconnect(self, pickle):
260
271
self .is_empty ()
261
272
262
273
@pytest .mark .parametrize ('pickle' , [True , False ])
263
- def test_callback_wrong_disconnect (self , pickle ):
274
+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
275
+ def test_callback_wrong_disconnect (self , pickle , cls ):
264
276
# ensure we start with an empty registry
265
277
self .is_empty ()
266
278
267
279
# create a class for testing
268
- mini_me = Test_callback_registry ()
280
+ mini_me = cls ()
269
281
270
282
# test that we can add a callback
271
283
cid1 = self .connect (self .signal , mini_me .dummy , pickle )
@@ -278,20 +290,21 @@ def test_callback_wrong_disconnect(self, pickle):
278
290
self .is_not_empty ()
279
291
280
292
@pytest .mark .parametrize ('pickle' , [True , False ])
281
- def test_registration_on_non_empty_registry (self , pickle ):
293
+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
294
+ def test_registration_on_non_empty_registry (self , pickle , cls ):
282
295
# ensure we start with an empty registry
283
296
self .is_empty ()
284
297
285
298
# setup the registry with a callback
286
- mini_me = Test_callback_registry ()
299
+ mini_me = cls ()
287
300
self .connect (self .signal , mini_me .dummy , pickle )
288
301
289
302
# Add another callback
290
- mini_me2 = Test_callback_registry ()
303
+ mini_me2 = cls ()
291
304
self .connect (self .signal , mini_me2 .dummy , pickle )
292
305
293
306
# Remove and add the second callback
294
- mini_me2 = Test_callback_registry ()
307
+ mini_me2 = cls ()
295
308
self .connect (self .signal , mini_me2 .dummy , pickle )
296
309
297
310
# We still have 2 references
@@ -303,9 +316,6 @@ def test_registration_on_non_empty_registry(self, pickle):
303
316
mini_me2 = None
304
317
self .is_empty ()
305
318
306
- def dummy (self ):
307
- pass
308
-
309
319
def test_pickling (self ):
310
320
assert hasattr (pickle .loads (pickle .dumps (cbook .CallbackRegistry ())),
311
321
"callbacks" )
0 commit comments