mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
made verify a built-in; added want-verify-pdb
This commit is contained in:
parent
56978e1ade
commit
0c338d3c3d
@ -1,22 +1,24 @@
|
|||||||
"""
|
"""
|
||||||
You can use verify() just like assert, with these small differences:
|
You can use verify() just like assert, with these small differences:
|
||||||
- you may need to "from Verify import *", if someone hasn't done it
|
- you may need to "import Verify", if someone hasn't done it
|
||||||
for you.
|
for you.
|
||||||
- unlike assert where using parenthises are optional, verify()
|
- unlike assert where using parenthises are optional, verify()
|
||||||
requires them.
|
requires them.
|
||||||
e.g.:
|
e.g.:
|
||||||
assert foo # OK
|
assert foo # OK
|
||||||
assert(foo) # OK
|
|
||||||
verify foo # Error
|
verify foo # Error
|
||||||
|
assert(foo) # OK
|
||||||
verify(foo) # OK
|
verify(foo) # OK
|
||||||
- verify() will print something like the following before raising
|
- verify() will print something like the following before raising
|
||||||
an exception:
|
an exception:
|
||||||
|
|
||||||
verify failed:
|
verify failed:
|
||||||
File "direct/src/showbase/ShowBase.py", line 60
|
File "direct/src/showbase/ShowBase.py", line 60
|
||||||
- verify() will optionally start pdb for you (this is currently
|
- verify() will optionally start pdb for you (this is currently
|
||||||
true by default).
|
false by default). You can either edit Verify.py to set
|
||||||
- verify() will still function in the release build.
|
wantVerifyPdb = 1 or if you are using ShowBase you can set
|
||||||
|
want-verify-pdb 1 in your Configrc to start pdb automatically.
|
||||||
|
- verify() will still function in the release build. It will
|
||||||
|
not be removed by -O like assert will.
|
||||||
|
|
||||||
verify() will also throw an AssertionError, but you can ignore that if you
|
verify() will also throw an AssertionError, but you can ignore that if you
|
||||||
like (I don't suggest trying to catch it, it's just doing it so that it can
|
like (I don't suggest trying to catch it, it's just doing it so that it can
|
||||||
@ -35,9 +37,13 @@ you don't always have the time to write proper error handling, go ahead
|
|||||||
and use verify() -- that's what it's for.
|
and use verify() -- that's what it's for.
|
||||||
|
|
||||||
Please use assert (properly) and do proper error handling; and use verify()
|
Please use assert (properly) and do proper error handling; and use verify()
|
||||||
only where it helps you resist using assert for error handling.
|
only when debugging (i.e. when it won't be checked-in) or where it helps
|
||||||
|
you resist using assert for error handling.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
wantVerifyPdb = 0 # Set to true to load pdb on failure.
|
||||||
|
|
||||||
|
|
||||||
def verify(assertion):
|
def verify(assertion):
|
||||||
"""
|
"""
|
||||||
verify() is intended to be used in place of assert where you
|
verify() is intended to be used in place of assert where you
|
||||||
@ -49,7 +55,10 @@ def verify(assertion):
|
|||||||
print " File \"%s\", line %d"%(
|
print " File \"%s\", line %d"%(
|
||||||
sys._getframe(1).f_code.co_filename,
|
sys._getframe(1).f_code.co_filename,
|
||||||
sys._getframe(1).f_lineno)
|
sys._getframe(1).f_lineno)
|
||||||
if 1:
|
if wantVerifyPdb:
|
||||||
import pdb
|
import pdb
|
||||||
pdb.set_trace()
|
pdb.set_trace()
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
|
if not hasattr(__builtins__, "verify"):
|
||||||
|
__builtins__["verify"] = verify
|
||||||
|
@ -7,7 +7,7 @@ import inspect
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from Verify import *
|
import Verify
|
||||||
|
|
||||||
|
|
||||||
# NOTE: ifAbsentPut has been replaced with Python's dictionary's builtin setdefault
|
# NOTE: ifAbsentPut has been replaced with Python's dictionary's builtin setdefault
|
||||||
|
@ -42,6 +42,8 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Get the dconfig object
|
# Get the dconfig object
|
||||||
self.config = ConfigConfigureGetConfigConfigShowbase
|
self.config = ConfigConfigureGetConfigConfigShowbase
|
||||||
|
# Setup wantVerifyPdb as soon as reasonable:
|
||||||
|
Verify.wantVerifyPdb = self.config.GetBool('want-verify-pdb', 0)
|
||||||
|
|
||||||
self.printEnvDebugInfo()
|
self.printEnvDebugInfo()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user