diff --git a/pymlac/test_Trace.py b/pymlac/test_Trace.py new file mode 100755 index 0000000..53c2843 --- /dev/null +++ b/pymlac/test_Trace.py @@ -0,0 +1,65 @@ +""" +Test the pymlac Trace code. + +Usage: test_Trace.py [-h] +""" + + +import Trace + +# if we don't have log.py, don't crash +try: + import log + log = log.Log('test.log', log.Log.DEBUG) +except ImportError: + def log(*args, **kwargs): + pass + +def test(): + for inst in (' NOP', ' LAW 0'): + Trace.start() + Trace.itrace(inst) + Trace.dtrace(inst) + Trace.end() + + +################################################################################ + +if __name__ == '__main__': + import sys + import getopt + import traceback + + # print some usage information + def usage(msg=None): + if msg: + print(msg+'\n') + print(__doc__) # module docstring used + + # our own handler for uncaught exceptions + def excepthook(type, value, tb): + msg = '\n' + '=' * 80 + msg += '\nUncaught exception:\n' + msg += ''.join(traceback.format_exception(type, value, tb)) + msg += '=' * 80 + '\n' + print(msg) + sys.exit(1) + + # plug our handler into the python system + sys.excepthook = excepthook + + # decide which tiles to use, default is GMT + argv = sys.argv[1:] + + try: + (opts, args) = getopt.getopt(argv, 'h', ['help']) + except getopt.error: + usage() + sys.exit(1) + + for (opt, param) in opts: + if opt in ['-h', '--help']: + usage() + sys.exit(0) + + test()