test harness attempt
jonf at connix.com
Thu May 4 16:15:03 CEST 2000
I am trying to figure out how to write a test harness for my class. I want pass a code string to a function that will print the string and then exec it. The function should be able to compare the
value of the statement against an expected value. I've have managed to get it half-way working but I can't seem to do an assignment in an 'exec' statement. Is there any way to do this ? Any help would
be greatly appreciated.
This is my object.py module:
print '\ntesting object'
_run( 'x = Object()' )
_run( 'y = Object()' )
_run( 'z = Object()' )
_run( 'nObjects()', 3 )
def _run( codeStr, test = None ):
if test == None:
exec codeStr in object.__dict__
exec '_x_ = ' + codeStr in object.__dict__
print '(expecting: ' + `test` + ' got: ' + `object._x_` + ')'
_nObjs = 0
def __init__( self ):
Object._nObjs = Object._nObjs + 1
if __name__ == "__main__":
More information about the Python-list