@@ -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,22 +209,23 @@ 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
@pytest .mark .parametrize ('pickle' , [True , False ])
213
- def test_callback_complete (self , pickle ):
222
+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
223
+ def test_callback_complete (self , pickle , cls ):
214
224
# ensure we start with an empty registry
215
225
self .is_empty ()
216
226
217
227
# create a class for testing
218
- mini_me = Test_callback_registry ()
228
+ mini_me = cls ()
219
229
220
230
# test that we can add a callback
221
231
cid1 = self .connect (self .signal , mini_me .dummy , pickle )
@@ -226,7 +236,7 @@ def test_callback_complete(self, pickle):
226
236
cid2 = self .connect (self .signal , mini_me .dummy , pickle )
227
237
assert cid1 == cid2
228
238
self .is_not_empty ()
229
- assert len (self .callbacks ._func_cid_map ) == 1
239
+ assert len ([ * self .callbacks ._func_cid_map ] ) == 1
230
240
assert len (self .callbacks .callbacks ) == 1
231
241
232
242
del mini_me
@@ -235,12 +245,13 @@ def test_callback_complete(self, pickle):
235
245
self .is_empty ()
236
246
237
247
@pytest .mark .parametrize ('pickle' , [True , False ])
238
- def test_callback_disconnect (self , pickle ):
248
+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
249
+ def test_callback_disconnect (self , pickle , cls ):
239
250
# ensure we start with an empty registry
240
251
self .is_empty ()
241
252
242
253
# create a class for testing
243
- mini_me = Test_callback_registry ()
254
+ mini_me = cls ()
244
255
245
256
# test that we can add a callback
246
257
cid1 = self .connect (self .signal , mini_me .dummy , pickle )
@@ -253,12 +264,13 @@ def test_callback_disconnect(self, pickle):
253
264
self .is_empty ()
254
265
255
266
@pytest .mark .parametrize ('pickle' , [True , False ])
256
- def test_callback_wrong_disconnect (self , pickle ):
267
+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
268
+ def test_callback_wrong_disconnect (self , pickle , cls ):
257
269
# ensure we start with an empty registry
258
270
self .is_empty ()
259
271
260
272
# create a class for testing
261
- mini_me = Test_callback_registry ()
273
+ mini_me = cls ()
262
274
263
275
# test that we can add a callback
264
276
cid1 = self .connect (self .signal , mini_me .dummy , pickle )
@@ -271,20 +283,21 @@ def test_callback_wrong_disconnect(self, pickle):
271
283
self .is_not_empty ()
272
284
273
285
@pytest .mark .parametrize ('pickle' , [True , False ])
274
- def test_registration_on_non_empty_registry (self , pickle ):
286
+ @pytest .mark .parametrize ('cls' , [Hashable , Unhashable ])
287
+ def test_registration_on_non_empty_registry (self , pickle , cls ):
275
288
# ensure we start with an empty registry
276
289
self .is_empty ()
277
290
278
291
# setup the registry with a callback
279
- mini_me = Test_callback_registry ()
292
+ mini_me = cls ()
280
293
self .connect (self .signal , mini_me .dummy , pickle )
281
294
282
295
# Add another callback
283
- mini_me2 = Test_callback_registry ()
296
+ mini_me2 = cls ()
284
297
self .connect (self .signal , mini_me2 .dummy , pickle )
285
298
286
299
# Remove and add the second callback
287
- mini_me2 = Test_callback_registry ()
300
+ mini_me2 = cls ()
288
301
self .connect (self .signal , mini_me2 .dummy , pickle )
289
302
290
303
# We still have 2 references
@@ -296,9 +309,6 @@ def test_registration_on_non_empty_registry(self, pickle):
296
309
mini_me2 = None
297
310
self .is_empty ()
298
311
299
- def dummy (self ):
300
- pass
301
-
302
312
def test_pickling (self ):
303
313
assert hasattr (pickle .loads (pickle .dumps (cbook .CallbackRegistry ())),
304
314
"callbacks" )
0 commit comments