Wrap func and replace the result with the truth value of the trap (True if no exception). First, give the decorator an alias to support Python 3.8 Syntax. >>> passes = ExceptionTrap(ValueError).passes Now decorate a function that always fails.
(self, func)
| 97 | return wrapper |
| 98 | |
| 99 | def passes(self, func): |
| 100 | """ |
| 101 | Wrap func and replace the result with the truth |
| 102 | value of the trap (True if no exception). |
| 103 | |
| 104 | First, give the decorator an alias to support Python 3.8 |
| 105 | Syntax. |
| 106 | |
| 107 | >>> passes = ExceptionTrap(ValueError).passes |
| 108 | |
| 109 | Now decorate a function that always fails. |
| 110 | |
| 111 | >>> @passes |
| 112 | ... def fail(): |
| 113 | ... raise ValueError('failed') |
| 114 | |
| 115 | >>> fail() |
| 116 | False |
| 117 | """ |
| 118 | return self.raises(func, _test=operator.not_) |