@@ -233,22 +233,33 @@ def test_pickling(self):
233233 "callbacks" )
234234
235235
236+ def test_callbackregistry_default_exception_handler (monkeypatch ):
237+ cb = cbook .CallbackRegistry ()
238+ cb .connect ("foo" , lambda : None )
239+ monkeypatch .setattr (
240+ cbook , "_get_running_interactive_framework" , lambda : None )
241+ with pytest .raises (TypeError ):
242+ cb .process ("foo" , "argument mismatch" )
243+ monkeypatch .setattr (
244+ cbook , "_get_running_interactive_framework" , lambda : "not-none" )
245+ cb .process ("foo" , "argument mismatch" ) # No error in that case.
246+
247+
236248def raising_cb_reg (func ):
237249 class TestException (Exception ):
238250 pass
239251
240252 def raising_function ():
241253 raise RuntimeError
242254
255+ def raising_function_VE ():
256+ raise ValueError
257+
243258 def transformer (excp ):
244259 if isinstance (excp , RuntimeError ):
245260 raise TestException
246261 raise excp
247262
248- # default behavior
249- cb = cbook .CallbackRegistry ()
250- cb .connect ('foo' , raising_function )
251-
252263 # old default
253264 cb_old = cbook .CallbackRegistry (exception_handler = None )
254265 cb_old .connect ('foo' , raising_function )
@@ -257,18 +268,21 @@ def transformer(excp):
257268 cb_filt = cbook .CallbackRegistry (exception_handler = transformer )
258269 cb_filt .connect ('foo' , raising_function )
259270
271+ # filter
272+ cb_filt_pass = cbook .CallbackRegistry (exception_handler = transformer )
273+ cb_filt_pass .connect ('foo' , raising_function_VE )
274+
260275 return pytest .mark .parametrize ('cb, excp' ,
261- [[cb , None ],
262- [cb_old , RuntimeError ],
263- [cb_filt , TestException ]])(func )
276+ [[cb_old , RuntimeError ],
277+ [cb_filt , TestException ],
278+ [cb_filt_pass , ValueError ]])(func )
264279
265280
266281@raising_cb_reg
267- def test_callbackregistry_process_exception (cb , excp ):
268- if excp is not None :
269- with pytest .raises (excp ):
270- cb .process ('foo' )
271- else :
282+ def test_callbackregistry_custom_exception_handler (monkeypatch , cb , excp ):
283+ monkeypatch .setattr (
284+ cbook , "_get_running_interactive_framework" , lambda : None )
285+ with pytest .raises (excp ):
272286 cb .process ('foo' )
273287
274288
0 commit comments