|
| 1 | +""" |
| 2 | +You can use verify() just like assert, with these small differences: |
| 3 | + - you may need to "from Verify import *", if someone hasn't done it |
| 4 | + for you. |
| 5 | + - unlike assert where using parenthises are optional, verify() |
| 6 | + requires them. |
| 7 | + e.g.: |
| 8 | + assert foo # OK |
| 9 | + assert(foo) # OK |
| 10 | + verify foo # Error |
| 11 | + verify(foo) # OK |
| 12 | + - verify() will print something like the following before raising |
| 13 | + an exception: |
| 14 | + |
| 15 | + verify failed: |
| 16 | + File "direct/src/showbase/ShowBase.py", line 60 |
| 17 | + - verify() will optionally start pdb for you (this is currently |
| 18 | + true by default). |
| 19 | + - verify() will still function in the release build. |
1 | 20 |
|
| 21 | +verify() will also throw an AssertionError, but you can ignore that if you |
| 22 | +like (I don't suggest trying to catch it, it's just doing it so that it can |
| 23 | +replace assert more fully). |
| 24 | +
|
| 25 | +Please do not use assert() for things that you want run on release builds. |
| 26 | +That is a bad thing to do. One of the main reasons that assert exists |
| 27 | +is to stip out debug code from a release build. The fact that it throws |
| 28 | +an exception can get it mistaken for an error handler. If your code |
| 29 | +needs to handle an error or throw an exception, you should do that |
| 30 | +(and not just assert() for it). |
| 31 | +
|
| 32 | +If you want to be a super keen software engineer then avoid using verify(). |
| 33 | +If you want to be, or already are, a super keen software engineer, but |
| 34 | +you don't always have the time to write proper error handling, go ahead |
| 35 | +and use verify() -- that's what it's for. |
| 36 | +
|
| 37 | +Please use assert (properly) and do proper error handling; and use verify() |
| 38 | +only where it helps you resist using assert for error handling. |
| 39 | +""" |
2 | 40 |
|
3 | 41 | def verify(assertion): |
4 | 42 | """ |
|
0 commit comments