Skip to content

Commit 8f0af2a

Browse files
committed
improve coverage
1 parent 14b6f95 commit 8f0af2a

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

unpythonic/conditions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def accepts_arg(f):
159159
try:
160160
if arity_includes(f, 1):
161161
return True
162-
except UnknownArity:
162+
except UnknownArity: # pragma: no cover
163163
return True # just assume it
164164
return False
165165

unpythonic/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def accepts_arg(f):
297297
try:
298298
if arity_includes(f, 1):
299299
return True
300-
except UnknownArity:
300+
except UnknownArity: # pragma: no cover
301301
return True # just assume it
302302
return False
303303

unpythonic/test/test_conditions.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)