@@ -168,6 +168,11 @@ def highlevel():
168168 highlevel ()
169169 basic_usage2 ()
170170
171+ with testset ("signaling a class instead of an instance" ):
172+ class JustTesting (Exception ):
173+ pass
174+ test_signals [JustTesting , signal (JustTesting )]
175+
171176 # More elaborate error handling scenarios can be constructed by defining
172177 # restarts at multiple levels, as appropriate.
173178 #
@@ -351,6 +356,12 @@ def warn_protocol():
351356 result << 21
352357 test [unbox (result ) == 21 ]
353358
359+ with catch_signals (False ):
360+ with handlers ():
361+ with restarts ():
362+ print ("Testing warn() - this should print a warning:" )
363+ warn (Warning ("Testing the warning system, 1 2 3." ))
364+
354365 with handlers ((JustTesting , muffle )): # canonical way to muffle a warning
355366 with restarts () as result :
356367 warn (JustTesting ("unhandled warn() does not print a warning when it is muffled" ))
@@ -415,6 +426,21 @@ def errorcases():
415426 with test_signals (ControlError , "should yell when trying to invoke a nonexistent restart" ):
416427 with restarts (foo = (lambda x : x )):
417428 invoke ("bar" )
429+
430+ # a signal must be an Exception instance or subclass
431+ test_signals [ControlError , signal (int )]
432+ test_signals [ControlError , signal (42 )]
433+
434+ # invoke() accepts only a name (str) or a return value of `find_restart`
435+ test_signals [TypeError , invoke (42 )]
436+
437+ # invalid bindings
438+ with test_signals (TypeError ):
439+ with restarts (myrestart = 42 ): # name=callable, ...
440+ pass
441+ with test_signals (TypeError ):
442+ with handlers (("ha ha ha" , 42 )): # (excspec, callable), ...
443+ pass
418444 errorcases ()
419445
420446 # name shadowing: dynamically the most recent binding of the same restart name wins
0 commit comments